Skip to content

Commit 9008195

Browse files
committed
Fixed failing tests to align with new model for skip_un=true clusters at plan time
1 parent 652f2be commit 9008195

File tree

3 files changed

+24
-510
lines changed

3 files changed

+24
-510
lines changed

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,35 +91,33 @@ public void testFailed() throws Exception {
9191
assertThat(telemetry.getSuccessCount(), equalTo(0L));
9292
assertThat(telemetry.getByRemoteCluster().size(), equalTo(0));
9393

94-
// One remote is skipped, one is not
94+
// Errors from both remotes
9595
telemetry = getTelemetryFromFailedQuery("from logs-*,c*:no_such_index | stats sum (v)");
9696

9797
assertThat(telemetry.getTotalCount(), equalTo(1L));
9898
assertThat(telemetry.getSuccessCount(), equalTo(0L));
99-
assertThat(telemetry.getByRemoteCluster().size(), equalTo(1));
99+
assertThat(telemetry.getByRemoteCluster().size(), equalTo(0));
100100
assertThat(telemetry.getRemotesPerSearchAvg(), equalTo(2.0));
101101
assertThat(telemetry.getRemotesPerSearchMax(), equalTo(2L));
102-
assertThat(telemetry.getSearchCountWithSkippedRemotes(), equalTo(1L));
102+
assertThat(telemetry.getSearchCountWithSkippedRemotes(), equalTo(0L));
103103
Map<String, Long> expectedFailure = Map.of(CCSUsageTelemetry.Result.NOT_FOUND.getName(), 1L);
104104
assertThat(telemetry.getFailureReasons(), equalTo(expectedFailure));
105-
// cluster-b should be skipped
106-
assertThat(telemetry.getByRemoteCluster().get(REMOTE2).getCount(), equalTo(0L));
107-
assertThat(telemetry.getByRemoteCluster().get(REMOTE2).getSkippedCount(), equalTo(1L));
108105

109106
// this is only for cluster-a so no skipped remotes
110107
telemetry = getTelemetryFromFailedQuery("from logs-*,cluster-a:no_such_index | stats sum (v)");
108+
System.err.println("telemetry: " + telemetry);
111109
assertThat(telemetry.getTotalCount(), equalTo(2L));
112110
assertThat(telemetry.getSuccessCount(), equalTo(0L));
113-
assertThat(telemetry.getByRemoteCluster().size(), equalTo(1));
111+
assertThat(telemetry.getByRemoteCluster().size(), equalTo(0));
114112
assertThat(telemetry.getRemotesPerSearchAvg(), equalTo(2.0));
115113
assertThat(telemetry.getRemotesPerSearchMax(), equalTo(2L));
116-
assertThat(telemetry.getSearchCountWithSkippedRemotes(), equalTo(1L));
114+
assertThat(telemetry.getSearchCountWithSkippedRemotes(), equalTo(0L));
117115
expectedFailure = Map.of(CCSUsageTelemetry.Result.NOT_FOUND.getName(), 2L);
118116
assertThat(telemetry.getFailureReasons(), equalTo(expectedFailure));
119-
assertThat(telemetry.getByRemoteCluster().size(), equalTo(1));
117+
assertThat(telemetry.getByRemoteCluster().size(), equalTo(0));
120118
}
121119

122-
// TODO: enable when skip-up patch is merged
120+
// TODO: enable when skip-un patch is merged
123121
// public void testSkipAllRemotes() throws Exception {
124122
// var telemetry = getTelemetryFromQuery("from logs-*,c*:no_such_index | stats sum (v)", "unknown");
125123
//

x-pack/plugin/security/qa/multi-cluster/src/javaRestTest/java/org/elasticsearch/xpack/remotecluster/CrossClusterEsqlRCS1MissingIndicesIT.java

Lines changed: 11 additions & 243 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.elasticsearch.test.cluster.ElasticsearchCluster;
1515
import org.elasticsearch.xcontent.XContentBuilder;
1616
import org.elasticsearch.xcontent.json.JsonXContent;
17-
import org.hamcrest.Matchers;
1817
import org.junit.ClassRule;
1918
import org.junit.rules.RuleChain;
2019
import org.junit.rules.TestRule;
@@ -125,228 +124,11 @@ void assertExpectedClustersForMissingIndicesTests(Map<String, Object> responseMa
125124
}
126125

