Skip to content

Commit b658baf

Browse files
[Metrics Alerts] Fix alerting on a rate aggregation (#58789)
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent 0f329f5 commit b658baf

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

x-pack/plugins/infra/server/lib/alerting/metric_threshold/register_metric_threshold_alert_type.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import uuid from 'uuid';
77
import { i18n } from '@kbn/i18n';
88
import { schema } from '@kbn/config-schema';
9+
import { networkTraffic } from '../../../../common/inventory_models/shared/metrics/snapshot/network_traffic';
910
import {
1011
MetricThresholdAlertTypeParams,
1112
Comparator,
@@ -26,6 +27,17 @@ async function getMetric(
2627
{ metric, aggType, timeUnit, timeSize, indexPattern }: MetricThresholdAlertTypeParams
2728
) {
2829
const interval = `${timeSize}${timeUnit}`;
30+
const aggregations =
31+
aggType === 'rate'
32+
? networkTraffic('aggregatedValue', metric)
33+
: {
34+
aggregatedValue: {
35+
[aggType]: {
36+
field: metric,
37+
},
38+
},
39+
};
40+
2941
const searchBody = {
3042
query: {
3143
bool: {
@@ -50,13 +62,7 @@ async function getMetric(
5062
field: '@timestamp',
5163
fixed_interval: interval,
5264
},
53-
aggregations: {
54-
aggregatedValue: {
55-
[aggType]: {
56-
field: metric,
57-
},
58-
},
59-
},
65+
aggregations,
6066
},
6167
},
6268
};

0 commit comments

Comments
 (0)