Commit 3d7748d9 by Chris Cowan Committed by GitHub

Elasticsearch: Use minimum interval for alerts (#30049)

The current backend code doesn't honor the minimum interval set in the UI for alerts using 
the Elasticsearch data source. This means that the data the alerts are triggering against 
will never match the data in the visualization if auto is used in the date histogram as interval. 
This fixes the problem to make sure that date histogram auto interval is set according to 
min interval set in UI for the query or fallback to data source min interval setting.

Fixes #22082

Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com>
parent dac7add4
......@@ -313,7 +313,7 @@ func (p *timeSeriesQueryParser) parse(tsdbQuery *tsdb.TsdbQuery) ([]*Query, erro
return nil, err
}
alias := model.Get("alias").MustString("")
interval := strconv.FormatInt(q.IntervalMs, 10) + "ms"
interval := model.Get("interval").MustString("")
queries = append(queries, &Query{
TimeField: timeField,
......
......@@ -865,6 +865,7 @@ func TestTimeSeriesQueryParser(t *testing.T) {
"timeField": "@timestamp",
"query": "@metric:cpu",
"alias": "{{@hostname}} {{metric}}",
"interval": "10m",
"metrics": [
{
"field": "@value",
......@@ -921,6 +922,7 @@ func TestTimeSeriesQueryParser(t *testing.T) {
So(q.TimeField, ShouldEqual, "@timestamp")
So(q.RawQuery, ShouldEqual, "@metric:cpu")
So(q.Alias, ShouldEqual, "{{@hostname}} {{metric}}")
So(q.Interval, ShouldEqual, "10m")
So(q.Metrics, ShouldHaveLength, 2)
So(q.Metrics[0].Field, ShouldEqual, "@value")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment