Skip to content

Commit 01b7ccd

Browse files
authored
ESQL: Reenable test (elastic#110305)
We have a security test that fails one every thousand or so runs because it runs an async esql action and *sometimes* it requests the async result and the index does not yet exist. This retries. I think there's probably a better solution, but for now I'm going to fix the test and open an issue to track that. Closes elastic#109806
1 parent 7c2b852 commit 01b7ccd

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ tests:
4747
- class: "org.elasticsearch.xpack.test.rest.XPackRestIT"
4848
issue: "https://github.com/elastic/elasticsearch/issues/109687"
4949
method: "test {p0=sql/translate/Translate SQL}"
50-
- class: "org.elasticsearch.xpack.esql.EsqlAsyncSecurityIT"
51-
issue: "https://github.com/elastic/elasticsearch/issues/109806"
52-
method: "testInsufficientPrivilege"
5350
- class: org.elasticsearch.action.search.SearchProgressActionListenerIT
5451
method: testSearchProgressWithHits
5552
issue: https://github.com/elastic/elasticsearch/issues/109830

x-pack/plugin/esql/qa/security/src/javaRestTest/java/org/elasticsearch/xpack/esql/EsqlAsyncSecurityIT.java

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
package org.elasticsearch.xpack.esql;
99

10+
import org.apache.http.util.EntityUtils;
1011
import org.elasticsearch.client.Request;
1112
import org.elasticsearch.client.RequestOptions;
1213
import org.elasticsearch.client.Response;
@@ -36,7 +37,8 @@ protected Response runESQLCommand(String user, String command) throws IOExceptio
3637
var respMap = entityAsMap(response.getEntity());
3738
String id = (String) respMap.get("id");
3839
assertThat((boolean) respMap.get("is_running"), either(is(true)).or(is(false)));
39-
var getResponse = runAsyncGet(user, id);
40+
int tries = 0;
41+
Response getResponse = runAsyncGet(user, id);
4042
assertOK(getResponse);
4143
var deleteResponse = runAsyncDelete(user, id);
4244
assertOK(deleteResponse);
@@ -98,26 +100,53 @@ private Response runAsync(String user, String command) throws IOException {
98100
Request request = new Request("POST", "_query/async");
99101
request.setJsonEntity(Strings.toString(json));
100102
request.setOptions(RequestOptions.DEFAULT.toBuilder().addHeader("es-security-runas-user", user));
103+
request.addParameter("error_trace", "true");
101104
logRequest(request);
102105
Response response = client().performRequest(request);
103106
logResponse(response);
104107
return response;
105108
}
106109

107110
private Response runAsyncGet(String user, String id) throws IOException {
108-
Request getRequest = new Request("GET", "_query/async/" + id + "?wait_for_completion_timeout=60s");
109-
getRequest.setOptions(RequestOptions.DEFAULT.toBuilder().addHeader("es-security-runas-user", user));
110-
logRequest(getRequest);
111-
var response = client().performRequest(getRequest);
112-
logResponse(response);
113-
return response;
111+
int tries = 0;
112+
while (tries < 10) {
113+
// Sometimes we get 404s fetching the task status.
114+
try {
115+
Request getRequest = new Request("GET", "_query/async/" + id + "?wait_for_completion_timeout=60s");
116+
getRequest.setOptions(RequestOptions.DEFAULT.toBuilder().addHeader("es-security-runas-user", user));
117+
getRequest.addParameter("error_trace", "true");
118+
logRequest(getRequest);
119+
var response = client().performRequest(getRequest);
120+
logResponse(response);
121+
return response;
122+
} catch (ResponseException e) {
123+
if (e.getResponse().getStatusLine().getStatusCode() == 404
124+
&& EntityUtils.toString(e.getResponse().getEntity()).contains("no such index [.async-search]")) {
125+
/*
126+
* Work around https://github.com/elastic/elasticsearch/issues/110304 - the .async-search
127+
* index may not exist when we try the fetch, but it should exist on next attempt.
128+
*/
129+
logger.warn("async-search index does not exist", e);
130+
try {
131+
Thread.sleep(1000);
132+
} catch (InterruptedException ex) {
133+
throw new RuntimeException(ex);
134+
}
135+
} else {
136+
throw e;
137+
}
138+
tries++;
139+
}
140+
}
141+
throw new IllegalStateException("couldn't find task status");
114142
}
115143

116144
private Response runAsyncDelete(String user, String id) throws IOException {
117-
Request getRequest = new Request("DELETE", "_query/async/" + id);
118-
getRequest.setOptions(RequestOptions.DEFAULT.toBuilder().addHeader("es-security-runas-user", user));
119-
logRequest(getRequest);
120-
var response = client().performRequest(getRequest);
145+
Request deleteRequest = new Request("DELETE", "_query/async/" + id);
146+
deleteRequest.setOptions(RequestOptions.DEFAULT.toBuilder().addHeader("es-security-runas-user", user));
147+
deleteRequest.addParameter("error_trace", "true");
148+
logRequest(deleteRequest);
149+
var response = client().performRequest(deleteRequest);
121150
logResponse(response);
122151
return response;
123152
}

x-pack/plugin/esql/qa/security/src/javaRestTest/java/org/elasticsearch/xpack/esql/EsqlSecurityIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public void testInsufficientPrivilege() {
142142
Exception.class,
143143
() -> runESQLCommand("metadata1_read2", "FROM index-user1,index-user2 | STATS sum=sum(value)")
144144
);
145+
logger.info("error", error);
145146
assertThat(
146147
error.getMessage(),
147148
containsString(

0 commit comments

Comments
 (0)