|
12 | 12 | import org.apache.http.HttpHost; |
13 | 13 | import org.elasticsearch.Version; |
14 | 14 | import org.elasticsearch.client.Request; |
| 15 | +import org.elasticsearch.client.Response; |
15 | 16 | import org.elasticsearch.client.RestClient; |
16 | 17 | import org.elasticsearch.common.Strings; |
17 | 18 | import org.elasticsearch.common.settings.Settings; |
|
37 | 38 |
|
38 | 39 | import static org.elasticsearch.test.MapMatcher.assertMap; |
39 | 40 | import static org.elasticsearch.test.MapMatcher.matchesMap; |
| 41 | +import static org.elasticsearch.xpack.esql.ccq.Clusters.REMOTE_CLUSTER_NAME; |
40 | 42 | import static org.hamcrest.Matchers.any; |
41 | 43 | import static org.hamcrest.Matchers.equalTo; |
42 | 44 | import static org.hamcrest.Matchers.greaterThanOrEqualTo; |
| 45 | +import static org.hamcrest.Matchers.hasKey; |
43 | 46 |
|
44 | 47 | @ThreadLeakFilters(filters = TestClustersThreadFilter.class) |
45 | 48 | public class MultiClustersIT extends ESRestTestCase { |
@@ -395,6 +398,34 @@ public void testIndexPattern() throws Exception { |
395 | 398 | } |
396 | 399 | } |
397 | 400 |
|
| 401 | + @SuppressWarnings("unchecked") |
| 402 | + public void testStats() throws IOException { |
| 403 | + assumeTrue("Older versions do not have ESQL stats", Clusters.localClusterVersion().onOrAfter(Version.V_8_18_0)); |
| 404 | + run("FROM test-local-index,*:test-remote-index | STATS total = SUM(data) BY color | SORT color", includeCCSMetadata()); |
| 405 | + Request stats = new Request("GET", "_cluster/stats"); |
| 406 | + Response statsResponse = client().performRequest(stats); |
| 407 | + Map<String, Object> result = entityAsMap(statsResponse.getEntity()); |
| 408 | + assertThat(result, hasKey("ccs")); |
| 409 | + Map<String, Object> ccs = (Map<String, Object>) result.get("ccs"); |
| 410 | + assertThat(ccs, hasKey("_esql")); |
| 411 | + Map<String, Object> esql = (Map<String, Object>) ccs.get("_esql"); |
| 412 | + assertThat(esql, hasKey("total")); |
| 413 | + assertThat(esql, hasKey("success")); |
| 414 | + assertThat(esql, hasKey("took")); |
| 415 | + assertThat(esql, hasKey("remotes_per_search_max")); |
| 416 | + assertThat(esql, hasKey("remotes_per_search_avg")); |
| 417 | + assertThat(esql, hasKey("failure_reasons")); |
| 418 | + assertThat(esql, hasKey("features")); |
| 419 | + assertThat(esql, hasKey("clusters")); |
| 420 | + Map<String, Object> clusters = (Map<String, Object>) esql.get("clusters"); |
| 421 | + assertThat(clusters, hasKey(REMOTE_CLUSTER_NAME)); |
| 422 | + assertThat(clusters, hasKey("(local)")); |
| 423 | + Map<String, Object> clusterData = (Map<String, Object>) clusters.get(REMOTE_CLUSTER_NAME); |
| 424 | + assertThat(clusterData, hasKey("total")); |
| 425 | + assertThat(clusterData, hasKey("skipped")); |
| 426 | + assertThat(clusterData, hasKey("took")); |
| 427 | + } |
| 428 | + |
398 | 429 | private RestClient remoteClusterClient() throws IOException { |
399 | 430 | var clusterHosts = parseClusterHosts(remoteCluster.getHttpAddresses()); |
400 | 431 | return buildClient(restClientSettings(), clusterHosts.toArray(new HttpHost[0])); |
|
0 commit comments