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

[ML] Single metric viewer: Fix race condition when changing jobs. #45420

Merged
merged 10 commits into from
Sep 13, 2019

Conversation

walterra
Copy link
Contributor

@walterra walterra commented Sep 11, 2019

Summary

Part of #42909.

Fixes a race condition where changing jobs in Single Metric Viewer could result in the focus chart being empty.

Applying the job change would cause two events to be triggered which would cause the Single Metric Viewer to refresh twice: The updated time range would be triggered via timefilter, the updated jobs via the globalState listener.

This PR solves the problem by setting a global flag skipRefresh which allows us to skip updating single metric viewer and only update again once both the new time range and jobs are set. The PR also adds some checks to avoid unnecessary updates in d3 code triggered by React render calls.

I'm not sure polluting the globalState with this flag is the best approach but it allowed me to implement the fix for 7.4 with the least code changes. For 7.5 maybe we can find a better solution, for example using an observable that keeps track of it.

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

For maintainers

@walterra walterra added bug Fixes for quality problems that affect the customer experience regression :ml Feature:Anomaly Detection ML anomaly detection v8.0.0 release_note:skip Skip the PR/issue when compiling release notes v7.4.0 v7.5.0 labels Sep 11, 2019
@walterra walterra requested a review from a team as a code owner September 11, 2019 18:18
@walterra walterra self-assigned this Sep 11, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui

@elasticmachine
Copy link
Contributor

💔 Build Failed

}

function showFlyout() {
function showFlyout(setSkipRefresh = true) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be more intuitive to have setSkipRefresh = false and then send in true when we want to set it? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My intention was to have it default to true because it is the default behaviour and therefore in the usual cases where it's used and e.g. passed on as a prop like onClose={closeFlyout} doesn't need wrapping in another callback and no code change to set it to true. The only time we need it to be false is inside applySelection where we call closeFlyout directly and can easily pass on the flag.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@peteharverson
Copy link
Contributor

With these first couple of commits I can no longer produce the original issues (focus chart blank, or wrong entity dropdowns, when switching jobs).

But I now see a new issue where the focus chart is blank after changing the end time of a job. Here an example using gallery data. This happens even with refresh turned off:

smv_time_update

I also saw the context chart blank on one occasion:
image

@walterra
Copy link
Contributor Author

@peteharverson I addressed the issue you're seeing in ffcccbc, please have another look.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@walterra
Copy link
Contributor Author

@peteharverson b0eddb5 has a fix for the issue where applying the same job with job selector wouldn't update the time range.

@alvarezmelissa87
Copy link
Contributor

Gave this a local test since the latest commit. Unfortunately, I'm seeing an issue now where when I select a farequote job from the jobs list and then use the action icon to navigate to the single metric viewer I end up with a blank screen and these errors in the console:

image

image

Copy link
Contributor

@alvarezmelissa87 alvarezmelissa87 left a comment

Choose a reason for hiding this comment

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

Left a comment about getting a blank page when navigating to the single metric viewer with a farequote job.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@walterra
Copy link
Contributor Author

@alvarezmelissa87 @peteharverson 0dbd337 fixes the rendering loop with blank page you found.

@elasticmachine
Copy link
Contributor

💔 Build Failed

Copy link
Contributor

@peteharverson peteharverson left a comment

Choose a reason for hiding this comment

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

Tested the latest edit, and confirm it fixes the previous issue I was seeing with the infinite loop for multi metric jobs. LGTM!

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@alvarezmelissa87
Copy link
Contributor

Tested the latest changes and wasn't able to reproduce any of the previous issues. Thank you @walterra 🙌
LGTM

Copy link
Contributor

@alvarezmelissa87 alvarezmelissa87 left a comment

Choose a reason for hiding this comment

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

LGTM

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@walterra walterra merged commit d8cc11d into elastic:master Sep 13, 2019
@walterra walterra deleted the ml-fix-job-selection-refresh branch September 13, 2019 14:36
walterra added a commit to walterra/kibana that referenced this pull request Sep 13, 2019
…astic#45420)

Fixes a race condition where changing jobs in Single Metric Viewer could result in the focus chart being empty.
Applying the job change would cause two events to be triggered which would cause the Single Metric Viewer to refresh twice: The updated time range would be triggered via timefilter, the updated jobs via the globalState listener.
This PR solves the problem by setting a global flag skipRefresh which allows us to skip updating single metric viewer and only update again once both the new time range and jobs are set. The PR also adds some checks to avoid unnecessary updates in d3 code triggered by React render calls.
walterra added a commit to walterra/kibana that referenced this pull request Sep 13, 2019
…astic#45420)

Fixes a race condition where changing jobs in Single Metric Viewer could result in the focus chart being empty.
Applying the job change would cause two events to be triggered which would cause the Single Metric Viewer to refresh twice: The updated time range would be triggered via timefilter, the updated jobs via the globalState listener.
This PR solves the problem by setting a global flag skipRefresh which allows us to skip updating single metric viewer and only update again once both the new time range and jobs are set. The PR also adds some checks to avoid unnecessary updates in d3 code triggered by React render calls.
walterra added a commit that referenced this pull request Sep 13, 2019
…5420) (#45643)

Fixes a race condition where changing jobs in Single Metric Viewer could result in the focus chart being empty.
Applying the job change would cause two events to be triggered which would cause the Single Metric Viewer to refresh twice: The updated time range would be triggered via timefilter, the updated jobs via the globalState listener.
This PR solves the problem by setting a global flag skipRefresh which allows us to skip updating single metric viewer and only update again once both the new time range and jobs are set. The PR also adds some checks to avoid unnecessary updates in d3 code triggered by React render calls.
walterra added a commit that referenced this pull request Sep 16, 2019
…5420) (#45644)

Fixes a race condition where changing jobs in Single Metric Viewer could result in the focus chart being empty.
Applying the job change would cause two events to be triggered which would cause the Single Metric Viewer to refresh twice: The updated time range would be triggered via timefilter, the updated jobs via the globalState listener.
This PR solves the problem by setting a global flag skipRefresh which allows us to skip updating single metric viewer and only update again once both the new time range and jobs are set. The PR also adds some checks to avoid unnecessary updates in d3 code triggered by React render calls.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience Feature:Anomaly Detection ML anomaly detection :ml regression release_note:skip Skip the PR/issue when compiling release notes v7.4.0 v7.5.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants