|
43 | 43 | import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
44 | 44 | import static org.hamcrest.Matchers.hasSize;
|
45 | 45 | import static org.hamcrest.Matchers.is;
|
| 46 | +import static org.hamcrest.Matchers.lessThanOrEqualTo; |
46 | 47 |
|
47 | 48 | public class CrossClustersQueryIT extends AbstractMultiClustersTestCase {
|
48 | 49 | private static final String REMOTE_CLUSTER = "cluster-a";
|
@@ -339,6 +340,108 @@ public void testSearchesWhereNonExistentClusterIsSpecifiedWithWildcards() {
|
339 | 340 | }
|
340 | 341 | }
|
341 | 342 |
|
| 343 | + /** |
| 344 | + * Searches with LIMIT 0 are used by Kibana to get a list of columns. After the initial planning |
| 345 | + * (which involves cross-cluster field-caps calls), it is a coordinator only operation at query time |
| 346 | + * which uses a different pathway compared to queries that require data node (and remote data node) operations |
| 347 | + * at query time. |
| 348 | + */ |
| 349 | + public void testCCSExecutionOnSearchesWithLimit0() { |
| 350 | + setupTwoClusters(); |
| 351 | + |
| 352 | + // Ensure non-cross cluster queries have overall took time |
| 353 | + try (EsqlQueryResponse resp = runQuery("FROM logs* | LIMIT 0")) { |
| 354 | + EsqlExecutionInfo executionInfo = resp.getExecutionInfo(); |
| 355 | + assertNotNull(executionInfo); |
| 356 | + assertThat(executionInfo.isCrossClusterSearch(), is(false)); |
| 357 | + assertThat(executionInfo.overallTook().millis(), greaterThanOrEqualTo(0L)); |
| 358 | + } |
| 359 | + |
| 360 | + // ensure cross-cluster searches have overall took time and correct per-cluster details in EsqlExecutionInfo |
| 361 | + try (EsqlQueryResponse resp = runQuery("FROM logs*,cluster-a:* | LIMIT 0")) { |
| 362 | + EsqlExecutionInfo executionInfo = resp.getExecutionInfo(); |
| 363 | + assertNotNull(executionInfo); |
| 364 | + assertThat(executionInfo.isCrossClusterSearch(), is(true)); |
| 365 | + long overallTookMillis = executionInfo.overallTook().millis(); |
| 366 | + assertThat(overallTookMillis, greaterThanOrEqualTo(0L)); |
| 367 | + assertThat(executionInfo.clusterAliases(), equalTo(Set.of(REMOTE_CLUSTER, LOCAL_CLUSTER))); |
| 368 | + |
| 369 | + EsqlExecutionInfo.Cluster remoteCluster = executionInfo.getCluster(REMOTE_CLUSTER); |
| 370 | + assertThat(remoteCluster.getIndexExpression(), equalTo("*")); |
| 371 | + assertThat(remoteCluster.getStatus(), equalTo(EsqlExecutionInfo.Cluster.Status.SUCCESSFUL)); |
| 372 | + assertThat(remoteCluster.getTook().millis(), greaterThanOrEqualTo(0L)); |
| 373 | + assertThat(remoteCluster.getTook().millis(), lessThanOrEqualTo(overallTookMillis)); |
| 374 | + assertNull(remoteCluster.getTotalShards()); |
| 375 | + assertNull(remoteCluster.getSuccessfulShards()); |
| 376 | + assertNull(remoteCluster.getSkippedShards()); |
| 377 | + assertNull(remoteCluster.getFailedShards()); |
| 378 | + |
| 379 | + EsqlExecutionInfo.Cluster localCluster = executionInfo.getCluster(LOCAL_CLUSTER); |
| 380 | + assertThat(localCluster.getIndexExpression(), equalTo("logs*")); |
| 381 | + assertThat(localCluster.getStatus(), equalTo(EsqlExecutionInfo.Cluster.Status.SUCCESSFUL)); |
| 382 | + assertThat(localCluster.getTook().millis(), greaterThanOrEqualTo(0L)); |
| 383 | + assertThat(localCluster.getTook().millis(), lessThanOrEqualTo(overallTookMillis)); |
| 384 | + assertNull(localCluster.getTotalShards()); |
| 385 | + assertNull(localCluster.getSuccessfulShards()); |
| 386 | + assertNull(localCluster.getSkippedShards()); |
| 387 | + assertNull(localCluster.getFailedShards()); |
| 388 | + } |
| 389 | + |
| 390 | + try (EsqlQueryResponse resp = runQuery("FROM logs*,cluster-a:nomatch* | LIMIT 0")) { |
| 391 | + EsqlExecutionInfo executionInfo = resp.getExecutionInfo(); |
| 392 | + assertNotNull(executionInfo); |
| 393 | + assertThat(executionInfo.isCrossClusterSearch(), is(true)); |
| 394 | + long overallTookMillis = executionInfo.overallTook().millis(); |
| 395 | + assertThat(overallTookMillis, greaterThanOrEqualTo(0L)); |
| 396 | + assertThat(executionInfo.clusterAliases(), equalTo(Set.of(REMOTE_CLUSTER, LOCAL_CLUSTER))); |
| 397 | + |
| 398 | + EsqlExecutionInfo.Cluster remoteCluster = executionInfo.getCluster(REMOTE_CLUSTER); |
| 399 | + assertThat(remoteCluster.getIndexExpression(), equalTo("nomatch*")); |
| 400 | + assertThat(remoteCluster.getStatus(), equalTo(EsqlExecutionInfo.Cluster.Status.SKIPPED)); |
| 401 | + assertThat(remoteCluster.getTook().millis(), equalTo(0L)); |
| 402 | + assertThat(remoteCluster.getTotalShards(), equalTo(0)); |
| 403 | + assertThat(remoteCluster.getSuccessfulShards(), equalTo(0)); |
| 404 | + assertThat(remoteCluster.getSkippedShards(), equalTo(0)); |
| 405 | + assertThat(remoteCluster.getFailedShards(), equalTo(0)); |
| 406 | + |
| 407 | + EsqlExecutionInfo.Cluster localCluster = executionInfo.getCluster(LOCAL_CLUSTER); |
| 408 | + assertThat(localCluster.getIndexExpression(), equalTo("logs*")); |
| 409 | + assertThat(localCluster.getStatus(), equalTo(EsqlExecutionInfo.Cluster.Status.SUCCESSFUL)); |
| 410 | + assertThat(localCluster.getTook().millis(), greaterThanOrEqualTo(0L)); |
| 411 | + assertThat(localCluster.getTook().millis(), lessThanOrEqualTo(overallTookMillis)); |
| 412 | + assertNull(localCluster.getTotalShards()); |
| 413 | + assertNull(localCluster.getSuccessfulShards()); |
| 414 | + assertNull(localCluster.getSkippedShards()); |
| 415 | + assertNull(localCluster.getFailedShards()); |
| 416 | + } |
| 417 | + |
| 418 | + try (EsqlQueryResponse resp = runQuery("FROM nomatch*,cluster-a:* | LIMIT 0")) { |
| 419 | + EsqlExecutionInfo executionInfo = resp.getExecutionInfo(); |
| 420 | + assertNotNull(executionInfo); |
| 421 | + assertThat(executionInfo.isCrossClusterSearch(), is(true)); |
| 422 | + long overallTookMillis = executionInfo.overallTook().millis(); |
| 423 | + assertThat(overallTookMillis, greaterThanOrEqualTo(0L)); |
| 424 | + assertThat(executionInfo.clusterAliases(), equalTo(Set.of(REMOTE_CLUSTER, LOCAL_CLUSTER))); |
| 425 | + |
| 426 | + EsqlExecutionInfo.Cluster remoteCluster = executionInfo.getCluster(REMOTE_CLUSTER); |
| 427 | + assertThat(remoteCluster.getIndexExpression(), equalTo("*")); |
| 428 | + assertThat(remoteCluster.getStatus(), equalTo(EsqlExecutionInfo.Cluster.Status.SUCCESSFUL)); |
| 429 | + assertThat(remoteCluster.getTook().millis(), greaterThanOrEqualTo(0L)); |
| 430 | + assertThat(remoteCluster.getTook().millis(), lessThanOrEqualTo(overallTookMillis)); |
| 431 | + assertNull(remoteCluster.getTotalShards()); |
| 432 | + assertNull(remoteCluster.getSuccessfulShards()); |
| 433 | + assertNull(remoteCluster.getSkippedShards()); |
| 434 | + assertNull(remoteCluster.getFailedShards()); |
| 435 | + |
| 436 | + EsqlExecutionInfo.Cluster localCluster = executionInfo.getCluster(LOCAL_CLUSTER); |
| 437 | + assertThat(localCluster.getIndexExpression(), equalTo("nomatch*")); |
| 438 | + // TODO: in https://github.com/elastic/elasticsearch/issues/112886, this will be changed to be SKIPPED |
| 439 | + assertThat(localCluster.getStatus(), equalTo(EsqlExecutionInfo.Cluster.Status.SUCCESSFUL)); |
| 440 | + assertThat(localCluster.getTook().millis(), greaterThanOrEqualTo(0L)); |
| 441 | + assertThat(localCluster.getTook().millis(), lessThanOrEqualTo(overallTookMillis)); |
| 442 | + } |
| 443 | + } |
| 444 | + |
342 | 445 | public void testMetadataIndex() {
|
343 | 446 | Map<String, Object> testClusterInfo = setupTwoClusters();
|
344 | 447 | int localNumShards = (Integer) testClusterInfo.get("local.num_shards");
|
|
0 commit comments