fix handle of elasticsearch 6.0+ version

This commit is contained in:
Marcus Efraimsson 2018-11-23 15:24:16 +01:00
parent 9aa4d71550
commit a022284cb0
No known key found for this signature in database
GPG Key ID: EBFE0FB04612DD4A
2 changed files with 14 additions and 7 deletions

View File

@ -65,7 +65,7 @@ var NewClient = func(ctx context.Context, ds *models.DataSource, timeRange *tsdb
clientLog.Debug("Creating new client", "version", version, "timeField", timeField, "indices", strings.Join(indices, ", ")) clientLog.Debug("Creating new client", "version", version, "timeField", timeField, "indices", strings.Join(indices, ", "))
switch version { switch version {
case 2, 5, 56: case 2, 5, 56, 60:
return &baseClientImpl{ return &baseClientImpl{
ctx: ctx, ctx: ctx,
ds: ds, ds: ds,

View File

@ -90,6 +90,19 @@ func TestClient(t *testing.T) {
So(err, ShouldBeNil) So(err, ShouldBeNil)
So(c.GetVersion(), ShouldEqual, 56) So(c.GetVersion(), ShouldEqual, 56)
}) })
Convey("When version 60 should return v6.0 client", func() {
ds := &models.DataSource{
JsonData: simplejson.NewFromAny(map[string]interface{}{
"esVersion": 60,
"timeField": "@timestamp",
}),
}
c, err := NewClient(context.Background(), ds, nil)
So(err, ShouldBeNil)
So(c.GetVersion(), ShouldEqual, 60)
})
}) })
Convey("Given a fake http client", func() { Convey("Given a fake http client", func() {
@ -153,8 +166,6 @@ func TestClient(t *testing.T) {
jBody, err := simplejson.NewJson(bodyBytes) jBody, err := simplejson.NewJson(bodyBytes)
So(err, ShouldBeNil) So(err, ShouldBeNil)
fmt.Println("body", string(headerBytes))
So(jHeader.Get("index").MustString(), ShouldEqual, "metrics-2018.05.15") So(jHeader.Get("index").MustString(), ShouldEqual, "metrics-2018.05.15")
So(jHeader.Get("ignore_unavailable").MustBool(false), ShouldEqual, true) So(jHeader.Get("ignore_unavailable").MustBool(false), ShouldEqual, true)
So(jHeader.Get("search_type").MustString(), ShouldEqual, "count") So(jHeader.Get("search_type").MustString(), ShouldEqual, "count")
@ -209,8 +220,6 @@ func TestClient(t *testing.T) {
jBody, err := simplejson.NewJson(bodyBytes) jBody, err := simplejson.NewJson(bodyBytes)
So(err, ShouldBeNil) So(err, ShouldBeNil)
fmt.Println("body", string(headerBytes))
So(jHeader.Get("index").MustString(), ShouldEqual, "metrics-2018.05.15") So(jHeader.Get("index").MustString(), ShouldEqual, "metrics-2018.05.15")
So(jHeader.Get("ignore_unavailable").MustBool(false), ShouldEqual, true) So(jHeader.Get("ignore_unavailable").MustBool(false), ShouldEqual, true)
So(jHeader.Get("search_type").MustString(), ShouldEqual, "query_then_fetch") So(jHeader.Get("search_type").MustString(), ShouldEqual, "query_then_fetch")
@ -265,8 +274,6 @@ func TestClient(t *testing.T) {
jBody, err := simplejson.NewJson(bodyBytes) jBody, err := simplejson.NewJson(bodyBytes)
So(err, ShouldBeNil) So(err, ShouldBeNil)
fmt.Println("body", string(headerBytes))
So(jHeader.Get("index").MustString(), ShouldEqual, "metrics-2018.05.15") So(jHeader.Get("index").MustString(), ShouldEqual, "metrics-2018.05.15")
So(jHeader.Get("ignore_unavailable").MustBool(false), ShouldEqual, true) So(jHeader.Get("ignore_unavailable").MustBool(false), ShouldEqual, true)
So(jHeader.Get("search_type").MustString(), ShouldEqual, "query_then_fetch") So(jHeader.Get("search_type").MustString(), ShouldEqual, "query_then_fetch")