Skip to content

Commit c5ebb70

Browse files
committed
Fix more tests
1 parent 29d0edb commit c5ebb70

File tree

4 files changed

+91
-17
lines changed

4 files changed

+91
-17
lines changed

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/CrossClusterQueryIT.java

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ public void testSearchesAgainstNonMatchingIndices() throws Exception {
260260
Map<String, Object> testClusterInfo = setupClusters(numClusters);
261261
int localNumShards = (Integer) testClusterInfo.get("local.num_shards");
262262
int remote1NumShards = (Integer) testClusterInfo.get("remote1.num_shards");
263+
int remote2NumShards = (Integer) testClusterInfo.get("remote2.num_shards");
263264
String localIndex = (String) testClusterInfo.get("local.index");
264265
String remote1Index = (String) testClusterInfo.get("remote1.index");
265266
String remote2Index = (String) testClusterInfo.get("remote2.index");
@@ -281,7 +282,23 @@ public void testSearchesAgainstNonMatchingIndices() throws Exception {
281282
{
282283
String q = "FROM logs*,cluster-a:nomatch";
283284
String expectedError = "Unknown index [cluster-a:nomatch]";
285+
setSkipUnavailable(REMOTE_CLUSTER_1, false);
284286
expectVerificationExceptionForQuery(q, expectedError, requestIncludeMeta);
287+
setSkipUnavailable(REMOTE_CLUSTER_1, true);
288+
try (EsqlQueryResponse resp = runQuery(q, requestIncludeMeta)) {
289+
assertThat(getValuesList(resp).size(), greaterThanOrEqualTo(1));
290+
EsqlExecutionInfo executionInfo = resp.getExecutionInfo();
291+
assertThat(executionInfo.isCrossClusterSearch(), is(true));
292+
assertThat(executionInfo.includeCCSMetadata(), equalTo(responseExpectMeta));
293+
assertExpectedClustersForMissingIndicesTests(
294+
executionInfo,
295+
List.of(
296+
new ExpectedCluster(LOCAL_CLUSTER, "logs*", EsqlExecutionInfo.Cluster.Status.SUCCESSFUL, localNumShards),
297+
new ExpectedCluster(REMOTE_CLUSTER_1, "nomatch", EsqlExecutionInfo.Cluster.Status.SKIPPED, 0)
298+
)
299+
);
300+
301+
}
285302
}
286303

287304
// No error since local non-matching index has wildcard and the remote cluster index expression matches
@@ -411,7 +428,34 @@ public void testSearchesAgainstNonMatchingIndices() throws Exception {
411428
String remote2IndexName = randomFrom(remote2Index, IDX_ALIAS, FILTERED_IDX_ALIAS);
412429
String q = Strings.format("FROM %s*,cluster-a:nomatch,%s:%s*", localIndexName, REMOTE_CLUSTER_2, remote2IndexName);
413430
String expectedError = "Unknown index [cluster-a:nomatch]";
431+
setSkipUnavailable(REMOTE_CLUSTER_1, false);
414432
expectVerificationExceptionForQuery(q, expectedError, requestIncludeMeta);
433+
setSkipUnavailable(REMOTE_CLUSTER_1, true);
434+
try (EsqlQueryResponse resp = runQuery(q, requestIncludeMeta)) {
435+
assertThat(getValuesList(resp).size(), greaterThanOrEqualTo(1));
436+
EsqlExecutionInfo executionInfo = resp.getExecutionInfo();
437+
assertThat(executionInfo.isCrossClusterSearch(), is(true));
438+
assertThat(executionInfo.includeCCSMetadata(), equalTo(responseExpectMeta));
439+
assertExpectedClustersForMissingIndicesTests(
440+
executionInfo,
441+
List.of(
442+
new ExpectedCluster(
443+
LOCAL_CLUSTER,
444+
"alias-filtered-1*",
445+
EsqlExecutionInfo.Cluster.Status.SUCCESSFUL,
446+
localNumShards
447+
),
448+
new ExpectedCluster(REMOTE_CLUSTER_1, "nomatch", EsqlExecutionInfo.Cluster.Status.SKIPPED, 0),
449+
new ExpectedCluster(
450+
REMOTE_CLUSTER_2,
451+
remote2IndexName + "*",
452+
EsqlExecutionInfo.Cluster.Status.SUCCESSFUL,
453+
remote2NumShards
454+
)
455+
)
456+
);
457+
458+
}
415459
}
416460
}
417461

@@ -454,8 +498,8 @@ public void assertExpectedClustersForMissingIndicesTests(EsqlExecutionInfo execu
454498
assertThat(msg, cluster.getSkippedShards(), equalTo(expectedCluster.totalShards()));
455499
assertThat(msg, cluster.getFailures().size(), equalTo(1));
456500
assertThat(msg, cluster.getFailures().get(0).getCause(), instanceOf(VerificationException.class));
457-
String expectedMsg = "Unknown index [" + expectedCluster.indexExpression() + "]";
458-
assertThat(msg, cluster.getFailures().get(0).getCause().getMessage(), containsString(expectedMsg));
501+
assertThat(msg, cluster.getFailures().get(0).getCause().getMessage(), containsString("Unknown index"));
502+
assertThat(msg, cluster.getFailures().get(0).getCause().getMessage(), containsString(expectedCluster.indexExpression()));
459503
hasSkipped = true;
460504
}
461505
// currently failed shards is always zero - change this once we start allowing partial data for individual shard failures
@@ -809,18 +853,30 @@ public void testWarnings() throws Exception {
809853
assertTrue(latch.await(30, TimeUnit.SECONDS));
810854
}
811855

812-
// Non-disconnect remote failures still fail the request even if skip_unavailable is true
856+
// Non-disconnect remote failures lead to skipping if skip_unavailable is true
813857
public void testRemoteFailureSkipUnavailableTrue() throws IOException {
814858
Map<String, Object> testClusterInfo = setupFailClusters();
815859
String localIndex = (String) testClusterInfo.get("local.index");
816860
String remote1Index = (String) testClusterInfo.get("remote.index");
817861
String q = Strings.format("FROM %s,cluster-a:%s*", localIndex, remote1Index);
818862

819-
Exception error = expectThrows(Exception.class, () -> runQuery(q, false));
820-
error = EsqlTestUtils.unwrapIfWrappedInRemoteException(error);
863+
try (EsqlQueryResponse resp = runQuery(q, randomBoolean())) {
864+
EsqlExecutionInfo executionInfo = resp.getExecutionInfo();
865+
assertNotNull(executionInfo);
866+
assertThat(executionInfo.isCrossClusterSearch(), is(true));
867+
assertThat(executionInfo.overallTook().millis(), greaterThanOrEqualTo(0L));
821868

822-
assertThat(error, instanceOf(IllegalStateException.class));
823-
assertThat(error.getMessage(), containsString("Accessing failing field"));
869+
EsqlExecutionInfo.Cluster remoteCluster = executionInfo.getCluster(REMOTE_CLUSTER_1);
870+
assertThat(remoteCluster.getIndexExpression(), equalTo("logs-2*"));
871+
assertThat(remoteCluster.getStatus(), equalTo(EsqlExecutionInfo.Cluster.Status.SKIPPED));
872+
assertThat(remoteCluster.getTook().millis(), greaterThanOrEqualTo(0L));
873+
assertThat(remoteCluster.getTotalShards(), equalTo(0));
874+
assertThat(remoteCluster.getSuccessfulShards(), equalTo(0));
875+
assertThat(remoteCluster.getSkippedShards(), equalTo(0));
876+
assertThat(remoteCluster.getFailedShards(), equalTo(0));
877+
assertThat(remoteCluster.getFailures(), hasSize(1));
878+
assertThat(remoteCluster.getFailures().getFirst().reason(), containsString("Accessing failing field"));
879+
}
824880
}
825881

826882
private static void assertClusterMetadataInResponse(EsqlQueryResponse resp, boolean responseExpectMeta) {

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/CrossClusterQueryWithPartialResultsIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ public void sendResponse(Exception exception) {
227227
assertNotNull(unwrapped);
228228
assertThat(unwrapped.getMessage(), equalTo(simulatedFailure.getMessage()));
229229
}
230+
// The failure leads to skipped regardless of allowPartialResults
230231
request.allowPartialResults(true);
231232
try (var resp = runQuery(request)) {
232233
assertTrue(resp.isPartial());
@@ -289,7 +290,7 @@ public void testFailToStartRequestOnRemoteCluster() throws Exception {
289290
assertThat(returnedIds, equalTo(local.okIds));
290291
assertClusterSuccess(resp, LOCAL_CLUSTER, local.okShards);
291292
EsqlExecutionInfo.Cluster remoteInfo = resp.getExecutionInfo().getCluster(REMOTE_CLUSTER_1);
292-
assertThat(remoteInfo.getStatus(), equalTo(EsqlExecutionInfo.Cluster.Status.PARTIAL));
293+
assertThat(remoteInfo.getStatus(), equalTo(EsqlExecutionInfo.Cluster.Status.SKIPPED));
293294
assertClusterFailure(resp, REMOTE_CLUSTER_1, simulatedFailure.getMessage());
294295
}
295296
} finally {

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plugin/ClusterComputeHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ void startComputeOnRemoteCluster(
8585
final AtomicReference<ComputeResponse> finalResponse = new AtomicReference<>();
8686
listener = listener.delegateResponse((l, e) -> {
8787
final boolean receivedResults = finalResponse.get() != null || pagesFetched.get();
88-
if (EsqlCCSUtils.shouldIgnoreRuntimeError(executionInfo, clusterAlias, e)) {
88+
if (EsqlCCSUtils.shouldIgnoreRuntimeError(executionInfo, clusterAlias, e)
89+
|| (configuration.allowPartialResults() && EsqlCCSUtils.canAllowPartial(e))) {
8990
EsqlCCSUtils.markClusterWithFinalStateAndNoShards(
9091
executionInfo,
9192
clusterAlias,

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/session/EsqlCCSUtilsTests.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import static org.hamcrest.Matchers.containsString;
5454
import static org.hamcrest.Matchers.equalTo;
5555
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
56+
import static org.hamcrest.Matchers.hasSize;
5657
import static org.hamcrest.Matchers.is;
5758

5859
public class EsqlCCSUtilsTests extends ESTestCase {
@@ -364,30 +365,45 @@ public void testUpdateExecutionInfoWithClustersWithNoMatchingIndices() {
364365
}
365366

366367
// No remotes had matching indices from field-caps call: 1) remote1 because it was unavailable, 2) remote2 was available,
367-
// but had no matching indices and since a concrete index was requested, a VerificationException is thrown
368+
// but had no matching indices. remote2 is set to skipped since it has skip_unavailable by default.
368369
{
369370
EsqlExecutionInfo executionInfo = new EsqlExecutionInfo(true);
370371
executionInfo.swapCluster(LOCAL_CLUSTER_ALIAS, (k, v) -> new EsqlExecutionInfo.Cluster(LOCAL_CLUSTER_ALIAS, "logs*"));
371372
executionInfo.swapCluster(REMOTE1_ALIAS, (k, v) -> new EsqlExecutionInfo.Cluster(REMOTE1_ALIAS, "*", randomBoolean()));
372373
executionInfo.swapCluster(
373374
REMOTE2_ALIAS,
374-
(k, v) -> new EsqlExecutionInfo.Cluster(REMOTE2_ALIAS, "mylogs1,mylogs2,logs*", randomBoolean())
375+
(k, v) -> new EsqlExecutionInfo.Cluster(REMOTE2_ALIAS, "mylogs1,mylogs2*", randomBoolean())
375376
);
376377

377378
EsIndex esIndex = new EsIndex(
378-
"logs*,remote2:mylogs1,remote2:mylogs2,remote2:logs*", // original user-provided index expression
379+
"logs*,remote2:mylogs1,remote2:mylogs2*,remote1:logs*", // original user-provided index expression
379380
randomMapping(),
380381
Map.of("logs-a", IndexMode.STANDARD) // resolved indices from field-caps (none from either remote)
381382
);
382383

383384
var failure = new FieldCapabilitiesFailure(new String[] { "logs-a" }, new NoSeedNodeLeftException("unable to connect"));
384385
Map<String, FieldCapabilitiesFailure> unavailableClusters = Map.of(REMOTE1_ALIAS, failure);
385386
IndexResolution indexResolution = IndexResolution.valid(esIndex, esIndex.concreteIndices(), Set.of(), unavailableClusters);
386-
VerificationException ve = expectThrows(
387-
VerificationException.class,
388-
() -> EsqlCCSUtils.updateExecutionInfoWithClustersWithNoMatchingIndices(executionInfo, indexResolution)
389-
);
390-
assertThat(ve.getDetailedMessage(), containsString("Unknown index [remote2:mylogs1,mylogs2,logs*]"));
387+
EsqlCCSUtils.updateExecutionInfoWithClustersWithNoMatchingIndices(executionInfo, indexResolution);
388+
389+
EsqlExecutionInfo.Cluster localCluster = executionInfo.getCluster(LOCAL_CLUSTER_ALIAS);
390+
assertThat(localCluster.getIndexExpression(), equalTo("logs*"));
391+
assertClusterStatusAndShardCounts(localCluster, EsqlExecutionInfo.Cluster.Status.RUNNING);
392+
393+
EsqlExecutionInfo.Cluster remote1Cluster = executionInfo.getCluster(REMOTE1_ALIAS);
394+
// since remote1 is in the unavailable Map (passed to IndexResolution.valid), it's status will not be changed
395+
// by updateExecutionInfoWithClustersWithNoMatchingIndices (it is handled in updateExecutionInfoWithUnavailableClusters)
396+
assertThat(remote1Cluster.getStatus(), equalTo(EsqlExecutionInfo.Cluster.Status.RUNNING));
397+
398+
EsqlExecutionInfo.Cluster remote2Cluster = executionInfo.getCluster(REMOTE2_ALIAS);
399+
assertThat(remote2Cluster.getStatus(), equalTo(EsqlExecutionInfo.Cluster.Status.SKIPPED));
400+
assertThat(remote2Cluster.getTook().millis(), greaterThanOrEqualTo(0L));
401+
assertThat(remote2Cluster.getTotalShards(), equalTo(0));
402+
assertThat(remote2Cluster.getSuccessfulShards(), equalTo(0));
403+
assertThat(remote2Cluster.getSkippedShards(), equalTo(0));
404+
assertThat(remote2Cluster.getFailedShards(), equalTo(0));
405+
assertThat(remote2Cluster.getFailures(), hasSize(1));
406+
assertThat(remote2Cluster.getFailures().getFirst().reason(), containsString("Unknown index [remote2:mylogs1,mylogs2*]"));
391407
}
392408

393409
// test where remote2 is already marked as SKIPPED so no modifications or exceptions should be thrown

0 commit comments

Comments
 (0)