diff --git a/docs/sources/datasources/elasticsearch.md b/docs/sources/datasources/elasticsearch.md index 7cef8d4a46e..356d3dfc850 100644 --- a/docs/sources/datasources/elasticsearch.md +++ b/docs/sources/datasources/elasticsearch.md @@ -80,6 +80,13 @@ number followed by a valid time identifier, e.g. `1m` (1 minute) or `30s` (30 se | `s` | second | | `ms` | millisecond | +### X-Pack enabled + +Enables `X-Pack` specific features and options, providing the query editor with additional aggregations such as `Rate` and `Top Metrics`. + +#### Include frozen indices + +When `X-Pack enabled` is active and the configured Elasticsearch version is higher than `6.6.0`, you can configure Grafana to not ignore [frozen indices](https://www.elastic.co/guide/en/elasticsearch/reference/7.13/frozen-indices.html) when performing search requests. ### Logs There are two parameters, `Message field name` and `Level field name`, that can optionally be configured from the data source settings page that determine diff --git a/pkg/tsdb/elasticsearch/client/client.go b/pkg/tsdb/elasticsearch/client/client.go index 7798e0034ca..f1b9ad9ea7f 100644 --- a/pkg/tsdb/elasticsearch/client/client.go +++ b/pkg/tsdb/elasticsearch/client/client.go @@ -334,12 +334,23 @@ func (c *baseClientImpl) createMultiSearchRequests(searchRequests []*SearchReque } func (c *baseClientImpl) getMultiSearchQueryParameters() string { + var qs []string + if c.version.Major() >= 7 { maxConcurrentShardRequests := c.getSettings().Get("maxConcurrentShardRequests").MustInt(5) - return fmt.Sprintf("max_concurrent_shard_requests=%d", maxConcurrentShardRequests) + qs = append(qs, fmt.Sprintf("max_concurrent_shard_requests=%d", maxConcurrentShardRequests)) } - return "" + // Querying frozen indices was added in 6.6 with xpack + includeFrozen := c.getSettings().Get("includeFrozen").MustBool(false) + xpack := c.getSettings().Get("xpack").MustBool(false) + allowedFrozenIndicesVersionRange, _ := semver.NewConstraint(">=6.6.0") + + if (allowedFrozenIndicesVersionRange.Check(c.version)) && includeFrozen && xpack { + qs = append(qs, "ignore_throttled=false") + } + + return strings.Join(qs, "&") } func (c *baseClientImpl) MultiSearch() *MultiSearchRequestBuilder { diff --git a/pkg/tsdb/elasticsearch/client/client_test.go b/pkg/tsdb/elasticsearch/client/client_test.go index 61537d214a9..64e8312e44d 100644 --- a/pkg/tsdb/elasticsearch/client/client_test.go +++ b/pkg/tsdb/elasticsearch/client/client_test.go @@ -253,10 +253,12 @@ func TestClient_ExecuteMultisearch(t *testing.T) { httpClientScenario(t, "Given a fake http client and a v5.6 client with response", &models.DataSource{ Database: "[metrics-]YYYY.MM.DD", JsonData: simplejson.NewFromAny(map[string]interface{}{ - "esVersion": 56, + "esVersion": "5.6.0", "maxConcurrentShardRequests": 100, "timeField": "@timestamp", "interval": "Daily", + "includeFrozen": true, + "xpack": true, }), }, func(sc *scenarioContext) { sc.responseBody = `{ @@ -276,6 +278,7 @@ func TestClient_ExecuteMultisearch(t *testing.T) { require.NotNil(t, sc.request) assert.Equal(t, http.MethodPost, sc.request.Method) assert.Equal(t, "/_msearch", sc.request.URL.Path) + assert.NotContains(t, sc.request.URL.RawQuery, "ignore_throttled=") require.NotNil(t, sc.requestBody) @@ -305,10 +308,12 @@ func TestClient_ExecuteMultisearch(t *testing.T) { httpClientScenario(t, "Given a fake http client and a v7.0 client with response", &models.DataSource{ Database: "[metrics-]YYYY.MM.DD", JsonData: simplejson.NewFromAny(map[string]interface{}{ - "esVersion": 70, + "esVersion": "7.0.0", "maxConcurrentShardRequests": 6, "timeField": "@timestamp", "interval": "Daily", + "includeFrozen": true, + "xpack": true, }), }, func(sc *scenarioContext) { sc.responseBody = `{ @@ -328,7 +333,7 @@ func TestClient_ExecuteMultisearch(t *testing.T) { require.NotNil(t, sc.request) assert.Equal(t, http.MethodPost, sc.request.Method) assert.Equal(t, "/_msearch", sc.request.URL.Path) - assert.Equal(t, "max_concurrent_shard_requests=6", sc.request.URL.RawQuery) + assert.Equal(t, "max_concurrent_shard_requests=6&ignore_throttled=false", sc.request.URL.RawQuery) require.NotNil(t, sc.requestBody) @@ -346,6 +351,7 @@ func TestClient_ExecuteMultisearch(t *testing.T) { assert.True(t, jHeader.Get("ignore_unavailable").MustBool(false)) assert.Equal(t, "query_then_fetch", jHeader.Get("search_type").MustString()) assert.Empty(t, jHeader.Get("max_concurrent_shard_requests")) + assert.False(t, jHeader.Get("ignore_throttled").MustBool()) assert.Equal(t, "15000*@hostname", jBody.GetPath("aggs", "2", "aggs", "1", "avg", "script").MustString()) diff --git a/pkg/tsdb/elasticsearch/response_parser.go b/pkg/tsdb/elasticsearch/response_parser.go index d932e71dc59..1333ef29a2c 100644 --- a/pkg/tsdb/elasticsearch/response_parser.go +++ b/pkg/tsdb/elasticsearch/response_parser.go @@ -67,7 +67,8 @@ func (rp *responseParser) getTimeSeries() (plugins.DataResponse, error) { } queryRes := plugins.DataQueryResult{ - Meta: debugInfo, + Meta: debugInfo, + Dataframes: plugins.NewDecodedDataFrames(data.Frames{}), } props := make(map[string]string) err := rp.processBuckets(res.Aggregations, target, &queryRes, props, 0) diff --git a/public/app/plugins/datasource/elasticsearch/configuration/ElasticDetails.tsx b/public/app/plugins/datasource/elasticsearch/configuration/ElasticDetails.tsx index ecaead176a6..9cf6c0233f8 100644 --- a/public/app/plugins/datasource/elasticsearch/configuration/ElasticDetails.tsx +++ b/public/app/plugins/datasource/elasticsearch/configuration/ElasticDetails.tsx @@ -145,17 +145,29 @@ export const ElasticDetails = ({ value, onChange }: Props) => {