Skip to content

Commit

Permalink
[ML] Use constant metric, revert code removal, update function descri…
Browse files Browse the repository at this point in the history
…ption type signature
  • Loading branch information
qn895 committed Nov 9, 2020
1 parent 595b8b3 commit 64ecedb
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
import { MULTI_BUCKET_IMPACT } from '../../../../common/constants/multi_bucket_impact';
import { formatValue } from '../../formatters/format_value';
import { MAX_CHARS } from './anomalies_table_constants';
import { ML_JOB_AGGREGATION } from '../../../../common/constants/aggregation_types';

const TIME_FIELD_NAME = 'timestamp';

Expand Down Expand Up @@ -130,7 +131,8 @@ function getDetailsItems(anomaly, examples, filter) {
title: i18n.translate('xpack.ml.anomaliesTable.anomalyDetails.functionTitle', {
defaultMessage: 'function',
}),
description: source.function !== 'metric' ? source.function : source.function_description,
description:
source.function !== ML_JOB_AGGREGATION.METRIC ? source.function : source.function_description,
});

if (source.field_name !== undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { getEntityFieldList } from '../../../../common/util/anomaly_utils';
import { buildConfigFromDetector } from '../../util/chart_config_builder';
import { mlJobService } from '../../services/job_service';
import { mlFunctionToESAggregation } from '../../../../common/util/job_utils';
import { ML_JOB_AGGREGATION } from '../../../../common/constants/aggregation_types';

// Builds the chart configuration for the provided anomaly record, returning
// an object with properties used for the display (series function and field, aggregation interval etc),
Expand Down Expand Up @@ -49,7 +50,7 @@ export function buildConfig(record) {
// define the metric series to be plotted.
config.entityFields = getEntityFieldList(record);

if (record.function === 'metric') {
if (record.function === ML_JOB_AGGREGATION.METRIC) {
config.metricFunction = mlFunctionToESAggregation(record.function_description);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const resultsApiProvider = (httpService: HttpService) => ({
maxRecords: number,
maxExamples?: number,
influencersFilterQuery?: any,
functionDescription?: string | undefined
functionDescription?: string
) {
const body = JSON.stringify({
jobIds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ export function resultsServiceRxProvider(mlApiServices: MlApiServices) {
earliestMs: number | null,
latestMs: number | null,
maxResults: number | undefined,
functionDescription?: string | undefined
functionDescription?: string
): Observable<RecordsForCriteria> {
const obj: RecordsForCriteria = { success: true, records: [] };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ToastNotificationService } from '../services/toast_notification_service
import { getControlsForDetector } from './get_controls_for_detector';
import { getCriteriaFields } from './get_criteria_fields';
import { CombinedJob } from '../../../common/types/anomaly_detection_jobs';
import { ML_JOB_AGGREGATION } from '../../../common/constants/aggregation_types';

/**
* Get the function description from the record with the highest anomaly score
Expand All @@ -30,7 +31,11 @@ export const getFunctionDescription = async (
) => {
// if the detector's function is metric, fetch the highest scoring anomaly record
// and set to plot the function_description (avg/min/max) of that record by default
if (selectedJob?.analysis_config?.detectors[selectedDetectorIndex]?.function !== 'metric') return;
if (
selectedJob?.analysis_config?.detectors[selectedDetectorIndex]?.function !==
ML_JOB_AGGREGATION.METRIC
)
return;

const entityControls = getControlsForDetector(
selectedDetectorIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,11 @@ export class TimeSeriesExplorer extends React.Component {

const { loadCounter: currentLoadCounter, functionDescription } = this.state;

const functionToPlotByIfMetric = aggregationTypeTransform.toES(functionDescription);

const currentSelectedJob = mlJobService.getJob(selectedJobId);
if (currentSelectedJob === undefined) {
return;
}
const functionToPlotByIfMetric = aggregationTypeTransform.toES(functionDescription);

this.contextChartSelectedInitCallDone = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function getFocusData(
nonBlankEntities: any[],
searchBounds: any,
selectedJob: Job,
functionDescription: string | undefined
functionDescription?: string | undefined
): Observable<FocusData> {
const esFunctionToPlotIfMetric =
functionDescription !== undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { parseInterval } from '../../../../common/util/parse_interval';
import { getBoundsRoundedToInterval, getTimeBucketsFromCache } from '../../util/time_buckets';

import { CHARTS_POINT_TARGET, TIME_FIELD_NAME } from '../timeseriesexplorer_constants';
import { ML_JOB_AGGREGATION } from '../../../../common/constants/aggregation_types';

// create new job objects based on standard job config objects
// new job objects just contain job id, bucket span in seconds and a selected flag.
Expand Down Expand Up @@ -143,7 +144,11 @@ export function processDataForFocusAnomalies(
// Look for a chart point with the same time as the record.
// If none found, find closest time in chartData set.
const recordTime = record[TIME_FIELD_NAME];
if (record.function === 'metric' && record.function_description !== functionDescription) return;
if (
record.function === ML_JOB_AGGREGATION.METRIC &&
record.function_description !== functionDescription
)
return;

const chartPoint = findChartPointForAnomalyTime(chartData, recordTime, aggregationInterval);
if (chartPoint !== undefined) {
Expand All @@ -163,7 +168,7 @@ export function processDataForFocusAnomalies(
chartPoint.value = record.actual;
}

if (record.function === 'metric') {
if (record.function === ML_JOB_AGGREGATION.METRIC) {
chartPoint.value = Array.isArray(record.actual) ? record.actual[0] : record.actual;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function resultsServiceProvider(mlClient: MlClient) {
maxRecords: number = ANOMALIES_TABLE_DEFAULT_QUERY_SIZE,
maxExamples: number = DEFAULT_MAX_EXAMPLES,
influencersFilterQuery?: any,
functionDescription?: string | undefined
functionDescription?: string
) {
// Build the query to return the matching anomaly record results.
// Add criteria for the time range, record score, plus any specified job IDs.
Expand Down

0 comments on commit 64ecedb

Please sign in to comment.