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>
This commit is contained in:
Chris Cowan
2021-01-14 10:48:59 +01:00
committed by GitHub
co-authored by Marcus Efraimsson
parent dac7add457
commit 3d7748d9f8
2 changed files with 3 additions and 1 deletions
+1 -1
View File
@@ -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")