diff --git a/x-pack/plugins/apm/public/components/app/ServiceMap/Popover/Contents.tsx b/x-pack/plugins/apm/public/components/app/ServiceMap/Popover/Contents.tsx index 259022bbee84e..198e189e4043f 100644 --- a/x-pack/plugins/apm/public/components/app/ServiceMap/Popover/Contents.tsx +++ b/x-pack/plugins/apm/public/components/app/ServiceMap/Popover/Contents.tsx @@ -123,6 +123,13 @@ const ANOMALY_DETECTION_NO_DATA_TEXT = i18n.translate( } ); +function getDisplayedAnomalyScore(score: number) { + if (score > 0 && score < 1) { + return '<1'; + } + return asInteger(score); +} + export function Contents({ selectedNodeData, isService, @@ -180,7 +187,7 @@ export function Contents({
- {asInteger(anomalyScore)} + {getDisplayedAnomalyScore(anomalyScore)} {anomalyDescription && (  ({anomalyDescription}) )} diff --git a/x-pack/plugins/apm/server/lib/service_map/get_service_anomalies.ts b/x-pack/plugins/apm/server/lib/service_map/get_service_anomalies.ts index 8259081709301..7b26078d5ffbf 100644 --- a/x-pack/plugins/apm/server/lib/service_map/get_service_anomalies.ts +++ b/x-pack/plugins/apm/server/lib/service_map/get_service_anomalies.ts @@ -62,7 +62,7 @@ export async function getServiceAnomalies( query: { bool: { filter: [ - { term: { result_type: 'bucket' } }, + { term: { result_type: 'record' } }, { terms: { job_id: apmJobIds, @@ -82,8 +82,8 @@ export async function getServiceAnomalies( aggs: { top_score_hits: { top_hits: { - sort: [{ anomaly_score: { order: 'desc' as const } }], - _source: ['anomaly_score', 'timestamp'], + sort: [{ record_score: { order: 'desc' as const } }], + _source: ['record_score', 'timestamp', 'typical', 'actual'], size: 1, }, }, @@ -101,7 +101,12 @@ export async function getServiceAnomalies( top_score_hits: { hits: { hits: Array<{ - _source: { anomaly_score: number; timestamp: number }; + _source: { + record_score: number; + timestamp: number; + typical: number[]; + actual: number[]; + }; }>; }; }; @@ -114,52 +119,11 @@ export async function getServiceAnomalies( const bucketSource = jobBucket.top_score_hits.hits.hits?.[0]?._source; return { jobId, - anomalyScore: bucketSource.anomaly_score, + anomalyScore: bucketSource.record_score, timestamp: bucketSource.timestamp, + typical: bucketSource.typical[0], + actual: bucketSource.actual[0], }; }); - const anomalyModelValuePromises = anomalyScores.map( - ({ jobId, timestamp }) => { - return (async () => { - try { - const modelPlotResponse = await ml.mlSystem.mlAnomalySearch({ - body: { - size: 1, - query: { - bool: { - filter: [ - { term: { result_type: 'model_plot' } }, - { term: { job_id: jobId } }, - { term: { timestamp } }, - ], - }, - }, - _source: ['actual', 'model_median'], - }, - }); - if (modelPlotResponse.hits.hits.length === 0) { - return; - } - const { actual, model_median } = modelPlotResponse.hits.hits[0] - ._source as { - actual: number; - model_median: number; - }; - return { jobId, actual, model_median }; - } catch (error) { - return; - } - })(); - } - ); - - const anomalyModelValues = ( - await Promise.all(anomalyModelValuePromises) - ).filter((value: T | undefined): value is T => value !== undefined); - - return leftJoin( - apmMlJobCategories, - 'jobId', - leftJoin(anomalyScores, 'jobId', anomalyModelValues) - ); + return leftJoin(apmMlJobCategories, 'jobId', anomalyScores); } diff --git a/x-pack/plugins/apm/server/lib/service_map/ml_helpers.test.ts b/x-pack/plugins/apm/server/lib/service_map/ml_helpers.test.ts index 9e761bd2181be..f07b575cc0a35 100644 --- a/x-pack/plugins/apm/server/lib/service_map/ml_helpers.test.ts +++ b/x-pack/plugins/apm/server/lib/service_map/ml_helpers.test.ts @@ -30,7 +30,7 @@ describe('addAnomaliesDataToNodes', () => { anomalyScore: 50, timestamp: 1591351200000, actual: 2000, - model_median: 1000, + typical: 1000, }, { jobId: 'opbeans-java-request-high_mean_response_time', @@ -39,7 +39,7 @@ describe('addAnomaliesDataToNodes', () => { anomalyScore: 100, timestamp: 1591351200000, actual: 9000, - model_median: 3000, + typical: 3000, }, ]; diff --git a/x-pack/plugins/apm/server/lib/service_map/ml_helpers.ts b/x-pack/plugins/apm/server/lib/service_map/ml_helpers.ts index 7473ec53d63c2..eb5d2b1c64bde 100644 --- a/x-pack/plugins/apm/server/lib/service_map/ml_helpers.ts +++ b/x-pack/plugins/apm/server/lib/service_map/ml_helpers.ts @@ -30,7 +30,7 @@ export function addAnomaliesDataToNodes( acc[anomalyJob.serviceName] = { anomaly_score: anomalyJob.anomalyScore, actual_value: anomalyJob.actual, - typical_value: anomalyJob.model_median, + typical_value: anomalyJob.typical, ml_job_id: anomalyJob.jobId, }; }