elasticsearch: always use fixed_interval (#50297)

This commit is contained in:
Gábor Farkas
2022-06-13 10:28:29 +02:00
committed by GitHub
parent 0a815a7777
commit a2eb4e85e5
7 changed files with 15 additions and 60 deletions

View File

@@ -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"

View File

@@ -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"`

View File

@@ -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

View File

@@ -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 {

View File

@@ -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)
})
})
})