Skip to content

Commit

Permalink
[Metrics Alerts] Fix alerting on a rate aggregation (#58789) (#58926)
Browse files Browse the repository at this point in the history
Co-authored-by: Elastic Machine <[email protected]>

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
Zacqary and elasticmachine authored Feb 28, 2020
1 parent 36651d8 commit b8f673b
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 {
MetricExpressionParams,
Comparator,
Expand All @@ -26,6 +27,17 @@ async function getMetric(
{ metric, aggType, timeUnit, timeSize, indexPattern }: MetricExpressionParams
) {
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 b8f673b

Please sign in to comment.