From b7a9f8c1f1237e563c4f7a3a077402f6e7544f09 Mon Sep 17 00:00:00 2001 From: Phillip Burch Date: Tue, 29 Sep 2020 08:07:29 -0500 Subject: [PATCH] Only show anomalies with a score greater than 50 --- .../server/lib/infra_ml/metrics_hosts_anomalies.ts | 10 ---------- .../infra/server/lib/infra_ml/queries/common.ts | 10 ++++++++++ .../lib/infra_ml/queries/metrics_hosts_anomalies.ts | 2 ++ .../lib/infra_ml/queries/metrics_k8s_anomalies.ts | 2 ++ 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/infra/server/lib/infra_ml/metrics_hosts_anomalies.ts b/x-pack/plugins/infra/server/lib/infra_ml/metrics_hosts_anomalies.ts index 0d18392e6a587..a3a0f91afaab8 100644 --- a/x-pack/plugins/infra/server/lib/infra_ml/metrics_hosts_anomalies.ts +++ b/x-pack/plugins/infra/server/lib/infra_ml/metrics_hosts_anomalies.ts @@ -175,16 +175,6 @@ async function fetchMetricsHostsAnomalies( const finalizeFetchLogEntryAnomaliesSpan = startTracingSpan('fetch metrics hosts anomalies'); - // console.log( - // 'data', - // JSON.stringify( - // await mlSystem.mlAnomalySearch( - // createMetricsHostsAnomaliesQuery(jobIds, startTime, endTime, sort, expandedPagination) - // ), - // null, - // 2 - // ) - // ); const results = decodeOrThrow(metricsHostsAnomaliesResponseRT)( await mlSystem.mlAnomalySearch( createMetricsHostsAnomaliesQuery(jobIds, startTime, endTime, sort, expandedPagination) diff --git a/x-pack/plugins/infra/server/lib/infra_ml/queries/common.ts b/x-pack/plugins/infra/server/lib/infra_ml/queries/common.ts index 63e39ef022392..eb08b6d692336 100644 --- a/x-pack/plugins/infra/server/lib/infra_ml/queries/common.ts +++ b/x-pack/plugins/infra/server/lib/infra_ml/queries/common.ts @@ -40,6 +40,16 @@ export const createTimeRangeFilters = (startTime: number, endTime: number) => [ }, ]; +export const createAnomalyScoreFilter = (minScore: number) => [ + { + range: { + record_score: { + gte: minScore, + }, + }, + }, +]; + export const createResultTypeFilters = (resultTypes: Array<'model_plot' | 'record'>) => [ { terms: { diff --git a/x-pack/plugins/infra/server/lib/infra_ml/queries/metrics_hosts_anomalies.ts b/x-pack/plugins/infra/server/lib/infra_ml/queries/metrics_hosts_anomalies.ts index af505255a19ed..bbdc77af1fbe6 100644 --- a/x-pack/plugins/infra/server/lib/infra_ml/queries/metrics_hosts_anomalies.ts +++ b/x-pack/plugins/infra/server/lib/infra_ml/queries/metrics_hosts_anomalies.ts @@ -11,6 +11,7 @@ import { createTimeRangeFilters, createResultTypeFilters, defaultRequestParameters, + createAnomalyScoreFilter, } from './common'; import { Sort, Pagination } from '../../../../common/http_api/infra_ml'; @@ -35,6 +36,7 @@ export const createMetricsHostsAnomaliesQuery = ( const filters = [ ...createJobIdsFilters(jobIds), + ...createAnomalyScoreFilter(50), ...createTimeRangeFilters(startTime, endTime), ...createResultTypeFilters(['record']), ]; diff --git a/x-pack/plugins/infra/server/lib/infra_ml/queries/metrics_k8s_anomalies.ts b/x-pack/plugins/infra/server/lib/infra_ml/queries/metrics_k8s_anomalies.ts index 104a0e7ccfca4..79bfdc91dc5a4 100644 --- a/x-pack/plugins/infra/server/lib/infra_ml/queries/metrics_k8s_anomalies.ts +++ b/x-pack/plugins/infra/server/lib/infra_ml/queries/metrics_k8s_anomalies.ts @@ -11,6 +11,7 @@ import { createTimeRangeFilters, createResultTypeFilters, defaultRequestParameters, + createAnomalyScoreFilter, } from './common'; import { Sort, Pagination } from '../../../../common/http_api/infra_ml'; @@ -35,6 +36,7 @@ export const createMetricsK8sAnomaliesQuery = ( const filters = [ ...createJobIdsFilters(jobIds), + ...createAnomalyScoreFilter(50), ...createTimeRangeFilters(startTime, endTime), ...createResultTypeFilters(['record']), ];