mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
elasticsearch: always use fixed_interval (#50297)
This commit is contained in:
parent
0a815a7777
commit
a2eb4e85e5
@ -145,7 +145,7 @@ func TestClient_ExecuteMultisearch(t *testing.T) {
|
||||
|
||||
assert.Equal(t, "15000*@hostname", jBody.GetPath("aggs", "2", "aggs", "1", "avg", "script").MustString())
|
||||
|
||||
assert.Equal(t, "15s", jBody.GetPath("aggs", "2", "date_histogram", "interval").MustString())
|
||||
assert.Equal(t, "15s", jBody.GetPath("aggs", "2", "date_histogram", "fixed_interval").MustString())
|
||||
|
||||
assert.Equal(t, 200, res.Status)
|
||||
require.Len(t, res.Responses, 1)
|
||||
@ -197,7 +197,7 @@ func TestClient_ExecuteMultisearch(t *testing.T) {
|
||||
|
||||
assert.Equal(t, "15000*@hostname", jBody.GetPath("aggs", "2", "aggs", "1", "avg", "script").MustString())
|
||||
|
||||
assert.Equal(t, "15s", jBody.GetPath("aggs", "2", "date_histogram", "interval").MustString())
|
||||
assert.Equal(t, "15s", jBody.GetPath("aggs", "2", "date_histogram", "fixed_interval").MustString())
|
||||
|
||||
assert.Equal(t, 200, res.Status)
|
||||
require.Len(t, res.Responses, 1)
|
||||
@ -252,7 +252,7 @@ func TestClient_ExecuteMultisearch(t *testing.T) {
|
||||
|
||||
assert.Equal(t, "15000*@hostname", jBody.GetPath("aggs", "2", "aggs", "1", "avg", "script").MustString())
|
||||
|
||||
assert.Equal(t, "15s", jBody.GetPath("aggs", "2", "date_histogram", "interval").MustString())
|
||||
assert.Equal(t, "15s", jBody.GetPath("aggs", "2", "date_histogram", "fixed_interval").MustString())
|
||||
|
||||
assert.Equal(t, 200, res.Status)
|
||||
require.Len(t, res.Responses, 1)
|
||||
@ -308,7 +308,7 @@ func TestClient_ExecuteMultisearch(t *testing.T) {
|
||||
|
||||
assert.Equal(t, "15000*@hostname", jBody.GetPath("aggs", "2", "aggs", "1", "avg", "script").MustString())
|
||||
|
||||
assert.Equal(t, "15s", jBody.GetPath("aggs", "2", "date_histogram", "interval").MustString())
|
||||
assert.Equal(t, "15s", jBody.GetPath("aggs", "2", "date_histogram", "fixed_interval").MustString())
|
||||
|
||||
assert.Equal(t, 200, res.Status)
|
||||
require.Len(t, res.Responses, 1)
|
||||
@ -321,7 +321,7 @@ func createMultisearchForTest(t *testing.T, c Client) (*MultiSearchRequest, erro
|
||||
msb := c.MultiSearch()
|
||||
s := msb.Search(intervalv2.Interval{Value: 15 * time.Second, Text: "15s"})
|
||||
s.Agg().DateHistogram("2", "@timestamp", func(a *DateHistogramAgg, ab AggBuilder) {
|
||||
a.Interval = "$__interval"
|
||||
a.FixedInterval = "$__interval"
|
||||
|
||||
ab.Metric("1", "avg", "@hostname", func(a *MetricAggregation) {
|
||||
a.Settings["script"] = "$__interval_ms*@hostname"
|
||||
|
@ -238,7 +238,6 @@ type HistogramAgg struct {
|
||||
// DateHistogramAgg represents a date histogram aggregation
|
||||
type DateHistogramAgg struct {
|
||||
Field string `json:"field"`
|
||||
Interval string `json:"interval,omitempty"`
|
||||
FixedInterval string `json:"fixed_interval,omitempty"`
|
||||
MinDocCount int `json:"min_doc_count"`
|
||||
Missing *string `json:"missing,omitempty"`
|
||||
|
@ -342,11 +342,6 @@ func (b *aggBuilderImpl) DateHistogram(key, field string, fn func(a *DateHistogr
|
||||
fn(innerAgg, builder)
|
||||
}
|
||||
|
||||
if b.version.Major() >= 8 {
|
||||
innerAgg.FixedInterval = innerAgg.Interval
|
||||
innerAgg.Interval = ""
|
||||
}
|
||||
|
||||
b.aggDefs = append(b.aggDefs, aggDef)
|
||||
|
||||
return b
|
||||
|
@ -245,13 +245,13 @@ func (bucketAgg BucketAgg) generateSettingsForDSL() map[string]interface{} {
|
||||
|
||||
func addDateHistogramAgg(aggBuilder es.AggBuilder, bucketAgg *BucketAgg, timeFrom, timeTo int64) es.AggBuilder {
|
||||
aggBuilder.DateHistogram(bucketAgg.ID, bucketAgg.Field, func(a *es.DateHistogramAgg, b es.AggBuilder) {
|
||||
a.Interval = bucketAgg.Settings.Get("interval").MustString("auto")
|
||||
a.FixedInterval = bucketAgg.Settings.Get("interval").MustString("auto")
|
||||
a.MinDocCount = bucketAgg.Settings.Get("min_doc_count").MustInt(0)
|
||||
a.ExtendedBounds = &es.ExtendedBounds{Min: timeFrom, Max: timeTo}
|
||||
a.Format = bucketAgg.Settings.Get("format").MustString(es.DateFormatEpochMS)
|
||||
|
||||
if a.Interval == "auto" {
|
||||
a.Interval = "$__interval"
|
||||
if a.FixedInterval == "auto" {
|
||||
a.FixedInterval = "$__interval"
|
||||
}
|
||||
|
||||
if offset, err := bucketAgg.Settings.Get("offset").String(); err == nil {
|
||||
|
@ -399,7 +399,7 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
||||
require.Equal(t, firstLevel.Aggregation.Type, "date_histogram")
|
||||
hAgg := firstLevel.Aggregation.Aggregation.(*es.DateHistogramAgg)
|
||||
require.Equal(t, hAgg.Field, "@timestamp")
|
||||
require.Equal(t, hAgg.Interval, "$__interval")
|
||||
require.Equal(t, hAgg.FixedInterval, "$__interval")
|
||||
require.Equal(t, hAgg.MinDocCount, 2)
|
||||
|
||||
t.Run("Should not include time_zone when timeZone is utc", func(t *testing.T) {
|
||||
@ -1050,35 +1050,8 @@ func TestSettingsCasting(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("interval parameter", func(t *testing.T) {
|
||||
t.Run("Uses interval with ES < 8.0.0", func(t *testing.T) {
|
||||
c := newFakeClient("7.7.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [
|
||||
{
|
||||
"type": "date_histogram",
|
||||
"field": "@timestamp",
|
||||
"id": "2",
|
||||
"settings": {
|
||||
"interval": "1d"
|
||||
}
|
||||
}
|
||||
],
|
||||
"metrics": [
|
||||
{ "id": "1", "type": "average", "field": "@value" }
|
||||
]
|
||||
}`, from, to, 15*time.Second)
|
||||
assert.Nil(t, err)
|
||||
sr := c.multisearchRequests[0].Requests[0]
|
||||
|
||||
dateHistogramAgg := sr.Aggs[0].Aggregation.Aggregation.(*es.DateHistogramAgg)
|
||||
|
||||
assert.Zero(t, dateHistogramAgg.FixedInterval)
|
||||
assert.NotZero(t, dateHistogramAgg.Interval)
|
||||
})
|
||||
|
||||
t.Run("Uses fixed_interval with ES >= 8.0.0", func(t *testing.T) {
|
||||
c := newFakeClient("8.0.0")
|
||||
t.Run("Uses fixed_interval", func(t *testing.T) {
|
||||
c := newFakeClient("7.10.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [
|
||||
@ -1101,7 +1074,6 @@ func TestSettingsCasting(t *testing.T) {
|
||||
dateHistogramAgg := sr.Aggs[0].Aggregation.Aggregation.(*es.DateHistogramAgg)
|
||||
|
||||
assert.NotZero(t, dateHistogramAgg.FixedInterval)
|
||||
assert.Zero(t, dateHistogramAgg.Interval)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -112,13 +112,7 @@ export class ElasticQueryBuilder {
|
||||
|
||||
const interval = settings.interval === 'auto' ? '$__interval' : settings.interval;
|
||||
|
||||
if (gte(this.esVersion, '8.0.0')) {
|
||||
// The deprecation was actually introduced in 7.0.0, we might want to use that instead of the removal date,
|
||||
// but it woudl be a breaking change on our side.
|
||||
esAgg.fixed_interval = interval;
|
||||
} else {
|
||||
esAgg.interval = interval;
|
||||
}
|
||||
esAgg.fixed_interval = interval;
|
||||
|
||||
return esAgg;
|
||||
}
|
||||
|
@ -763,16 +763,12 @@ describe('ElasticQueryBuilder', () => {
|
||||
extended_bounds: { max: '$timeTo', min: '$timeFrom' },
|
||||
field: '@timestamp',
|
||||
format: 'epoch_millis',
|
||||
interval: '$__interval',
|
||||
fixed_interval: '$__interval',
|
||||
min_doc_count: 0,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
if (gte(builder.esVersion, '8.0.0')) {
|
||||
expectedAggs['1'].date_histogram.fixed_interval = expectedAggs['1'].date_histogram.interval;
|
||||
delete expectedAggs['1'].date_histogram.interval;
|
||||
}
|
||||
expect(query.aggs).toMatchObject(expectedAggs);
|
||||
});
|
||||
|
||||
@ -959,7 +955,7 @@ describe('ElasticQueryBuilder', () => {
|
||||
});
|
||||
|
||||
describe('interval parameter', () => {
|
||||
it('should use interval if Elasticsearch version <8.0.0', () => {
|
||||
it('should use fixed_interval', () => {
|
||||
const query = builder77.build({
|
||||
refId: 'A',
|
||||
metrics: [{ type: 'count', id: '1' }],
|
||||
@ -974,8 +970,7 @@ describe('ElasticQueryBuilder', () => {
|
||||
],
|
||||
});
|
||||
|
||||
expect(query.aggs['2'].date_histogram.interval).toBe('1d');
|
||||
expect(query.aggs['2'].date_histogram.fixed_interval).toBeUndefined();
|
||||
expect(query.aggs['2'].date_histogram.fixed_interval).toBe('1d');
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user