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] Extends support for anomaly charts when model plot is enabled #34079

Merged
merged 2 commits into from
Mar 29, 2019

Conversation

peteharverson
Copy link
Contributor

@peteharverson peteharverson commented Mar 28, 2019

Summary

Previously anomaly charts were only shown in the Anomaly Explorer, and a detector was only visible in the Single Metric Viewer, if the detector function_description was one of mean, min, max, sum, count, distinct_count, median, or rare and the detector did not use a scripted field that was defined in the datafeed configuration.

If model plot has been enabled, this PR extends support for charts in the Anomaly Explorer, and the detector is visible in the Single Metric Viewer, to detectors where:

  • the partitioning field of the detector is a script field defined in the datafeed configuration
  • the field_name of the detector is a script field defined in the datafeed configuration
  • the function_description of the detector is varp
  • the function_description of the detector is info_content
  • the partitioning field is mlcategory

e.g. of a chart in the Anomaly Explorer for an info_content job where model plot has been enabled:
image

Checklist

For maintainers

See #22922.
Fixes #32124.

@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui

@peteharverson peteharverson requested a review from a team as a code owner March 28, 2019 15:38
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

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.

Added a couple of comments, but generally it all LGTM

// of objects in the form { fieldName: airline, fieldValue: AAL, fieldType: partition }
export function getEntityFieldList(record) {
const entityFields = [];
if (_.get(record, 'partition_field_name') !== undefined) {
Copy link
Member

Choose a reason for hiding this comment

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

Using _.get for these checks unnecessary IMO.
this check could just be record.partition_field_name !== undefined.

Edit:
I just noticed this code was moved from somewhere else. so ignore this if you don't want the code churn.
At some point we should look to review _.get usage as it was flagged by kibana as potentially dangerous due to prototype pollution. If we ever use it to get a user defined key, that should change.
I'd also personally like to change any situations like the one above where it's being used to get a single, non-nested key, as it's unnecessary and adds complexity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Seeing as this is a new function, I'll switch the _.get to e.g. record.partition_field_name here.

// plus varp and info_content functions.
isModelPlotChartable = (mlFunctionToESAggregation(functionName) !== null) ||
(['varp', 'high_varp', 'low_varp', 'info_content',
'high_info_content', 'low_info_content'].indexOf(functionName) > -1);
Copy link
Member

Choose a reason for hiding this comment

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

.includes rather than .indexOf could be used here.
Doesn't gain anything really, but i think it reads a bit better.

$scope.hasResults = false;
$scope.loading = false;
$scope.dataNotChartable = true;
$scope.$applyAsync();
Copy link
Member

Choose a reason for hiding this comment

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

it doesn't look like a promise is being used in this code, is this $applyAsync needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes this $applyAsync is needed. When you are viewing an entity which triggers this block, if you then hard refresh the page, the $applyAsync is needed to get the view to update correctly and show the correct error message on initial load.

Copy link
Contributor

@walterra walterra 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

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 ⚡

@peteharverson peteharverson merged commit e00dae7 into elastic:master Mar 29, 2019
@peteharverson peteharverson deleted the ml-model-plot-scripted branch March 29, 2019 14:12
peteharverson added a commit to peteharverson/kibana that referenced this pull request Mar 29, 2019
…lastic#34079)

* [ML] Extends support for anomaly charts when model plot is enabled

* [ML] Edits to util functions following review
peteharverson added a commit that referenced this pull request Mar 29, 2019
…34079) (#34159)

* [ML] Extends support for anomaly charts when model plot is enabled

* [ML] Edits to util functions following review
@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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ML] Detectors using scripted fields with model plot enabled should be viewable in the Single Metric Viewer
6 participants