-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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] Add option for anomaly charts for metric detector should plot min, mean or max as appropriate #81662
[ML] Add option for anomaly charts for metric detector should plot min, mean or max as appropriate #81662
Changes from 9 commits
7a4e9a0
26aa395
ffce815
3c8972a
5fff206
eda2c30
d1071a3
85f1526
21bb6cb
a583988
e27e433
cb2429e
9f51223
759a3f8
19e20ee
ea8d71f
97e0fc3
f694868
09fe186
12b32ad
638ed89
3c02f4f
5350e3d
a7e2482
2f028cd
595b8b3
64ecedb
df26340
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,8 +24,9 @@ export const resultsApiProvider = (httpService: HttpService) => ({ | |
latestMs: number, | ||
dateFormatTz: string, | ||
maxRecords: number, | ||
maxExamples: number, | ||
influencersFilterQuery: any | ||
maxExamples?: number, | ||
influencersFilterQuery?: any, | ||
actualPlotFunction?: string | undefined | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this should be renamed to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated here cb2429e |
||
) { | ||
const body = JSON.stringify({ | ||
jobIds, | ||
|
@@ -39,6 +40,7 @@ export const resultsApiProvider = (httpService: HttpService) => ({ | |
maxRecords, | ||
maxExamples, | ||
influencersFilterQuery, | ||
actualPlotFunction, | ||
}); | ||
|
||
return httpService.http$<any>({ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1272,7 +1272,14 @@ export function resultsServiceProvider(mlApiServices) { | |
// criteria, time range, and aggregation interval. | ||
// criteriaFields parameter must be an array, with each object in the array having 'fieldName' | ||
// 'fieldValue' properties. | ||
getRecordMaxScoreByTime(jobId, criteriaFields, earliestMs, latestMs, intervalMs) { | ||
getRecordMaxScoreByTime( | ||
jobId, | ||
criteriaFields, | ||
earliestMs, | ||
latestMs, | ||
intervalMs, | ||
actualPlotFunctionIfMetric | ||
) { | ||
return new Promise((resolve, reject) => { | ||
const obj = { | ||
success: true, | ||
|
@@ -1300,6 +1307,14 @@ export function resultsServiceProvider(mlApiServices) { | |
}, | ||
}); | ||
}); | ||
if (actualPlotFunctionIfMetric !== undefined && actualPlotFunctionIfMetric !== 'unknown') { | ||
mustCriteria.push({ | ||
term: { | ||
function_description: | ||
actualPlotFunctionIfMetric === 'avg' ? 'mean' : actualPlotFunctionIfMetric, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you use the enums out of |
||
}, | ||
}); | ||
} | ||
|
||
mlApiServices.results | ||
.anomalySearch({ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export { PlotByFunctionControls } from './plot_function_controls'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import React from 'react'; | ||
import { EuiFlexItem, EuiFormRow, EuiSelect } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
const plotByFunctionOptions = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it necessary to translate these since they relate to Elasticsearch aggregations? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since these are not strict terms that are excluded in the translation guide, I'll keep these translations here. |
||
{ | ||
value: 'avg', | ||
text: i18n.translate('xpack.ml.timeSeriesExplorer.plotByAvgOptionLabel', { | ||
defaultMessage: 'average', | ||
}), | ||
}, | ||
{ | ||
value: 'min', | ||
text: i18n.translate('xpack.ml.timeSeriesExplorer.plotByMinOptionLabel', { | ||
defaultMessage: 'min', | ||
}), | ||
}, | ||
{ | ||
value: 'max', | ||
text: i18n.translate('xpack.ml.timeSeriesExplorer.plotByMaxOptionLabel', { | ||
defaultMessage: 'max', | ||
}), | ||
}, | ||
]; | ||
export const PlotByFunctionControls = ({ | ||
actualPlotFunction, | ||
setPlotByFunction, | ||
}: { | ||
actualPlotFunction: undefined | string; | ||
setPlotByFunction: (func: string) => void; | ||
}) => { | ||
if (actualPlotFunction === 'unknown' || !actualPlotFunction) return null; | ||
return ( | ||
<EuiFlexItem style={{ textAlign: 'right' }} grow={false}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to avoid inline styles, you can use EuiText with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I realized this style wasn't necessary so I removed it here a7e2482 |
||
<EuiFormRow | ||
label={i18n.translate('xpack.ml.timeSeriesExplorer.metricPlotByOption', { | ||
defaultMessage: 'Function', | ||
})} | ||
> | ||
<EuiSelect | ||
options={plotByFunctionOptions} | ||
value={actualPlotFunction ?? 'avg'} | ||
onChange={(e) => setPlotByFunction(e.target.value)} | ||
aria-label="Pick function to plot by (min, max, or average) if metric function" | ||
darnautov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/> | ||
</EuiFormRow> | ||
</EuiFlexItem> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { mlJobService } from '../services/job_service'; | ||
export const UNKNOWN_METRIC_PLOT_FUNCTION = 'unknown'; | ||
|
||
export const getPlotByOptions = ( | ||
selectedJobId: string, | ||
selectedDetectorIndex: number, | ||
currentActualPlotFunction: string | undefined, | ||
defaultFunctionToPlotIfMetric: string | undefined | ||
) => { | ||
// only load the options to view chart by 'avg', 'min', or 'max' | ||
// if the original function is 'metric' | ||
const selectedJob = mlJobService.getJob(selectedJobId); | ||
|
||
if (selectedJob === undefined) return; | ||
|
||
const detectors = selectedJob.analysis_config.detectors; | ||
|
||
if (detectors && detectors[selectedDetectorIndex]?.function) { | ||
if (detectors[selectedDetectorIndex]?.function === 'metric') { | ||
if (currentActualPlotFunction === undefined) { | ||
// here we just know the detector is a metric function, but we don't know what to plot yet | ||
// need to find the highest scoring anomaly record in order to pick the default view | ||
return defaultFunctionToPlotIfMetric || UNKNOWN_METRIC_PLOT_FUNCTION; | ||
} | ||
} else { | ||
return undefined; | ||
} | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
ML_JOB_AGGREGATION.METRIC
fromcommon/constants/aggregation_types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated here 64ecedb