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] Fix appState/globalState #52987

Merged
merged 52 commits into from
Jan 13, 2020

Conversation

walterra
Copy link
Contributor

@walterra walterra commented Dec 13, 2019

Summary

Fixes #52986.
Fixes #54317.

Replaces appState/globalState with a custom hook useUrlState().

Some notes for reviewers:

  • Migrates some more components and utils to TypeScript.
  • Removed our own injectObservablesAsProps() utility, replaced with a pattern based on useObservable() hook.
  • Removed jobSelectService$, events are no longer passed around using it, instead useUrlState() replaces it to subscribe and update these settings.
  • skipRefresh in the job selector is no longer necessary because updates are no longer triggered by both date picker and job selector.
  • useJobSelection() replaces some utilities from explorer and relies no longer on internal mutable state.
  • loading the data for the Anomaly Explorer is now wrapped in a switchMap() to avoid triggering multiple updates.
  • The diff for the Explorer (explorer.js) component is quite large because it's no longer necessary to wrap it in injectObservablesAsProps and injectI18n, but the interals didn't change that much.
  • All appState related actions are gone from EXPLORER_ACTION, appStateReducer is no longer necessary. Instead, explorerAppState$ now transforms the explorer's internal state into the format we store in the URL. setAppState from useUrlState() is then used to update the URL. The custom hook useSelectedCells() is now used to manage cell selection and store in it the URL (instead of appStateReducer).
  • Anomaly Explorer no longer needs different behavior for initialization and switching jobs.
  • The <TimeSeriesExplorer /> component no longer relies on the custom refresh() method, instead React's componentDidUpdate() lifecycle method is used to react to updating props. Its internal methods have been revamped to trigger less setStates() and rerenders.
  • Reduces passing around the whole timefilter, instead just passes down bounds as props.
  • The controls for showCharts/severity/interval no longer rely on custom state management using observables, instead they make use of useUrlState() and provide custom hooks to access/set their setting via a custom hook.

Todo

  • Remove legacy utils and services.
  • Full reload should properly set date picker time.
  • Moving back between jobs list and anomaly explorer should load the correct data.
  • Single Metric Viewer does not update to changes in the time filter. a9d9fea
  • Selected job isn't retained when switching between the Anomaly Explorer and Single Metric Viewer. 815bc61
  • Fix loading Anomaly Explorer charts. b4d3c88
  • Fix show charts checkbox. b4d3c88
  • Fix interval dropdown. aa87033
  • Annotation flyout rerender on every key press.
  • Fix forecasting 0ba9882.
  • when multiple jobs are selected in the Anomaly Explorer and then a cell is selected in a swimlane the View by and cell selection is not retained on refresh 8edb24d.
  • Hide anomalies table in single metric viewer if no results available. c0237f9
  • Restore KQL filter setting from URL on refresh 83d2f51

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 Feature:New Platform :ml Feature:Anomaly Detection ML anomaly detection refactoring v8.0.0 release_note:skip Skip the PR/issue when compiling release notes v7.6.0 labels Dec 13, 2019
@walterra walterra self-assigned this Dec 13, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

@walterra walterra force-pushed the ml-fix-react-router-appstate branch from c4875a3 to 2354a4c Compare December 17, 2019 12:15
@walterra walterra marked this pull request as ready for review December 17, 2019 12:40
@walterra walterra requested a review from a team as a code owner December 17, 2019 12:40
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.

Was there also some legacy code around the severity and interval controls that needed to be removed once this work was done?

@peteharverson
Copy link
Contributor

If I select a cell in the (view by) swimlane, and then refresh the browser, the time filter setting resets to Last 15 minutes and the view is empty:

image

@peteharverson
Copy link
Contributor

Viewed farequote, returned to the Jobs List, then clicked on the Anomaly Explorer link for a different job, the Anomaly Explorer loads to show the data for the previous job:

image

@peteharverson
Copy link
Contributor

If I switch jobs in the Single Metric Viewer to one with a different time range and entities, the previous settings get retained:

image

