Skip to content

Commit

Permalink
[Metrics Alerts] Fix alerting on a rate aggregation (elastic#58789)
Browse files Browse the repository at this point in the history
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
Zacqary and elasticmachine committed Feb 28, 2020
1 parent 4db8acd commit 20dd0cf
Showing 1 changed file with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import uuid from 'uuid';
import { i18n } from '@kbn/i18n';
import { schema } from '@kbn/config-schema';
import { networkTraffic } from '../../../../common/inventory_models/shared/metrics/snapshot/network_traffic';
import {
MetricThresholdAlertTypeParams,
Comparator,
Expand All @@ -26,6 +27,17 @@ async function getMetric(
{ metric, aggType, timeUnit, timeSize, indexPattern }: MetricThresholdAlertTypeParams
) {
const interval = `${timeSize}${timeUnit}`;
const aggregations =
aggType === 'rate'
? networkTraffic('aggregatedValue', metric)
: {
aggregatedValue: {
[aggType]: {
field: metric,
},
},
};

const searchBody = {
query: {
bool: {
Expand All @@ -50,13 +62,7 @@ async function getMetric(
field: '@timestamp',
fixed_interval: interval,
},
aggregations: {
aggregatedValue: {
[aggType]: {
field: metric,
},
},
},
aggregations,
},
},
};
Expand Down

0 comments on commit 20dd0cf

Please sign in to comment.