127126
@SuppressWarnings("unchecked")
128-
public void testSearchesAgainstNonMatchingIndicesWithSkipUnavailableTrue() throws Exception {
127+
public void testSearchesAgainstNonMatchingIndices() throws Exception {
129128
setupRolesAndPrivileges();
130129
setupIndex();
131130

132-
configureRemoteCluster(REMOTE_CLUSTER_ALIAS, fulfillingCluster, true, randomBoolean(), true);
133-
134-
// missing concrete local index is an error
135-
{
136-
String q = Strings.format("FROM nomatch,%s:%s | STATS count(*)", REMOTE_CLUSTER_ALIAS, INDEX2);
137-
138-
String limit1 = q + " | LIMIT 1";
139-
ResponseException e = expectThrows(ResponseException.class, () -> client().performRequest(esqlRequest(limit1)));
140-
assertThat(e.getMessage(), containsString("Unknown index [nomatch]"));
141-
142-
String limit0 = q + " | LIMIT 0";
143-
e = expectThrows(ResponseException.class, () -> client().performRequest(esqlRequest(limit0)));
144-
assertThat(e.getMessage(), Matchers.containsString("Unknown index [nomatch]"));
145-
}
146-
147-
// missing concrete remote index is not fatal when skip_unavailable=true (as long as an index matches on another cluster)
148-
{
149-
String q = Strings.format("FROM %s,%s:nomatch | STATS count(*)", INDEX1, REMOTE_CLUSTER_ALIAS);
150-
151-
String limit1 = q + " | LIMIT 1";
152-
Response response = client().performRequest(esqlRequest(limit1));
153-
assertOK(response);
154-
155-
Map<String, Object> map = responseAsMap(response);
156-
assertThat(((ArrayList<?>) map.get("columns")).size(), greaterThanOrEqualTo(1));
157-
assertThat(((ArrayList<?>) map.get("values")).size(), greaterThanOrEqualTo(1));
158-
159-
assertExpectedClustersForMissingIndicesTests(
160-
map,
161-
List.of(
162-
new ExpectedCluster("(local)", INDEX1, "successful", null),
163-
new ExpectedCluster(REMOTE_CLUSTER_ALIAS, "nomatch", "skipped", 0)
164-
)
165-
);
166-
167-
String limit0 = q + " | LIMIT 0";
168-
response = client().performRequest(esqlRequest(limit0));
169-
assertOK(response);
170-
171-
map = responseAsMap(response);
172-
assertThat(((ArrayList<?>) map.get("columns")).size(), greaterThanOrEqualTo(1));
173-
assertThat(((ArrayList<?>) map.get("values")).size(), is(0));
174-
175-
assertExpectedClustersForMissingIndicesTests(
176-
map,
177-
List.of(
178-
new ExpectedCluster("(local)", INDEX1, "successful", 0),
179-
new ExpectedCluster(REMOTE_CLUSTER_ALIAS, "nomatch", "skipped", 0)
180-
)
181-
);
182-
}
183-
184-
// since there is at least one matching index in the query, the missing wildcarded local index is not an error
185-
{
186-
String q = Strings.format("FROM nomatch*,%s:%s", REMOTE_CLUSTER_ALIAS, INDEX2);
187-
188-
String limit1 = q + " | LIMIT 1";
189-
Response response = client().performRequest(esqlRequest(limit1));
190-
assertOK(response);
191-
192-
Map<String, Object> map = responseAsMap(response);
193-
assertThat(((ArrayList<?>) map.get("columns")).size(), greaterThanOrEqualTo(1));
194-
assertThat(((ArrayList<?>) map.get("values")).size(), greaterThanOrEqualTo(1));
195-
196-
assertExpectedClustersForMissingIndicesTests(
197-
map,
198-
List.of(
199-
// local cluster is never marked as SKIPPED even when no matching indices - just marked as 0 shards searched
200-
new ExpectedCluster("(local)", "nomatch*", "successful", 0),
201-
new ExpectedCluster(REMOTE_CLUSTER_ALIAS, INDEX2, "successful", null)
202-
)
203-
);
204-
205-
String limit0 = q + " | LIMIT 0";
206-
response = client().performRequest(esqlRequest(limit0));
207-
assertOK(response);
208-
209-
map = responseAsMap(response);
210-
assertThat(((ArrayList<?>) map.get("columns")).size(), greaterThanOrEqualTo(1));
211-
assertThat(((ArrayList<?>) map.get("values")).size(), is(0));
212-
213-
assertExpectedClustersForMissingIndicesTests(
214-
map,
215-
List.of(
216-
// local cluster is never marked as SKIPPED even when no matching indices - just marked as 0 shards searched
217-
new ExpectedCluster("(local)", "nomatch*", "successful", 0),
218-
new ExpectedCluster(REMOTE_CLUSTER_ALIAS, INDEX2, "successful", 0)
219-
)
220-
);
221-
}
222-
223-
// since at least one index of the query matches on some cluster, a missing wildcarded index on skip_un=true is not an error
224-
{
225-
String q = Strings.format("FROM %s,%s:nomatch*", INDEX1, REMOTE_CLUSTER_ALIAS);
226-
227-
String limit1 = q + " | LIMIT 1";
228-
Response response = client().performRequest(esqlRequest(limit1));
229-
assertOK(response);
230-
231-
Map<String, Object> map = responseAsMap(response);
232-
assertThat(((ArrayList<?>) map.get("columns")).size(), greaterThanOrEqualTo(1));
233-
assertThat(((ArrayList<?>) map.get("values")).size(), greaterThanOrEqualTo(1));
234-
235-
assertExpectedClustersForMissingIndicesTests(
236-
map,
237-
List.of(
238-
new ExpectedCluster("(local)", INDEX1, "successful", null),
239-
new ExpectedCluster(REMOTE_CLUSTER_ALIAS, "nomatch*", "skipped", 0)
240-
)
241-
);
242-
243-
String limit0 = q + " | LIMIT 0";
244-
response = client().performRequest(esqlRequest(limit0));
245-
assertOK(response);
246-
247-
map = responseAsMap(response);
248-
assertThat(((ArrayList<?>) map.get("columns")).size(), greaterThanOrEqualTo(1));
249-
assertThat(((ArrayList<?>) map.get("values")).size(), is(0));
250-
251-
assertExpectedClustersForMissingIndicesTests(
252-
map,
253-
List.of(
254-
new ExpectedCluster("(local)", INDEX1, "successful", 0),
255-
new ExpectedCluster(REMOTE_CLUSTER_ALIAS, "nomatch*", "skipped", 0)
256-
)
257-
);
258-
}
259-
260-
// an error is thrown if there are no matching indices at all, even when the cluster is skip_unavailable=true
261-
{
262-
// with non-matching concrete index
263-
String q = Strings.format("FROM %s:nomatch", REMOTE_CLUSTER_ALIAS);
264-
265-
String limit1 = q + " | LIMIT 1";
266-
ResponseException e = expectThrows(ResponseException.class, () -> client().performRequest(esqlRequest(limit1)));
267-
assertThat(e.getMessage(), containsString(Strings.format("Unknown index [%s:nomatch]", REMOTE_CLUSTER_ALIAS)));
268-
269-
String limit0 = q + " | LIMIT 0";
270-
e = expectThrows(ResponseException.class, () -> client().performRequest(esqlRequest(limit0)));
271-
assertThat(e.getMessage(), containsString(Strings.format("Unknown index [%s:nomatch]", REMOTE_CLUSTER_ALIAS)));
272-
}
273-
274-
// an error is thrown if there are no matching indices at all, even when the cluster is skip_unavailable=true and the
275-
// index was wildcarded
276-
{
277-
String q = Strings.format("FROM %s:nomatch*", REMOTE_CLUSTER_ALIAS);
278-
279-
String limit1 = q + " | LIMIT 1";
280-
ResponseException e = expectThrows(ResponseException.class, () -> client().performRequest(esqlRequest(limit1)));
281-
assertThat(e.getMessage(), containsString(Strings.format("Unknown index [%s:nomatch*]", REMOTE_CLUSTER_ALIAS)));
282-
283-
String limit0 = q + " | LIMIT 0";
284-
e = expectThrows(ResponseException.class, () -> client().performRequest(esqlRequest(limit0)));
285-
assertThat(e.getMessage(), containsString(Strings.format("Unknown index [%s:nomatch*]", REMOTE_CLUSTER_ALIAS)));
286-
}
287-
288-
// an error is thrown if there are no matching indices at all
289-
{
290-
String localExpr = randomFrom("nomatch", "nomatch*");
291-
String remoteExpr = randomFrom("nomatch", "nomatch*");
292-
String q = Strings.format("FROM %s,%s:%s", localExpr, REMOTE_CLUSTER_ALIAS, remoteExpr);
293-
294-
String limit1 = q + " | LIMIT 1";
295-
ResponseException e = expectThrows(ResponseException.class, () -> client().performRequest(esqlRequest(limit1)));
296-
assertThat(e.getMessage(), containsString("Unknown index"));
297-
assertThat(e.getMessage(), containsString(Strings.format("%s:%s", REMOTE_CLUSTER_ALIAS, remoteExpr)));
298-
299-
String limit0 = q + " | LIMIT 0";
300-
e = expectThrows(ResponseException.class, () -> client().performRequest(esqlRequest(limit0)));
301-
assertThat(e.getMessage(), containsString("Unknown index"));
302-
assertThat(e.getMessage(), containsString(Strings.format("%s:%s", REMOTE_CLUSTER_ALIAS, remoteExpr)));
303-
}
304-
305-
// TODO uncomment and test in follow-on PR which does skip_unavailable handling at execution time
306-
// {
307-
// String q = Strings.format("FROM %s,%s:nomatch,%s:%s*", INDEX1, REMOTE_CLUSTER_ALIAS, REMOTE_CLUSTER_ALIAS, INDEX2);
308-
//
309-
// String limit1 = q + " | LIMIT 1";
310-
// Response response = client().performRequest(esqlRequest(limit1));
311-
// assertOK(response);
312-
//
313-
// Map<String, Object> map = responseAsMap(response);
314-
// assertThat(((ArrayList<?>) map.get("columns")).size(), greaterThanOrEqualTo(1));
315-
// assertThat(((ArrayList<?>) map.get("values")).size(), greaterThanOrEqualTo(1));
316-
//
317-
// assertExpectedClustersForMissingIndicesTests(map,
318-
// List.of(
319-
// new ExpectedCluster("(local)", INDEX1, "successful", null),
320-
// new ExpectedCluster(REMOTE_CLUSTER_ALIAS, "nomatch," + INDEX2 + "*", "skipped", 0)
321-
// )
322-
// );
323-
//
324-
// String limit0 = q + " | LIMIT 0";
325-
// response = client().performRequest(esqlRequest(limit0));
326-
// assertOK(response);
327-
//
328-
// map = responseAsMap(response);
329-
// assertThat(((ArrayList<?>) map.get("columns")).size(), greaterThanOrEqualTo(1));
330-
// assertThat(((ArrayList<?>) map.get("values")).size(), is(0));
331-
//
332-
// assertExpectedClustersForMissingIndicesTests(map,
333-
// List.of(
334-
// new ExpectedCluster("(local)", INDEX1, "successful", 0),
335-
// new ExpectedCluster(REMOTE_CLUSTER_ALIAS, "nomatch," + INDEX2 + "*", "skipped", 0)
336-
// )
337-
// );
338-
// }
339-
}
340-
341-
@SuppressWarnings("unchecked")
342-
public void testSearchesAgainstNonMatchingIndicesWithSkipUnavailableFalse() throws Exception {
343-
// Remote cluster is closed and skip_unavailable is set to false.
344-
// Although the other cluster is open, we expect an Exception.
345-
346-
setupRolesAndPrivileges();
347-
setupIndex();
348-
349-
configureRemoteCluster(REMOTE_CLUSTER_ALIAS, fulfillingCluster, true, randomBoolean(), false);
131+
configureRemoteCluster(REMOTE_CLUSTER_ALIAS, fulfillingCluster, true, randomBoolean(), randomBoolean());
350132

351133
// missing concrete local index is an error
352134
{
@@ -361,9 +143,9 @@ public void testSearchesAgainstNonMatchingIndicesWithSkipUnavailableFalse() thro
361143
assertThat(e.getMessage(), containsString("Unknown index [nomatch]"));
362144
}
363145

364-
// missing concrete remote index is not fatal when skip_unavailable=true (as long as an index matches on another cluster)
146+
// missing concrete index on remote cluster is an error
365147
{
366-
String q = Strings.format("FROM %s,%s:nomatch | STATS count(*)", INDEX1, REMOTE_CLUSTER_ALIAS);
148+
String q = Strings.format("FROM %s:nomatch", REMOTE_CLUSTER_ALIAS);
367149

368150
String limit1 = q + " | LIMIT 1";
369151
ResponseException e = expectThrows(ResponseException.class, () -> client().performRequest(esqlRequest(limit1)));
@@ -413,37 +195,23 @@ public void testSearchesAgainstNonMatchingIndicesWithSkipUnavailableFalse() thro
413195
);
414196
}
415197

416-
// query is fatal since the remote cluster has skip_unavailable=false and has no matching indices
417-
{
418-
String q = Strings.format("FROM %s,%s:nomatch*", INDEX1, REMOTE_CLUSTER_ALIAS);
419-
420-
String limit1 = q + " | LIMIT 1";
421-
ResponseException e = expectThrows(ResponseException.class, () -> client().performRequest(esqlRequest(limit1)));
422-
assertThat(e.getMessage(), containsString(Strings.format("Unknown index [%s:nomatch*]", REMOTE_CLUSTER_ALIAS)));
423-
424-
String limit0 = q + " | LIMIT 0";
425-
e = expectThrows(ResponseException.class, () -> client().performRequest(esqlRequest(limit0)));
426-
assertThat(e.getMessage(), Matchers.containsString(Strings.format("Unknown index [%s:nomatch*]", REMOTE_CLUSTER_ALIAS)));
427-
}
428-
429198
// an error is thrown if there are no matching indices at all
430199
{
431-
// with non-matching concrete index
432-
String q = Strings.format("FROM %s:nomatch", REMOTE_CLUSTER_ALIAS);
200+
String q = Strings.format("FROM %s:nomatch*", REMOTE_CLUSTER_ALIAS);
433201

434202
String limit1 = q + " | LIMIT 1";
435203
ResponseException e = expectThrows(ResponseException.class, () -> client().performRequest(esqlRequest(limit1)));
436-
assertThat(e.getMessage(), containsString(Strings.format("Unknown index [%s:nomatch]", REMOTE_CLUSTER_ALIAS)));
204+
assertThat(e.getMessage(), containsString(Strings.format("Unknown index [%s:nomatch*]", REMOTE_CLUSTER_ALIAS)));
437205

438206
String limit0 = q + " | LIMIT 0";
439207
e = expectThrows(ResponseException.class, () -> client().performRequest(esqlRequest(limit0)));
440-
assertThat(e.getMessage(), containsString(Strings.format("Unknown index [%s:nomatch]", REMOTE_CLUSTER_ALIAS)));
208+
assertThat(e.getMessage(), containsString(Strings.format("Unknown index [%s:nomatch*]", REMOTE_CLUSTER_ALIAS)));
441209
}
442210

443-
// an error is thrown if there are no matching indices at all
211+
// an error is thrown if there are no matching indices at all (2 clusters)
444212
{
445-
String localExpr = randomFrom("nomatch", "nomatch*");
446-
String remoteExpr = randomFrom("nomatch", "nomatch*");
213+
String localExpr = "nomatch*";
214+
String remoteExpr = "nomatch*";
447215
String q = Strings.format("FROM %s,%s:%s", localExpr, REMOTE_CLUSTER_ALIAS, remoteExpr);
448216

449217
String limit1 = q + " | LIMIT 1";
@@ -457,7 +225,7 @@ public void testSearchesAgainstNonMatchingIndicesWithSkipUnavailableFalse() thro
457225
assertThat(e.getMessage(), containsString(Strings.format("%s:%s", REMOTE_CLUSTER_ALIAS, remoteExpr)));
458226
}
459227

460-
// error since the remote cluster with skip_unavailable=false specified a concrete index that is not found
228+
// error since the remote cluster specified a concrete index that is not found
461229
{
462230
String q = Strings.format("FROM %s,%s:nomatch,%s:%s*", INDEX1, REMOTE_CLUSTER_ALIAS, REMOTE_CLUSTER_ALIAS, INDEX2);
463231

0 commit comments

Comments
 (0)