Skip to content

Commit 2e932be

Browse files
authored
Improve error messages to help debug flaky tests (#120838) (#121332)
Recent test failure in CrossClusterEsqlRCS2EnrichUnavailableRemotesIT is undecipherable because of the structure of these qa tests, so adding more context to the error message to help debug them if/when they next fail.
1 parent dcf506d commit 2e932be

File tree

3 files changed

+65
-92
lines changed

3 files changed

+65
-92
lines changed

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

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.ArrayList;
2424
import java.util.Map;
2525
import java.util.concurrent.atomic.AtomicBoolean;
26+
import java.util.function.Function;
2627

2728
import static org.hamcrest.Matchers.anyOf;
2829
import static org.hamcrest.Matchers.containsString;
@@ -108,32 +109,34 @@ private void esqlEnrichWithRandomSkipUnavailable() throws Exception {
108109
Map<?, ?> localClusterDetails = (Map<?, ?>) clusterDetails.get("(local)");
109110
Map<?, ?> remoteClusterDetails = (Map<?, ?>) clusterDetails.get("my_remote_cluster");
110111

112+
Function<String, String> info = (msg) -> "test: esqlEnrichWithRandomSkipUnavailable: " + msg;
113+
111114
assertOK(response);
112-
assertThat((int) map.get("took"), greaterThan(0));
113-
assertThat(values.size(), is(6));
115+
assertThat(info.apply("overall took"), (int) map.get("took"), greaterThan(0));
116+
assertThat(info.apply("overall num values"), values.size(), is(6));
114117
for (int i = 0; i < 6; i++) {
115118
ArrayList<?> value = (ArrayList<?>) values.get(i);
116119
// Size is 3: ID, Email, Designation.
117-
assertThat(value.size(), is(3));
120+
assertThat(info.apply("should be id, email, designation, so size 3"), value.size(), is(3));
118121
// Email
119-
assertThat((String) value.get(0), endsWith("@corp.co"));
122+
assertThat(info.apply("email was: " + value.get(0)), (String) value.get(0), endsWith("@corp.co"));
120123
// ID
121-
assertThat(value.get(1), is(i + 1));
124+
assertThat(info.apply("id"), value.get(1), is(i + 1));
122125
}
123126

124-
assertThat((int) clusters.get("total"), is(2));
125-
assertThat((int) clusters.get("successful"), is(2));
126-
assertThat((int) clusters.get("running"), is(0));
127-
assertThat((int) clusters.get("skipped"), is(0));
128-
assertThat((int) clusters.get("partial"), is(0));
129-
assertThat((int) clusters.get("failed"), is(0));
127+
assertThat(info.apply("total clusters"), (int) clusters.get("total"), is(2));
128+
assertThat(info.apply("successful clusters"), (int) clusters.get("successful"), is(2));
129+
assertThat(info.apply("running clusters"), (int) clusters.get("running"), is(0));
130+
assertThat(info.apply("skipped clusters"), (int) clusters.get("skipped"), is(0));
131+
assertThat(info.apply("partial clusters"), (int) clusters.get("partial"), is(0));
132+
assertThat(info.apply("failed clusters"), (int) clusters.get("failed"), is(0));
130133

131134
assertThat(clusterDetails.size(), is(2));
132-
assertThat((int) localClusterDetails.get("took"), greaterThan(0));
133-
assertThat(localClusterDetails.get("status"), is("successful"));
135+
assertThat(info.apply("local cluster took"), (int) localClusterDetails.get("took"), greaterThan(0));
136+
assertThat(info.apply("local cluster status"), localClusterDetails.get("status"), is("successful"));
134137

135-
assertThat((int) remoteClusterDetails.get("took"), greaterThan(0));
136-
assertThat(remoteClusterDetails.get("status"), is("successful"));
138+
assertThat(info.apply("remote cluster took"), (int) remoteClusterDetails.get("took"), greaterThan(0));
139+
assertThat(info.apply("remote cluster status"), remoteClusterDetails.get("status"), is("successful"));
137140
}
138141

139142
@SuppressWarnings("unchecked")
@@ -153,44 +156,48 @@ private void esqlEnrichWithSkipUnavailableTrue() throws Exception {
153156
Map<?, ?> localClusterDetails = (Map<?, ?>) clusterDetails.get("(local)");
154157
Map<?, ?> remoteClusterDetails = (Map<?, ?>) clusterDetails.get("my_remote_cluster");
155158

159+
Function<String, String> info = (msg) -> "test: esqlEnrichWithSkipUnavailableTrue: " + msg;
160+
156161
assertOK(response);
157-
assertThat((int) map.get("took"), greaterThan(0));
158-
assertThat(values.size(), is(3));
162+
assertThat(info.apply("overall took"), (int) map.get("took"), greaterThan(0));
163+
assertThat(info.apply("overall values.size"), values.size(), is(3));
159164

160165
// We only have 3 values since the remote cluster is turned off.
161166
for (int i = 0; i < 3; i++) {
162167
ArrayList<?> value = (ArrayList<?>) values.get(i);
163168
// Size is 3: ID, Email, Designation.
164-
assertThat(value.size(), is(3));
169+
assertThat(info.apply("should be id, email, designation but had size: "), value.size(), is(3));
165170
// Email
166-
assertThat((String) value.get(0), endsWith("@corp.co"));
171+
assertThat(info.apply("email was: " + value.get(0)), (String) value.get(0), endsWith("@corp.co"));
167172
// ID
168-
assertThat(value.get(1), is(i + 1));
173+
assertThat(info.apply("id"), value.get(1), is(i + 1));
169174
}
170175

171-
assertThat((int) clusters.get("total"), is(2));
172-
assertThat((int) clusters.get("successful"), is(1));
173-
assertThat((int) clusters.get("running"), is(0));
174-
assertThat((int) clusters.get("skipped"), is(1));
175-
assertThat((int) clusters.get("partial"), is(0));
176-
assertThat((int) clusters.get("failed"), is(0));
176+
assertThat(info.apply("total clusters"), (int) clusters.get("total"), is(2));
177+
assertThat(info.apply("successful clusters"), (int) clusters.get("successful"), is(1));
178+
assertThat(info.apply("running clusters"), (int) clusters.get("running"), is(0));
179+
assertThat(info.apply("skipped clusters"), (int) clusters.get("skipped"), is(1));
180+
assertThat(info.apply("partial clusters"), (int) clusters.get("partial"), is(0));
181+
assertThat(info.apply("failed clusters"), (int) clusters.get("failed"), is(0));
177182

178-
assertThat(clusterDetails.size(), is(2));
179-
assertThat((int) localClusterDetails.get("took"), greaterThan(0));
180-
assertThat(localClusterDetails.get("status"), is("successful"));
183+
assertThat(info.apply("cluster details size"), clusterDetails.size(), is(2));
184+
assertThat(info.apply("local cluster took"), (int) localClusterDetails.get("took"), greaterThan(0));
185+
assertThat(info.apply("local cluster status"), localClusterDetails.get("status"), is("successful"));
181186

182-
assertThat((int) remoteClusterDetails.get("took"), greaterThan(0));
183-
assertThat(remoteClusterDetails.get("status"), is("skipped"));
187+
assertThat(info.apply("remote cluster took"), (int) remoteClusterDetails.get("took"), greaterThan(0));
188+
assertThat(info.apply("remote cluster status"), remoteClusterDetails.get("status"), is("skipped"));
184189

185190
ArrayList<?> remoteClusterFailures = (ArrayList<?>) remoteClusterDetails.get("failures");
186-
assertThat(remoteClusterFailures.size(), equalTo(1));
191+
assertThat(info.apply("remote cluster failure count"), remoteClusterFailures.size(), equalTo(1));
187192
Map<String, ?> failuresMap = (Map<String, ?>) remoteClusterFailures.get(0);
188193

189194
Map<String, ?> reason = (Map<String, ?>) failuresMap.get("reason");
190195
assertThat(
196+
info.apply("unexpected failure reason: " + reason),
191197
reason.get("type").toString(),
192198
oneOf("node_disconnected_exception", "connect_transport_exception", "node_not_connected_exception")
193199
);
200+
194201
} finally {
195202
fulfillingCluster.start();
196203
closeFulfillingClusterClient();
@@ -208,6 +215,7 @@ private void esqlEnrichWithSkipUnavailableFalse() throws Exception {
208215
ResponseException ex = expectThrows(ResponseException.class, () -> client().performRequest(esqlRequest(query)));
209216

210217
assertThat(
218+
"esqlEnrichWithSkipUnavailableFalse failure",
211219
ex.getMessage(),
212220
anyOf(
213221
containsString("connect_transport_exception"),

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

Lines changed: 22 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.ArrayList;
2626
import java.util.Map;
2727
import java.util.concurrent.atomic.AtomicReference;
28+
import java.util.function.Function;
2829

2930
import static org.hamcrest.Matchers.anyOf;
3031
import static org.hamcrest.Matchers.containsString;
@@ -110,56 +111,16 @@ public void setupPreRequisites() throws IOException {
110111
}
111112

112113
public void testEsqlEnrichWithSkipUnavailable() throws Exception {
113-
esqlEnrichWithRandomSkipUnavailable();
114114
esqlEnrichWithSkipUnavailableTrue();
115115
esqlEnrichWithSkipUnavailableFalse();
116116
}
117117

118-
private void esqlEnrichWithRandomSkipUnavailable() throws Exception {
119-
configureRemoteCluster("my_remote_cluster", fulfillingCluster, false, randomBoolean(), randomBoolean());
120-
121-
String query = "FROM to-be-enr*,my_remote_cluster:to-be-enr* | ENRICH " + randomFrom(modes) + ":employees-policy | LIMIT 10";
122-
Response response = performRequestWithRemoteSearchUser(esqlRequest(query));
123-
124-
Map<String, Object> map = responseAsMap(response);
125-
ArrayList<?> values = (ArrayList<?>) map.get("values");
126-
Map<?, ?> clusters = (Map<?, ?>) map.get("_clusters");
127-
Map<?, ?> clusterDetails = (Map<?, ?>) clusters.get("details");
128-
Map<?, ?> localClusterDetails = (Map<?, ?>) clusterDetails.get("(local)");
129-
Map<?, ?> remoteClusterDetails = (Map<?, ?>) clusterDetails.get("my_remote_cluster");
130-
131-
assertOK(response);
132-
assertThat((int) map.get("took"), greaterThan(0));
133-
assertThat(values.size(), is(6));
134-
for (int i = 0; i < 6; i++) {
135-
ArrayList<?> value = (ArrayList<?>) values.get(i);
136-
// Size is 3: ID, Email, Designation.
137-
assertThat(value.size(), is(3));
138-
// Email
139-
assertThat((String) value.get(0), endsWith("@corp.co"));
140-
// ID
141-
assertThat(value.get(1), is(i + 1));
142-
}
143-
144-
assertThat((int) clusters.get("total"), is(2));
145-
assertThat((int) clusters.get("successful"), is(2));
146-
assertThat((int) clusters.get("running"), is(0));
147-
assertThat((int) clusters.get("skipped"), is(0));
148-
assertThat((int) clusters.get("partial"), is(0));
149-
assertThat((int) clusters.get("failed"), is(0));
150-
151-
assertThat(clusterDetails.size(), is(2));
152-
assertThat((int) localClusterDetails.get("took"), greaterThan(0));
153-
assertThat(localClusterDetails.get("status"), is("successful"));
154-
155-
assertThat((int) remoteClusterDetails.get("took"), greaterThan(0));
156-
assertThat(remoteClusterDetails.get("status"), is("successful"));
157-
}
158-
159118
@SuppressWarnings("unchecked")
160119
private void esqlEnrichWithSkipUnavailableTrue() throws Exception {
161120
configureRemoteCluster("my_remote_cluster", fulfillingCluster, false, randomBoolean(), true);
162121

122+
Function<String, String> info = (msg) -> "test: esqlEnrichWithSkipUnavailableTrue: " + msg;
123+
163124
try {
164125
fulfillingCluster.stop(true);
165126

@@ -174,40 +135,41 @@ private void esqlEnrichWithSkipUnavailableTrue() throws Exception {
174135
Map<?, ?> remoteClusterDetails = (Map<?, ?>) clusterDetails.get("my_remote_cluster");
175136

176137
assertOK(response);
177-
assertThat((int) map.get("took"), greaterThan(0));
178-
assertThat(values.size(), is(3));
138+
assertThat(info.apply("overall took"), (int) map.get("took"), greaterThan(0));
139+
assertThat(info.apply("overall values.size"), values.size(), is(3));
179140

180141
// We only have 3 values since the remote cluster is turned off.
181142
for (int i = 0; i < 3; i++) {
182143
ArrayList<?> value = (ArrayList<?>) values.get(i);
183144
// Size is 3: ID, Email, Designation.
184-
assertThat(value.size(), is(3));
145+
assertThat(info.apply("should be id, email, designation: "), value.size(), is(3));
185146
// Email
186-
assertThat((String) value.get(0), endsWith("@corp.co"));
147+
assertThat(info.apply("email was: " + value.get(0)), (String) value.get(0), endsWith("@corp.co"));
187148
// ID
188-
assertThat(value.get(1), is(i + 1));
149+
assertThat(info.apply("id"), value.get(1), is(i + 1));
189150
}
190151

191-
assertThat((int) clusters.get("total"), is(2));
192-
assertThat((int) clusters.get("successful"), is(1));
193-
assertThat((int) clusters.get("running"), is(0));
194-
assertThat((int) clusters.get("skipped"), is(1));
195-
assertThat((int) clusters.get("partial"), is(0));
196-
assertThat((int) clusters.get("failed"), is(0));
152+
assertThat(info.apply("total clusters"), (int) clusters.get("total"), is(2));
153+
assertThat(info.apply("successful clusters"), (int) clusters.get("successful"), is(1));
154+
assertThat(info.apply("running clusters"), (int) clusters.get("running"), is(0));
155+
assertThat(info.apply("skipped clusters"), (int) clusters.get("skipped"), is(1));
156+
assertThat(info.apply("partial clusters"), (int) clusters.get("partial"), is(0));
157+
assertThat(info.apply("failed clusters"), (int) clusters.get("failed"), is(0));
197158

198-
assertThat(clusterDetails.size(), is(2));
199-
assertThat((int) localClusterDetails.get("took"), greaterThan(0));
200-
assertThat(localClusterDetails.get("status"), is("successful"));
159+
assertThat(info.apply("cluster details size"), clusterDetails.size(), is(2));
160+
assertThat(info.apply("local cluster took"), (int) localClusterDetails.get("took"), greaterThan(0));
161+
assertThat(info.apply("local cluster status"), localClusterDetails.get("status"), is("successful"));
201162

202-
assertThat((int) remoteClusterDetails.get("took"), greaterThan(0));
203-
assertThat(remoteClusterDetails.get("status"), is("skipped"));
163+
assertThat(info.apply("remote cluster took"), (int) remoteClusterDetails.get("took"), greaterThan(0));
164+
assertThat(info.apply("remote cluster status"), remoteClusterDetails.get("status"), is("skipped"));
204165

205166
ArrayList<?> remoteClusterFailures = (ArrayList<?>) remoteClusterDetails.get("failures");
206-
assertThat(remoteClusterFailures.size(), equalTo(1));
167+
assertThat(info.apply("remote cluster failure count"), remoteClusterFailures.size(), equalTo(1));
207168
Map<String, ?> failuresMap = (Map<String, ?>) remoteClusterFailures.get(0);
208169

209170
Map<String, ?> reason = (Map<String, ?>) failuresMap.get("reason");
210171
assertThat(
172+
info.apply("unexpected failure reason: " + reason),
211173
reason.get("type").toString(),
212174
oneOf("node_disconnected_exception", "connect_transport_exception", "node_not_connected_exception")
213175
);
@@ -227,6 +189,7 @@ private void esqlEnrichWithSkipUnavailableFalse() throws Exception {
227189
String query = "FROM to-be-enr*,my_remote_cluster:to-be-enr* | ENRICH " + randomFrom(modes) + ":employees-policy | LIMIT 10";
228190
ResponseException ex = expectThrows(ResponseException.class, () -> performRequestWithRemoteSearchUser(esqlRequest(query)));
229191
assertThat(
192+
"esqlEnrichWithSkipUnavailableFalse failure",
230193
ex.getMessage(),
231194
anyOf(
232195
containsString("connect_transport_exception"),

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,9 @@ public void testCrossClusterQueryWithOnlyRemotePrivs() throws Exception {
740740

741741
@SuppressWarnings("unchecked")
742742
public void testCrossClusterEnrich() throws Exception {
743-
configureRemoteCluster();
743+
boolean isProxyMode = randomBoolean();
744+
boolean skipUnavailable = randomBoolean();
745+
configureRemoteCluster(REMOTE_CLUSTER_ALIAS, fulfillingCluster, false, isProxyMode, skipUnavailable);
744746
populateData();
745747
// Query cluster
746748
{

0 commit comments

Comments
 (0)