Skip to content

Commit

Permalink
Add metric_agg_script to MetricAggregationRule
Browse files Browse the repository at this point in the history
Copied from SpikeMetricAggregationRule, which originally copied
generate_aggregation_query from MetricAggregationRule and added these
two lines.

So this commit just makes the two generate_aggregation_query look the
same, which just works and I'm not really sure why no one has done it
before.
  • Loading branch information
dequis committed Nov 15, 2021
1 parent ab9a1d0 commit 742c2c8
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion elastalert/ruletypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,8 @@ def get_match_str(self, match):
return message

def generate_aggregation_query(self):
if self.rules.get('metric_agg_script'):
return {self.metric_key: {self.rules['metric_agg_type']: self.rules['metric_agg_script']}}
query = {self.metric_key: {self.rules['metric_agg_type']: {'field': self.rules['metric_agg_key']}}}
if self.rules['metric_agg_type'] in self.allowed_percent_aggregations:
query[self.metric_key][self.rules['metric_agg_type']]['percents'] = [self.rules['percentile_range']]
Expand Down Expand Up @@ -1175,7 +1177,7 @@ def __init__(self, *args):
self.rules['aggregation_query_element'] = self.generate_aggregation_query()

def generate_aggregation_query(self):
"""Lifted from MetricAggregationRule, added support for scripted fields"""
"""Lifted from MetricAggregationRule"""
if self.rules.get('metric_agg_script'):
return {self.metric_key: {self.rules['metric_agg_type']: self.rules['metric_agg_script']}}
query = {self.metric_key: {self.rules['metric_agg_type']: {'field': self.rules['metric_agg_key']}}}
Expand Down

0 comments on commit 742c2c8

Please sign in to comment.