Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset the metrics after each emission #59551

Merged
merged 3 commits into from
Mar 9, 2020

Conversation

pgayvallet
Copy link
Contributor

Summary

Follow-up of #58623 after the discussion starting here #58623 (comment)

Resets the collectors state after each emission, to get back to the consumers' expected behavior

Checklist

@pgayvallet pgayvallet added Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Feature:New Platform v8.0.0 release_note:skip Skip the PR/issue when compiling release notes v7.7.0 labels Mar 6, 2020
@pgayvallet pgayvallet requested a review from a team as a code owner March 6, 2020 14:14
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-platform (Team:Platform)

@pgayvallet pgayvallet requested a review from chrisronline March 6, 2020 14:14
@pgayvallet pgayvallet mentioned this pull request Mar 6, 2020
3 tasks
Comment on lines -29 to 33
private readonly requests: OpsServerMetrics['requests'] = {
private requests: OpsServerMetrics['requests'] = {
disconnects: 0,
total: 0,
statusCodes: {},
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont want optional properties, and as calling reset in the constructor is not sufficient to have TS consider the variable as initialized, I'm forced to duplicate that in the reset function.

Comment on lines +81 to +91
const waitForNextEmission = () =>
getOpsMetrics$()
.pipe(take(1))
.toPromise();

expect(mockOpsCollector.collect).toHaveBeenCalledTimes(1);
expect(mockOpsCollector.reset).toHaveBeenCalledTimes(1);

let nextEmission = waitForNextEmission();
jest.advanceTimersByTime(testInterval);
await nextEmission;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  private async refreshMetrics() {
    this.logger.debug('Refreshing metrics');
    const metrics = await this.metricsCollector!.collect();
    this.metricsCollector!.reset();
    this.metrics$.next(metrics);
  }

this.metricsCollector!.collect() is the first thing called in the interval handler, so waiting for advanceTimersByTime is sufficient, however as the reset call is performed after an async operation, the reset was not called on time for the test, so I had to actually wait for the observable emission

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it make sense to add a comment in test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably. Will do

private metrics$ = new ReplaySubject<OpsMetrics>(1);
private metrics$ = new Subject<OpsMetrics>();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the metrics being reset after every emission, we probably don't want a replay effect anymore, so I switched back to a plain Subject. This also go closer to the legacy/oppsy implementation that was using events (therefor have no replay capabilities)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It means that a subscriber doesn't receive the last emitted value. But okay, if it works in this way in LP

Copy link
Contributor

@chrisronline chrisronline left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I brought over the commit to my NP branch and the numbers match the old system!

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@pgayvallet pgayvallet merged commit 1f8da9d into elastic:master Mar 9, 2020
pgayvallet added a commit to pgayvallet/kibana that referenced this pull request Mar 9, 2020
* reset the metrics after each emission

* add test comment
pgayvallet added a commit that referenced this pull request Mar 9, 2020
* reset the metrics after each emission

* add test comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:New Platform release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.7.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants