Elasticsearch: use semver strings to identify ES version (#33646)
* Elasticsearch: use proper semver strings to identify ES version * Update BE & tests * refactor BE tests * refactor isValidOption check * update test * Update pkg/tsdb/elasticsearch/client/client.go Co-authored-by: Piotr Jamróz <pm.jamroz@gmail.com> * Update pkg/tsdb/elasticsearch/client/search_request_test.go Co-authored-by: Piotr Jamróz <pm.jamroz@gmail.com> * Remove leftover FIXME comment * Add new test cases for new version format * Docs: add documentation about version dropdown * Update docs/sources/datasources/elasticsearch.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * Update docs/sources/datasources/elasticsearch.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * Update docs/sources/datasources/elasticsearch.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * Update provisioning documentation Co-authored-by: Piotr Jamróz <pm.jamroz@gmail.com> Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com>
This commit is contained in:
co-authored by
Piotr Jamróz
achatterjee-grafana
parent
1a504ce673
commit
e98a8bd11b
@@ -13,6 +13,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Masterminds/semver"
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/tsdb/interval"
|
||||
@@ -34,7 +35,7 @@ var newDatasourceHttpClient = func(ds *models.DataSource) (*http.Client, error)
|
||||
|
||||
// Client represents a client which can interact with elasticsearch api
|
||||
type Client interface {
|
||||
GetVersion() int
|
||||
GetVersion() *semver.Version
|
||||
GetTimeField() string
|
||||
GetMinInterval(queryInterval string) (time.Duration, error)
|
||||
ExecuteMultisearch(r *MultiSearchRequest) (*MultiSearchResponse, error)
|
||||
@@ -42,9 +43,38 @@ type Client interface {
|
||||
EnableDebug()
|
||||
}
|
||||
|
||||
func coerceVersion(v *simplejson.Json) (*semver.Version, error) {
|
||||
versionString, err := v.String()
|
||||
|
||||
if err != nil {
|
||||
versionNumber, err := v.Int()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch versionNumber {
|
||||
case 2:
|
||||
return semver.NewVersion("2.0.0")
|
||||
case 5:
|
||||
return semver.NewVersion("5.0.0")
|
||||
case 56:
|
||||
return semver.NewVersion("5.6.0")
|
||||
case 60:
|
||||
return semver.NewVersion("6.0.0")
|
||||
case 70:
|
||||
return semver.NewVersion("7.0.0")
|
||||
default:
|
||||
return nil, fmt.Errorf("elasticsearch version=%d is not supported", versionNumber)
|
||||
}
|
||||
}
|
||||
|
||||
return semver.NewVersion(versionString)
|
||||
}
|
||||
|
||||
// NewClient creates a new elasticsearch client
|
||||
var NewClient = func(ctx context.Context, ds *models.DataSource, timeRange plugins.DataTimeRange) (Client, error) {
|
||||
version, err := ds.JsonData.Get("esVersion").Int()
|
||||
version, err := coerceVersion(ds.JsonData.Get("esVersion"))
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("elasticsearch version is required, err=%v", err)
|
||||
}
|
||||
@@ -65,34 +95,29 @@ var NewClient = func(ctx context.Context, ds *models.DataSource, timeRange plugi
|
||||
return nil, err
|
||||
}
|
||||
|
||||
clientLog.Debug("Creating new client", "version", version, "timeField", timeField, "indices", strings.Join(indices, ", "))
|
||||
clientLog.Info("Creating new client", "version", version.String(), "timeField", timeField, "indices", strings.Join(indices, ", "))
|
||||
|
||||
switch version {
|
||||
case 2, 5, 56, 60, 70:
|
||||
return &baseClientImpl{
|
||||
ctx: ctx,
|
||||
ds: ds,
|
||||
version: version,
|
||||
timeField: timeField,
|
||||
indices: indices,
|
||||
timeRange: timeRange,
|
||||
}, nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("elasticsearch version=%d is not supported", version)
|
||||
return &baseClientImpl{
|
||||
ctx: ctx,
|
||||
ds: ds,
|
||||
version: version,
|
||||
timeField: timeField,
|
||||
indices: indices,
|
||||
timeRange: timeRange,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type baseClientImpl struct {
|
||||
ctx context.Context
|
||||
ds *models.DataSource
|
||||
version int
|
||||
version *semver.Version
|
||||
timeField string
|
||||
indices []string
|
||||
timeRange plugins.DataTimeRange
|
||||
debugEnabled bool
|
||||
}
|
||||
|
||||
func (c *baseClientImpl) GetVersion() int {
|
||||
func (c *baseClientImpl) GetVersion() *semver.Version {
|
||||
return c.version
|
||||
}
|
||||
|
||||
@@ -297,13 +322,15 @@ func (c *baseClientImpl) createMultiSearchRequests(searchRequests []*SearchReque
|
||||
interval: searchReq.Interval,
|
||||
}
|
||||
|
||||
if c.version == 2 {
|
||||
if c.version.Major() < 5 {
|
||||
mr.header["search_type"] = "count"
|
||||
}
|
||||
} else {
|
||||
allowedVersionRange, _ := semver.NewConstraint(">=5.6.0, <7.0.0")
|
||||
|
||||
if c.version >= 56 && c.version < 70 {
|
||||
maxConcurrentShardRequests := c.getSettings().Get("maxConcurrentShardRequests").MustInt(256)
|
||||
mr.header["max_concurrent_shard_requests"] = maxConcurrentShardRequests
|
||||
if allowedVersionRange.Check(c.version) {
|
||||
maxConcurrentShardRequests := c.getSettings().Get("maxConcurrentShardRequests").MustInt(256)
|
||||
mr.header["max_concurrent_shard_requests"] = maxConcurrentShardRequests
|
||||
}
|
||||
}
|
||||
|
||||
multiRequests = append(multiRequests, &mr)
|
||||
@@ -313,7 +340,7 @@ func (c *baseClientImpl) createMultiSearchRequests(searchRequests []*SearchReque
|
||||
}
|
||||
|
||||
func (c *baseClientImpl) getMultiSearchQueryParameters() string {
|
||||
if c.version >= 70 {
|
||||
if c.version.Major() >= 7 {
|
||||
maxConcurrentShardRequests := c.getSettings().Get("maxConcurrentShardRequests").MustInt(5)
|
||||
return fmt.Sprintf("max_concurrent_shard_requests=%d", maxConcurrentShardRequests)
|
||||
}
|
||||
|
||||
@@ -39,10 +39,104 @@ func TestNewClient(t *testing.T) {
|
||||
require.Error(t, err)
|
||||
})
|
||||
|
||||
t.Run("When unsupported version set should return error", func(t *testing.T) {
|
||||
t.Run("When using legacy version numbers", func(t *testing.T) {
|
||||
t.Run("When unsupported version set should return error", func(t *testing.T) {
|
||||
ds := &models.DataSource{
|
||||
JsonData: simplejson.NewFromAny(map[string]interface{}{
|
||||
"esVersion": 6,
|
||||
"timeField": "@timestamp",
|
||||
}),
|
||||
}
|
||||
|
||||
_, err := NewClient(context.Background(), ds, plugins.DataTimeRange{})
|
||||
require.Error(t, err)
|
||||
})
|
||||
|
||||
t.Run("When version 2 should return v2 client", func(t *testing.T) {
|
||||
ds := &models.DataSource{
|
||||
JsonData: simplejson.NewFromAny(map[string]interface{}{
|
||||
"esVersion": 2,
|
||||
"timeField": "@timestamp",
|
||||
}),
|
||||
}
|
||||
|
||||
c, err := NewClient(context.Background(), ds, plugins.DataTimeRange{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "2.0.0", c.GetVersion().String())
|
||||
})
|
||||
|
||||
t.Run("When version 5 should return v5 client", func(t *testing.T) {
|
||||
ds := &models.DataSource{
|
||||
JsonData: simplejson.NewFromAny(map[string]interface{}{
|
||||
"esVersion": 5,
|
||||
"timeField": "@timestamp",
|
||||
}),
|
||||
}
|
||||
|
||||
c, err := NewClient(context.Background(), ds, plugins.DataTimeRange{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "5.0.0", c.GetVersion().String())
|
||||
})
|
||||
|
||||
t.Run("When version 56 should return v5.6 client", func(t *testing.T) {
|
||||
ds := &models.DataSource{
|
||||
JsonData: simplejson.NewFromAny(map[string]interface{}{
|
||||
"esVersion": 56,
|
||||
"timeField": "@timestamp",
|
||||
}),
|
||||
}
|
||||
|
||||
c, err := NewClient(context.Background(), ds, plugins.DataTimeRange{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "5.6.0", c.GetVersion().String())
|
||||
})
|
||||
|
||||
t.Run("When version 60 should return v6.0 client", func(t *testing.T) {
|
||||
ds := &models.DataSource{
|
||||
JsonData: simplejson.NewFromAny(map[string]interface{}{
|
||||
"esVersion": 60,
|
||||
"timeField": "@timestamp",
|
||||
}),
|
||||
}
|
||||
|
||||
c, err := NewClient(context.Background(), ds, plugins.DataTimeRange{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "6.0.0", c.GetVersion().String())
|
||||
})
|
||||
|
||||
t.Run("When version 70 should return v7.0 client", func(t *testing.T) {
|
||||
ds := &models.DataSource{
|
||||
JsonData: simplejson.NewFromAny(map[string]interface{}{
|
||||
"esVersion": 70,
|
||||
"timeField": "@timestamp",
|
||||
}),
|
||||
}
|
||||
|
||||
c, err := NewClient(context.Background(), ds, plugins.DataTimeRange{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "7.0.0", c.GetVersion().String())
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("When version is a valid semver string should create a client", func(t *testing.T) {
|
||||
version := "7.2.4"
|
||||
ds := &models.DataSource{
|
||||
JsonData: simplejson.NewFromAny(map[string]interface{}{
|
||||
"esVersion": 6,
|
||||
"esVersion": version,
|
||||
"timeField": "@timestamp",
|
||||
}),
|
||||
}
|
||||
|
||||
c, err := NewClient(context.Background(), ds, plugins.DataTimeRange{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, version, c.GetVersion().String())
|
||||
})
|
||||
|
||||
t.Run("When version is NOT a valid semver string should return error", func(t *testing.T) {
|
||||
version := "7.NOT_VALID.4"
|
||||
ds := &models.DataSource{
|
||||
JsonData: simplejson.NewFromAny(map[string]interface{}{
|
||||
"esVersion": version,
|
||||
"timeField": "@timestamp",
|
||||
}),
|
||||
}
|
||||
@@ -50,71 +144,6 @@ func TestNewClient(t *testing.T) {
|
||||
_, err := NewClient(context.Background(), ds, plugins.DataTimeRange{})
|
||||
require.Error(t, err)
|
||||
})
|
||||
|
||||
t.Run("When version 2 should return v2 client", func(t *testing.T) {
|
||||
ds := &models.DataSource{
|
||||
JsonData: simplejson.NewFromAny(map[string]interface{}{
|
||||
"esVersion": 2,
|
||||
"timeField": "@timestamp",
|
||||
}),
|
||||
}
|
||||
|
||||
c, err := NewClient(context.Background(), ds, plugins.DataTimeRange{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 2, c.GetVersion())
|
||||
})
|
||||
|
||||
t.Run("When version 5 should return v5 client", func(t *testing.T) {
|
||||
ds := &models.DataSource{
|
||||
JsonData: simplejson.NewFromAny(map[string]interface{}{
|
||||
"esVersion": 5,
|
||||
"timeField": "@timestamp",
|
||||
}),
|
||||
}
|
||||
|
||||
c, err := NewClient(context.Background(), ds, plugins.DataTimeRange{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 5, c.GetVersion())
|
||||
})
|
||||
|
||||
t.Run("When version 56 should return v5.6 client", func(t *testing.T) {
|
||||
ds := &models.DataSource{
|
||||
JsonData: simplejson.NewFromAny(map[string]interface{}{
|
||||
"esVersion": 56,
|
||||
"timeField": "@timestamp",
|
||||
}),
|
||||
}
|
||||
|
||||
c, err := NewClient(context.Background(), ds, plugins.DataTimeRange{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 56, c.GetVersion())
|
||||
})
|
||||
|
||||
t.Run("When version 60 should return v6.0 client", func(t *testing.T) {
|
||||
ds := &models.DataSource{
|
||||
JsonData: simplejson.NewFromAny(map[string]interface{}{
|
||||
"esVersion": 60,
|
||||
"timeField": "@timestamp",
|
||||
}),
|
||||
}
|
||||
|
||||
c, err := NewClient(context.Background(), ds, plugins.DataTimeRange{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 60, c.GetVersion())
|
||||
})
|
||||
|
||||
t.Run("When version 70 should return v7.0 client", func(t *testing.T) {
|
||||
ds := &models.DataSource{
|
||||
JsonData: simplejson.NewFromAny(map[string]interface{}{
|
||||
"esVersion": 70,
|
||||
"timeField": "@timestamp",
|
||||
}),
|
||||
}
|
||||
|
||||
c, err := NewClient(context.Background(), ds, plugins.DataTimeRange{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 70, c.GetVersion())
|
||||
})
|
||||
}
|
||||
|
||||
func TestClient_ExecuteMultisearch(t *testing.T) {
|
||||
|
||||
@@ -3,12 +3,13 @@ package es
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/Masterminds/semver"
|
||||
"github.com/grafana/grafana/pkg/tsdb/interval"
|
||||
)
|
||||
|
||||
// SearchRequestBuilder represents a builder which can build a search request
|
||||
type SearchRequestBuilder struct {
|
||||
version int
|
||||
version *semver.Version
|
||||
interval interval.Interval
|
||||
index string
|
||||
size int
|
||||
@@ -19,7 +20,7 @@ type SearchRequestBuilder struct {
|
||||
}
|
||||
|
||||
// NewSearchRequestBuilder create a new search request builder
|
||||
func NewSearchRequestBuilder(version int, interval interval.Interval) *SearchRequestBuilder {
|
||||
func NewSearchRequestBuilder(version *semver.Version, interval interval.Interval) *SearchRequestBuilder {
|
||||
builder := &SearchRequestBuilder{
|
||||
version: version,
|
||||
interval: interval,
|
||||
@@ -87,18 +88,15 @@ func (b *SearchRequestBuilder) SortDesc(field, unmappedType string) *SearchReque
|
||||
// AddDocValueField adds a doc value field to the search request
|
||||
func (b *SearchRequestBuilder) AddDocValueField(field string) *SearchRequestBuilder {
|
||||
// fields field not supported on version >= 5
|
||||
if b.version < 5 {
|
||||
if b.version.Major() < 5 {
|
||||
b.customProps["fields"] = []string{"*", "_source"}
|
||||
}
|
||||
|
||||
b.customProps["script_fields"] = make(map[string]interface{})
|
||||
|
||||
if b.version < 5 {
|
||||
b.customProps["fielddata_fields"] = []string{field}
|
||||
} else {
|
||||
b.customProps["docvalue_fields"] = []string{field}
|
||||
}
|
||||
|
||||
b.customProps["script_fields"] = make(map[string]interface{})
|
||||
|
||||
return b
|
||||
}
|
||||
|
||||
@@ -119,12 +117,12 @@ func (b *SearchRequestBuilder) Agg() AggBuilder {
|
||||
|
||||
// MultiSearchRequestBuilder represents a builder which can build a multi search request
|
||||
type MultiSearchRequestBuilder struct {
|
||||
version int
|
||||
version *semver.Version
|
||||
requestBuilders []*SearchRequestBuilder
|
||||
}
|
||||
|
||||
// NewMultiSearchRequestBuilder creates a new multi search request builder
|
||||
func NewMultiSearchRequestBuilder(version int) *MultiSearchRequestBuilder {
|
||||
func NewMultiSearchRequestBuilder(version *semver.Version) *MultiSearchRequestBuilder {
|
||||
return &MultiSearchRequestBuilder{
|
||||
version: version,
|
||||
}
|
||||
@@ -275,10 +273,10 @@ type AggBuilder interface {
|
||||
type aggBuilderImpl struct {
|
||||
AggBuilder
|
||||
aggDefs []*aggDef
|
||||
version int
|
||||
version *semver.Version
|
||||
}
|
||||
|
||||
func newAggBuilder(version int) *aggBuilderImpl {
|
||||
func newAggBuilder(version *semver.Version) *aggBuilderImpl {
|
||||
return &aggBuilderImpl{
|
||||
aggDefs: make([]*aggDef, 0),
|
||||
version: version,
|
||||
@@ -367,7 +365,7 @@ func (b *aggBuilderImpl) Terms(key, field string, fn func(a *TermsAggregation, b
|
||||
fn(innerAgg, builder)
|
||||
}
|
||||
|
||||
if b.version >= 60 && len(innerAgg.Order) > 0 {
|
||||
if b.version.Major() >= 6 && len(innerAgg.Order) > 0 {
|
||||
if orderBy, exists := innerAgg.Order[termsOrderTerm]; exists {
|
||||
innerAgg.Order["_key"] = orderBy
|
||||
delete(innerAgg.Order, termsOrderTerm)
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/Masterminds/semver"
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/tsdb/interval"
|
||||
|
||||
@@ -15,7 +16,8 @@ func TestSearchRequest(t *testing.T) {
|
||||
Convey("Test elasticsearch search request", t, func() {
|
||||
timeField := "@timestamp"
|
||||
Convey("Given new search request builder for es version 5", func() {
|
||||
b := NewSearchRequestBuilder(5, interval.Interval{Value: 15 * time.Second, Text: "15s"})
|
||||
version5, _ := semver.NewVersion("5.0.0")
|
||||
b := NewSearchRequestBuilder(version5, interval.Interval{Value: 15 * time.Second, Text: "15s"})
|
||||
|
||||
Convey("When building search request", func() {
|
||||
sr, err := b.Build()
|
||||
@@ -390,7 +392,8 @@ func TestSearchRequest(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("Given new search request builder for es version 2", func() {
|
||||
b := NewSearchRequestBuilder(2, interval.Interval{Value: 15 * time.Second, Text: "15s"})
|
||||
version2, _ := semver.NewVersion("2.0.0")
|
||||
b := NewSearchRequestBuilder(version2, interval.Interval{Value: 15 * time.Second, Text: "15s"})
|
||||
|
||||
Convey("When adding doc value field", func() {
|
||||
b.AddDocValueField(timeField)
|
||||
@@ -446,7 +449,8 @@ func TestSearchRequest(t *testing.T) {
|
||||
func TestMultiSearchRequest(t *testing.T) {
|
||||
Convey("Test elasticsearch multi search request", t, func() {
|
||||
Convey("Given new multi search request builder", func() {
|
||||
b := NewMultiSearchRequestBuilder(0)
|
||||
version2, _ := semver.NewVersion("2.0.0")
|
||||
b := NewMultiSearchRequestBuilder(version2)
|
||||
|
||||
Convey("When adding one search request", func() {
|
||||
b.Search(interval.Interval{Value: 15 * time.Second, Text: "15s"})
|
||||
|
||||
@@ -32,6 +32,7 @@ func (e *Executor) DataQuery(ctx context.Context, dsInfo *models.DataSource,
|
||||
}
|
||||
|
||||
client, err := es.NewClient(ctx, dsInfo, *tsdbQuery.TimeRange)
|
||||
|
||||
if err != nil {
|
||||
return plugins.DataResponse{}, err
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/Masterminds/semver"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
es "github.com/grafana/grafana/pkg/tsdb/elasticsearch/client"
|
||||
"github.com/grafana/grafana/pkg/tsdb/interval"
|
||||
@@ -22,7 +23,7 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
||||
|
||||
Convey("Test execute time series query", t, func() {
|
||||
Convey("With defaults on es 2", func() {
|
||||
c := newFakeClient(2)
|
||||
c := newFakeClient("2.0.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [{ "type": "date_histogram", "field": "@timestamp", "id": "2" }],
|
||||
@@ -43,7 +44,7 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("With defaults on es 5", func() {
|
||||
c := newFakeClient(5)
|
||||
c := newFakeClient("5.0.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [{ "type": "date_histogram", "field": "@timestamp", "id": "2" }],
|
||||
@@ -58,7 +59,7 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("With multiple bucket aggs", func() {
|
||||
c := newFakeClient(5)
|
||||
c := newFakeClient("5.0.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [
|
||||
@@ -80,7 +81,7 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("With select field", func() {
|
||||
c := newFakeClient(5)
|
||||
c := newFakeClient("5.0.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [
|
||||
@@ -100,7 +101,7 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("With term agg and order by metric agg", func() {
|
||||
c := newFakeClient(5)
|
||||
c := newFakeClient("5.0.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [
|
||||
@@ -130,7 +131,7 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("With term agg and order by count metric agg", func() {
|
||||
c := newFakeClient(5)
|
||||
c := newFakeClient("5.0.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [
|
||||
@@ -154,7 +155,7 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("With term agg and order by percentiles agg", func() {
|
||||
c := newFakeClient(5)
|
||||
c := newFakeClient("5.0.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [
|
||||
@@ -179,7 +180,7 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("With term agg and order by extended stats agg", func() {
|
||||
c := newFakeClient(5)
|
||||
c := newFakeClient("5.0.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [
|
||||
@@ -204,7 +205,7 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("With term agg and order by term", func() {
|
||||
c := newFakeClient(5)
|
||||
c := newFakeClient("5.0.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [
|
||||
@@ -231,7 +232,7 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("With term agg and order by term with es6.x", func() {
|
||||
c := newFakeClient(60)
|
||||
c := newFakeClient("6.0.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [
|
||||
@@ -258,7 +259,7 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("With metric percentiles", func() {
|
||||
c := newFakeClient(5)
|
||||
c := newFakeClient("5.0.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [
|
||||
@@ -291,7 +292,7 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("With filters aggs on es 2", func() {
|
||||
c := newFakeClient(2)
|
||||
c := newFakeClient("2.0.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [
|
||||
@@ -322,7 +323,7 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("With filters aggs on es 5", func() {
|
||||
c := newFakeClient(5)
|
||||
c := newFakeClient("5.0.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [
|
||||
@@ -353,7 +354,7 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("With raw document metric", func() {
|
||||
c := newFakeClient(5)
|
||||
c := newFakeClient("5.0.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [],
|
||||
@@ -366,7 +367,7 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("With raw document metric size set", func() {
|
||||
c := newFakeClient(5)
|
||||
c := newFakeClient("5.0.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [],
|
||||
@@ -379,7 +380,7 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("With date histogram agg", func() {
|
||||
c := newFakeClient(5)
|
||||
c := newFakeClient("5.0.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [
|
||||
@@ -405,7 +406,7 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("With histogram agg", func() {
|
||||
c := newFakeClient(5)
|
||||
c := newFakeClient("5.0.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [
|
||||
@@ -432,7 +433,7 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("With geo hash grid agg", func() {
|
||||
c := newFakeClient(5)
|
||||
c := newFakeClient("5.0.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [
|
||||
@@ -457,7 +458,7 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("With moving average", func() {
|
||||
c := newFakeClient(5)
|
||||
c := newFakeClient("5.0.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [
|
||||
@@ -495,7 +496,7 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("With moving average doc count", func() {
|
||||
c := newFakeClient(5)
|
||||
c := newFakeClient("5.0.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [
|
||||
@@ -527,7 +528,7 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("With broken moving average", func() {
|
||||
c := newFakeClient(5)
|
||||
c := newFakeClient("5.0.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [
|
||||
@@ -563,7 +564,7 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("With cumulative sum", func() {
|
||||
c := newFakeClient(5)
|
||||
c := newFakeClient("5.0.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [
|
||||
@@ -601,7 +602,7 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("With cumulative sum doc count", func() {
|
||||
c := newFakeClient(5)
|
||||
c := newFakeClient("5.0.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [
|
||||
@@ -633,7 +634,7 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("With broken cumulative sum", func() {
|
||||
c := newFakeClient(5)
|
||||
c := newFakeClient("5.0.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [
|
||||
@@ -669,7 +670,7 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("With derivative", func() {
|
||||
c := newFakeClient(5)
|
||||
c := newFakeClient("5.0.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [
|
||||
@@ -698,7 +699,7 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("With derivative doc count", func() {
|
||||
c := newFakeClient(5)
|
||||
c := newFakeClient("5.0.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [
|
||||
@@ -727,7 +728,7 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("With serial_diff", func() {
|
||||
c := newFakeClient(5)
|
||||
c := newFakeClient("5.0.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [
|
||||
@@ -756,7 +757,7 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("With serial_diff doc count", func() {
|
||||
c := newFakeClient(5)
|
||||
c := newFakeClient("5.0.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [
|
||||
@@ -785,7 +786,7 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("With bucket_script", func() {
|
||||
c := newFakeClient(5)
|
||||
c := newFakeClient("5.0.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [
|
||||
@@ -822,7 +823,7 @@ func TestExecuteTimeSeriesQuery(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("With bucket_script doc count", func() {
|
||||
c := newFakeClient(5)
|
||||
c := newFakeClient("5.0.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [
|
||||
@@ -862,7 +863,7 @@ func TestSettingsCasting(t *testing.T) {
|
||||
to := time.Date(2018, 5, 15, 17, 55, 0, 0, time.UTC)
|
||||
|
||||
t.Run("Correctly transforms moving_average settings", func(t *testing.T) {
|
||||
c := newFakeClient(5)
|
||||
c := newFakeClient("5.0.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [
|
||||
@@ -906,7 +907,7 @@ func TestSettingsCasting(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Correctly transforms serial_diff settings", func(t *testing.T) {
|
||||
c := newFakeClient(5)
|
||||
c := newFakeClient("5.0.0")
|
||||
_, err := executeTsdbQuery(c, `{
|
||||
"timeField": "@timestamp",
|
||||
"bucketAggs": [
|
||||
@@ -935,7 +936,7 @@ func TestSettingsCasting(t *testing.T) {
|
||||
}
|
||||
|
||||
type fakeClient struct {
|
||||
version int
|
||||
version *semver.Version
|
||||
timeField string
|
||||
multiSearchResponse *es.MultiSearchResponse
|
||||
multiSearchError error
|
||||
@@ -943,7 +944,8 @@ type fakeClient struct {
|
||||
multisearchRequests []*es.MultiSearchRequest
|
||||
}
|
||||
|
||||
func newFakeClient(version int) *fakeClient {
|
||||
func newFakeClient(versionString string) *fakeClient {
|
||||
version, _ := semver.NewVersion(versionString)
|
||||
return &fakeClient{
|
||||
version: version,
|
||||
timeField: "@timestamp",
|
||||
@@ -954,7 +956,7 @@ func newFakeClient(version int) *fakeClient {
|
||||
|
||||
func (c *fakeClient) EnableDebug() {}
|
||||
|
||||
func (c *fakeClient) GetVersion() int {
|
||||
func (c *fakeClient) GetVersion() *semver.Version {
|
||||
return c.version
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user