-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[APM] Garbage collection metrics charts
Closes #36320.
- Loading branch information
1 parent
1592600
commit 227b160
Showing
11 changed files
with
297 additions
and
7 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
x-pack/legacy/plugins/apm/common/__snapshots__/elasticsearch_fieldnames.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
155 changes: 155 additions & 0 deletions
155
x-pack/legacy/plugins/apm/server/lib/metrics/by_agent/java/gc/fetchAndTransformGcMetrics.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,155 @@ | ||
/* | ||
* 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. | ||
*/ | ||
/* | ||
* 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 { idx } from '@kbn/elastic-idx'; | ||
import theme from '@elastic/eui/dist/eui_theme_light.json'; | ||
import { Setup } from '../../../../helpers/setup_request'; | ||
import { getMetricsDateHistogramParams } from '../../../../helpers/metrics'; | ||
import { ChartBase } from '../../../types'; | ||
import { getMetricsProjection } from '../../../../../../common/projections/metrics'; | ||
import { mergeProjection } from '../../../../../../common/projections/util/merge_projection'; | ||
import { | ||
SERVICE_AGENT_NAME, | ||
LABELS, | ||
METRIC_JAVA_GC_COUNT, | ||
METRIC_JAVA_GC_TIME | ||
} from '../../../../../../common/elasticsearch_fieldnames'; | ||
|
||
const colors = [ | ||
theme.euiColorVis0, | ||
theme.euiColorVis1, | ||
theme.euiColorVis2, | ||
theme.euiColorVis3, | ||
theme.euiColorVis4, | ||
theme.euiColorVis5, | ||
theme.euiColorVis6 | ||
]; | ||
|
||
export async function fetchAndTransformGcMetrics({ | ||
setup, | ||
serviceName, | ||
serviceNodeName, | ||
chartBase, | ||
fieldName | ||
}: { | ||
setup: Setup; | ||
serviceName: string; | ||
serviceNodeName?: string; | ||
chartBase: ChartBase; | ||
fieldName: typeof METRIC_JAVA_GC_COUNT | typeof METRIC_JAVA_GC_TIME; | ||
}) { | ||
const { start, end, client } = setup; | ||
|
||
const projection = getMetricsProjection({ | ||
setup, | ||
serviceName, | ||
serviceNodeName | ||
}); | ||
|
||
const params = mergeProjection(projection, { | ||
body: { | ||
size: 0, | ||
query: { | ||
bool: { | ||
filter: [ | ||
...projection.body.query.bool.filter, | ||
{ exists: { field: fieldName } }, | ||
{ term: { [SERVICE_AGENT_NAME]: 'java' } } | ||
] | ||
} | ||
}, | ||
aggs: { | ||
per_pool: { | ||
terms: { | ||
field: `${LABELS}.name` | ||
}, | ||
aggs: { | ||
average: { | ||
avg: { | ||
field: fieldName | ||
} | ||
}, | ||
over_time: { | ||
date_histogram: getMetricsDateHistogramParams(start, end), | ||
aggs: { | ||
max: { | ||
max: { | ||
field: fieldName | ||
} | ||
}, | ||
derivative: { | ||
derivative: { | ||
buckets_path: 'max' | ||
} | ||
}, | ||
value: { | ||
bucket_script: { | ||
buckets_path: { value: 'derivative' }, | ||
script: 'params.value > 0.0 ? params.value : 0.0' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
|
||
const response = await client.search(params); | ||
|
||
const aggregations = idx(response, _ => _.aggregations); | ||
|
||
if (!aggregations) { | ||
return { | ||
...chartBase, | ||
totalHits: 0, | ||
series: [] | ||
}; | ||
} | ||
|
||
const series = aggregations.per_pool.buckets.map((poolBucket, i) => { | ||
const label = poolBucket.key; | ||
const timeseriesData = poolBucket.over_time; | ||
|
||
const overallValue = poolBucket.average.value; | ||
|
||
return { | ||
title: label, | ||
key: label, | ||
type: chartBase.type, | ||
color: colors[i], | ||
overallValue, | ||
data: (idx(timeseriesData, _ => _.buckets) || []).map((bucket, index) => { | ||
if (!('value' in bucket)) { | ||
// derivative/value will be undefined for the first hit | ||
return { | ||
x: bucket.key, | ||
y: 0 | ||
}; | ||
} | ||
|
||
const { value } = bucket.value; | ||
const y = value === null || isNaN(value) ? null : value; | ||
return { | ||
x: bucket.key, | ||
y | ||
}; | ||
}) | ||
}; | ||
}); | ||
|
||
return { | ||
...chartBase, | ||
totalHits: response.hits.total, | ||
series | ||
}; | ||
} |
47 changes: 47 additions & 0 deletions
47
x-pack/legacy/plugins/apm/server/lib/metrics/by_agent/java/gc/getGcRateChart.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,47 @@ | ||
/* | ||
* 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 theme from '@elastic/eui/dist/eui_theme_light.json'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { METRIC_JAVA_GC_COUNT } from '../../../../../../common/elasticsearch_fieldnames'; | ||
import { Setup } from '../../../../helpers/setup_request'; | ||
import { fetchAndTransformGcMetrics } from './fetchAndTransformGcMetrics'; | ||
import { ChartBase } from '../../../types'; | ||
|
||
const series = { | ||
[METRIC_JAVA_GC_COUNT]: { | ||
title: i18n.translate('xpack.apm.agentMetrics.java.gcRate', { | ||
defaultMessage: 'GC count' | ||
}), | ||
color: theme.euiColorVis0 | ||
} | ||
}; | ||
|
||
const chartBase: ChartBase = { | ||
title: i18n.translate('xpack.apm.agentMetrics.java.gcCountChartTitle', { | ||
defaultMessage: 'Garbage collection count' | ||
}), | ||
key: 'gc_count_line_chart', | ||
type: 'linemark', | ||
yUnit: 'number', | ||
series | ||
}; | ||
|
||
const getGcRateChart = ( | ||
setup: Setup, | ||
serviceName: string, | ||
serviceNodeName?: string | ||
) => { | ||
return fetchAndTransformGcMetrics({ | ||
setup, | ||
serviceName, | ||
serviceNodeName, | ||
chartBase, | ||
fieldName: METRIC_JAVA_GC_COUNT | ||
}); | ||
}; | ||
|
||
export { getGcRateChart }; |
47 changes: 47 additions & 0 deletions
47
x-pack/legacy/plugins/apm/server/lib/metrics/by_agent/java/gc/getGcTimeChart.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,47 @@ | ||
/* | ||
* 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 theme from '@elastic/eui/dist/eui_theme_light.json'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { METRIC_JAVA_GC_TIME } from '../../../../../../common/elasticsearch_fieldnames'; | ||
import { Setup } from '../../../../helpers/setup_request'; | ||
import { fetchAndTransformGcMetrics } from './fetchAndTransformGcMetrics'; | ||
import { ChartBase } from '../../../types'; | ||
|
||
const series = { | ||
[METRIC_JAVA_GC_TIME]: { | ||
title: i18n.translate('xpack.apm.agentMetrics.java.gcTime', { | ||
defaultMessage: 'GC time' | ||
}), | ||
color: theme.euiColorVis0 | ||
} | ||
}; | ||
|
||
const chartBase: ChartBase = { | ||
title: i18n.translate('xpack.apm.agentMetrics.java.gcTimeChartTitle', { | ||
defaultMessage: 'Garbage collection time' | ||
}), | ||
key: 'gc_time_line_chart', | ||
type: 'linemark', | ||
yUnit: 'time', | ||
series | ||
}; | ||
|
||
const getGcTimeChart = ( | ||
setup: Setup, | ||
serviceName: string, | ||
serviceNodeName?: string | ||
) => { | ||
return fetchAndTransformGcMetrics({ | ||
setup, | ||
serviceName, | ||
serviceNodeName, | ||
chartBase, | ||
fieldName: METRIC_JAVA_GC_TIME | ||
}); | ||
}; | ||
|
||
export { getGcTimeChart }; |
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
Oops, something went wrong.