forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reintroduces the previous anomaly detection ML integration back into the
transaction duration chart in the service details screen. Support the latest APM anoamly detection by environment jobs.
- Loading branch information
Showing
10 changed files
with
396 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
x-pack/plugins/apm/server/lib/transactions/charts/get_anomaly_data/fetcher.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* 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 { PromiseReturnType } from '../../../../../../observability/typings/common'; | ||
import { Setup, SetupTimeRange } from '../../../helpers/setup_request'; | ||
|
||
export type ESResponse = Exclude< | ||
PromiseReturnType<typeof anomalySeriesFetcher>, | ||
undefined | ||
>; | ||
|
||
export async function anomalySeriesFetcher({ | ||
serviceName, | ||
transactionType, | ||
intervalString, | ||
mlBucketSize, | ||
setup, | ||
jobId, | ||
}: { | ||
serviceName: string; | ||
transactionType: string; | ||
intervalString: string; | ||
mlBucketSize: number; | ||
setup: Setup & SetupTimeRange; | ||
jobId: string; | ||
}) { | ||
const { ml, start, end } = setup; | ||
if (!ml) { | ||
return; | ||
} | ||
|
||
// move the start back with one bucket size, to ensure to get anomaly data in the beginning | ||
// this is required because ML has a minimum bucket size (default is 900s) so if our buckets are smaller, we might have several null buckets in the beginning | ||
const newStart = start - mlBucketSize * 1000; | ||
|
||
const params = { | ||
body: { | ||
size: 0, | ||
query: { | ||
bool: { | ||
filter: [ | ||
{ term: { job_id: jobId } }, | ||
{ exists: { field: 'bucket_span' } }, | ||
{ | ||
term: { | ||
result_type: 'model_plot', | ||
}, | ||
}, | ||
{ | ||
term: { | ||
partition_field_value: serviceName, | ||
}, | ||
}, | ||
{ | ||
term: { | ||
by_field_value: transactionType, | ||
}, | ||
}, | ||
{ | ||
range: { | ||
timestamp: { | ||
gte: newStart, | ||
lte: end, | ||
format: 'epoch_millis', | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
aggs: { | ||
ml_avg_response_times: { | ||
date_histogram: { | ||
field: 'timestamp', | ||
fixed_interval: intervalString, | ||
min_doc_count: 0, | ||
extended_bounds: { | ||
min: newStart, | ||
max: end, | ||
}, | ||
}, | ||
aggs: { | ||
anomaly_score: { max: { field: 'anomaly_score' } }, | ||
lower: { min: { field: 'model_lower' } }, | ||
upper: { max: { field: 'model_upper' } }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
try { | ||
const response = await ml.mlSystem.mlAnomalySearch(params); | ||
return response; | ||
} catch (err) { | ||
const isHttpError = 'statusCode' in err; | ||
if (isHttpError) { | ||
return; | ||
} | ||
throw err; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
x-pack/plugins/apm/server/lib/transactions/charts/get_anomaly_data/get_ml_bucket_size.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* 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 { Setup, SetupTimeRange } from '../../../helpers/setup_request'; | ||
|
||
interface IOptions { | ||
serviceName: string; | ||
transactionType: string; | ||
setup: Setup & SetupTimeRange; | ||
jobId: string; | ||
} | ||
|
||
interface ESResponse { | ||
bucket_span: number; | ||
} | ||
|
||
export async function getMlBucketSize({ | ||
serviceName, | ||
transactionType, | ||
setup, | ||
jobId, | ||
}: IOptions): Promise<number> { | ||
const { ml, start, end } = setup; | ||
if (!ml) { | ||
return 0; | ||
} | ||
|
||
const params = { | ||
body: { | ||
_source: 'bucket_span', | ||
size: 1, | ||
query: { | ||
bool: { | ||
filter: [ | ||
{ term: { job_id: jobId } }, | ||
{ exists: { field: 'bucket_span' } }, | ||
{ | ||
range: { | ||
timestamp: { | ||
gte: start, | ||
lte: end, | ||
format: 'epoch_millis', | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
try { | ||
const resp = await ml.mlSystem.mlAnomalySearch<ESResponse>(params); | ||
return resp.hits.hits[0]?._source.bucket_span || 0; | ||
} catch (err) { | ||
const isHttpError = 'statusCode' in err; | ||
if (isHttpError) { | ||
return 0; | ||
} | ||
throw err; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.