Skip to content

[ML] Fix Limit Dropdown, simplify state management of Anomaly Explorer.#23388

Merged
walterra merged 22 commits intoelastic:masterfrom
walterra:ml-swimlane-fix-selection
Sep 24, 2018
Merged

[ML] Fix Limit Dropdown, simplify state management of Anomaly Explorer.#23388
walterra merged 22 commits intoelastic:masterfrom
walterra:ml-swimlane-fix-selection

Conversation

@walterra
Copy link
Copy Markdown
Contributor

@walterra walterra commented Sep 21, 2018

Fixes #18996 and #18538.

This fixes the limit dropdown behavior. The fix for that is actually just the $scope.appState.fetch(); statements in explorer_controller.js, they avoid to run the information stored in appState across modules out of sync.

Additionally, the aim of this PR is to simplify the state management of Anomaly Explorer in the context of selecting cells in the swimlanes and updating the influencers list, charts and table accordingly.

Previously, esp. restoring a selection from URL/AppState involved a lot of complexity, something like:

Initial Load -> Load Overall Swimlane -> Load View By Swimlane -> Inside the swimlane code, check for a selection in AppState, if yes, use that data to trigger a swimlane selection click programmatically -> trigger the click listener again in Anomaly Explorer controller -> update $scope.cellData and trigger updating swimlanes/influencers/charts/table again

This has now been reduced to:

Check URL/AppState on initial load and restore $scope.cellData -> use updateExplorer() to update swimlanes/charts/influencers/table considering the selection

Here's some more detail about what's done in this PR:

  • The swimlanes state handling has been improved: click events no longer manipulate the DOM, only renderSwimlane() does that now. That means: click events only trigger listeners and send data (data out, no DOM manipulation); props include all the information necessary to render the swimlanes including selections (data in, update the DOM)
  • The swimlanes wrapper directives no longer require to pass through angularjs scope from the Anomaly Explorer controller. The props for the swimlanes are now prepared in the controller and handed on via the swimlaneDataChange listener.
  • Some issues with race conditions have been fixed involved with restoring a selection from URL/AppState, for example the Anomaly Explorer controller now waits for isChartsContainerInitialized to make sure the Charts Container directive is ready before passing on data to the charts. Previously child directives could miss updates if their link wasn't called yet which included setting up event listeners.
  • updateExplorer() was introduced to be able to trigger the same kind of update when we restore or do a selection on load or via click to avoid the event circling described in the beginning. That way the complexity/redundancy of swimlaneCellClickListener() could be reduced, it now just saves a new selection in appState and $scope.cellData, then triggers updateExporer().
  • The limit dropdown has been migrated to use React, this is more or less a copy of the interval dropdown. Reverted that conversion - it was originally done while trying to fix the bug related to the dropdown but it turned out to be not related. With that conversion the dropdowns for "view by" and "limit" would end up having different appearance so that should be done in a separate PR.

Everything of the above is a preparation to move explorer_controller at one point out of the anguarljs universe and make it an independent service that just manages state, similar to how it was done for explorerChartsContainerService.


Part of #22642 and #18374.

@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/ml-ui

@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

@walterra walterra changed the title [WIP] [ML] Simplify state management of Anomaly Explorer [WIP] [ML] Fix Limit Dropdown, simplify state management of Anomaly Explorer. Sep 22, 2018
@walterra walterra added the WIP Work in progress label Sep 22, 2018
@walterra walterra force-pushed the ml-swimlane-fix-selection branch from 12efbb7 to b7342f0 Compare September 22, 2018 09:30
@walterra walterra changed the title [WIP] [ML] Fix Limit Dropdown, simplify state management of Anomaly Explorer. [ML] Fix Limit Dropdown, simplify state management of Anomaly Explorer. Sep 22, 2018
@walterra walterra removed the WIP Work in progress label Sep 22, 2018
@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

@walterra
Copy link
Copy Markdown
Contributor Author

retest

const selectedJobIds = $scope.getSelectedJobIds();
const limit = mlSelectLimitService.state.get('limit');
const swimlaneLimit = (limit === undefined) ? 10 : limit.val;
const swimlaneLimit = (limit === undefined) ? 10 : limit;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can the default limit of 10 be moved to a constant at the top of the file?

const selectedJobIds = $scope.getSelectedJobIds();
const limit = mlSelectLimitService.state.get('limit');
const swimlaneLimit = (limit === undefined) ? 10 : limit.val;
const swimlaneLimit = (limit === undefined) ? 10 : limit;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can the default limit of 10 be moved to a constant at the top of the file?

};
}

const SWIMLANE_TYPE = {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would explorer_constants.js be a better place for these?

return limit;
}

class SelectLimit extends Component {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This needs a corresponding Jest test. Can the current Angular based tests inside __tests__/select_limit.js be removed if a Jest test is added?

@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

@walterra walterra added the bug Fixes for quality problems that affect the customer experience label Sep 24, 2018
Copy link
Copy Markdown
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.

added a few small comments but otherwise LGTM

) {
let selectionExists = false;
$scope.cellData.lanes.forEach((lane) => {
if ($scope.viewBySwimlaneData.laneLabels.indexOf(lane) > -1) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looks like this could be done with some to save those few extra loops :)

// which is where d3 supplies a reference to the corresponding DOM element.
return function (lane) {
const bucketScore = getBucketScore(lane, time);
if (bucketScore === 0) { return; }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit, rather than breaking out of this function early, you could invert the check:

if (bucketScore !== 0) {
  cellMouseover(this, lane, bucketScore, i, time);
}


expect(wrapper.html()).toBe(
`<div class="ml-swimlanes"><div class="time-tick-labels"><svg height="25">` +
`<div class="ml-swimlanes"><div class="time-tick-labels"><svg width="800" height="25">` +
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit, chartWidth should be used for the width

appState={mocks.appState}
lanes={[]}
mlExplorerDashboardService={mocks.mlExplorerDashboardService}
chartWidth={800}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit, 800 should come from a constant variable

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

@jgowdyelastic
Copy link
Copy Markdown
Member

latest changes LGTM

Copy link
Copy Markdown
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.

Latest edits LGTM

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

@walterra walterra merged commit c5d475f into elastic:master Sep 24, 2018
walterra added a commit to walterra/kibana that referenced this pull request Sep 24, 2018
…r. (elastic#23388)

- This fixes the limit dropdown behavior. The fix for that is actually just the $scope.appState.fetch(); statements in explorer_controller.js, they avoid to run the information stored in appState across modules out of sync.
- Additionally, the aim of this PR is to simplify the state management of Anomaly Explorer in the context of selecting cells in the swimlanes and updating the influencers list, charts and table accordingly.
walterra added a commit that referenced this pull request Sep 24, 2018
…r. (#23388) (#23440)

- This fixes the limit dropdown behavior. The fix for that is actually just the $scope.appState.fetch(); statements in explorer_controller.js, they avoid to run the information stored in appState across modules out of sync.
- Additionally, the aim of this PR is to simplify the state management of Anomaly Explorer in the context of selecting cells in the swimlanes and updating the influencers list, charts and table accordingly.
Copy link
Copy Markdown
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.

I know I'm a bit late on this one but LGTM! 😸
Thanks for the great context in the description, as well!

@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

@sophiec20 sophiec20 added the Feature:Anomaly Detection ML anomaly detection label Jun 19, 2019
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:ml-results legacy - do not use :ml v6.5.0 v7.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ML] Anomalies table inconsistent with swimlane selection after changing swimlane limit

6 participants