@walterra walterra force-pushed the ml-fix-react-router-appstate branch from a70d4c9 to 796a062 Compare December 27, 2019 15:48
@kibanamachine
Copy link
Contributor

💔 Build Failed

History

  • 💔 Build #16082 failed a70d4c95e42499a9db607b664ff4c4f8049ab043
  • 💔 Build #16057 failed 8b94b47b9f6260432552d5f8770d027bb4689b97
  • 💔 Build #15472 failed c4875a37d8a5a24d375a448b3a2471076e36588f
  • 💔 Build #15373 failed f7ad1c7bf77fec71c4662387dfe462849f386972

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

@elastic elastic deleted a comment from elasticmachine Dec 27, 2019
@kibanamachine
Copy link
Contributor

💔 Build Failed

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

@kibanamachine
Copy link
Contributor

💔 Build Failed

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

@walterra
Copy link
Contributor Author

walterra commented Jan 2, 2020

@peteharverson I pushed some updates:

  • With further updates and better use of useObservable I was able to remove a lot of legacy code and some of our own utilities. The code for severity and interval controls no longer has custom services.
  • If I select a cell in the (view by) swimlane, and then refresh the browser, the time filter setting should no longer reset to last 15 minutes and the view should be populated.
  • Moving back between jobs list and anomaly explorer should load the correct data.

I'm still working on fixing Single Metric Viewer but Anomaly Explorer should be ready for another go at testing.

@walterra walterra force-pushed the ml-fix-react-router-appstate branch from df9770d to 8a58e37 Compare January 2, 2020 09:35
@jgowdyelastic
Copy link
Member

I've found an issue when switching jobs with multiple detectors in the single metric viewer.
Job A - 2 detectors
Job B - 1 detector

Open job A, select the second detector so the URL contains detectorIndex:1
Switch to job B using the Edit job selection flyout.

It appears it attempts to load the detector at index 1 in job B which doesn't exist. This causes the page to crash.

@walterra
Copy link
Contributor Author

@jgowdyelastic thx for spotting the issue with detectorIndex, I pushed a fix in ff12232.

@walterra
Copy link
Contributor Author

@alvarezmelissa87 I pushed another fix for restoring the correct view-by field when multiple jobs are selected in 8edb24d.

@peteharverson
Copy link
Contributor

peteharverson commented Jan 13, 2020

If I view a job in the Anomaly Explorer which is not supported in the Single Metric Viewer (such as a categorization job without model plot enabled), and then switch to the Single Metric Viewer directly by the nav menu, the content area is blank, with errors in the console:

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.

Tested and latest edits LGTM ⚡️

@peteharverson
Copy link
Contributor

Probably one for a follow-up, but for a job with multiple influencer fields, if I'm viewing by one of the influencers, but then filter by one of the other influencers, the combination of the view by dropdown value and info message is confusing:

image

Ideally the dropdown value above should stay as 'instance'. or it should be changed to by 'region'.

@walterra
Copy link
Contributor Author

@peteharverson thanks for identifying those, suggest to do those in a follow up.

Copy link
Member

@jgowdyelastic jgowdyelastic left a comment

Choose a reason for hiding this comment

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

LGTM. Great job!

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.

Overall LGTM! Only found a couple of minor edge cases, which can be addressed in follow-up fixes.

@walterra walterra merged commit 6826ece into elastic:master Jan 13, 2020
walterra added a commit to walterra/kibana that referenced this pull request Jan 13, 2020
Replaces appState/globalState with a custom hook useUrlState().
@walterra walterra deleted the ml-fix-react-router-appstate branch January 13, 2020 17:18
jgowdyelastic pushed a commit that referenced this pull request Jan 14, 2020
Replaces appState/globalState with a custom hook useUrlState().

Co-authored-by: Elastic Machine <[email protected]>
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

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

jkelastic pushed a commit to jkelastic/kibana that referenced this pull request Jan 17, 2020
Replaces appState/globalState with a custom hook useUrlState().
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 Feature:New Platform :ml refactoring regression release_note:skip Skip the PR/issue when compiling release notes v7.6.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ML] Anomaly explorer throws error: could not parse global or app state [ML] Fix appState/globalState
7 participants