Skip to content

Commit dc56dfe

Browse files
authored
Allow query pragmas in release builds (elastic#111953) (elastic#112168)
I have investigated an issue with QA clusters that run release builds. I wish I could enable query pragmas to confirm the problem instead of setting up new clusters and replicating data before testing the theory. This change allows users to enable query pragmas in release builds. However, due to the risks associated with using pragmas, the accept_pragma_risks parameter must be explicitly set to true to proceed.
1 parent 8848c7f commit dc56dfe

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public class EsqlQueryRequest extends org.elasticsearch.xpack.core.esql.action.E
5050
private TimeValue keepAlive = DEFAULT_KEEP_ALIVE;
5151
private boolean keepOnCompletion;
5252
private boolean onSnapshotBuild = Build.current().isSnapshot();
53+
private boolean acceptedPragmaRisks = false;
5354

5455
/**
5556
* "Tables" provided in the request for use with things like {@code LOOKUP}.
@@ -78,8 +79,9 @@ public ActionRequestValidationException validate() {
7879
if (Strings.hasText(query) == false) {
7980
validationException = addValidationError("[" + RequestXContent.QUERY_FIELD + "] is required", validationException);
8081
}
82+
8183
if (onSnapshotBuild == false) {
82-
if (pragmas.isEmpty() == false) {
84+
if (pragmas.isEmpty() == false && acceptedPragmaRisks == false) {
8385
validationException = addValidationError(
8486
"[" + RequestXContent.PRAGMA_FIELD + "] only allowed in snapshot builds",
8587
validationException
@@ -230,4 +232,8 @@ public Task createTask(long id, String type, String action, TaskId parentTaskId,
230232
void onSnapshotBuild(boolean onSnapshotBuild) {
231233
this.onSnapshotBuild = onSnapshotBuild;
232234
}
235+
236+
void acceptedPragmaRisks(boolean accepted) {
237+
this.acceptedPragmaRisks = accepted;
238+
}
233239
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ String fields() {
6969
private static final ParseField PARAMS_FIELD = new ParseField("params");
7070
private static final ParseField LOCALE_FIELD = new ParseField("locale");
7171
private static final ParseField PROFILE_FIELD = new ParseField("profile");
72+
private static final ParseField ACCEPT_PRAGMA_RISKS = new ParseField("accept_pragma_risks");
7273
static final ParseField TABLES_FIELD = new ParseField("tables");
7374

7475
static final ParseField WAIT_FOR_COMPLETION_TIMEOUT = new ParseField("wait_for_completion_timeout");
@@ -92,6 +93,7 @@ private static void objectParserCommon(ObjectParser<EsqlQueryRequest, ?> parser)
9293
parser.declareString(EsqlQueryRequest::query, QUERY_FIELD);
9394
parser.declareBoolean(EsqlQueryRequest::columnar, COLUMNAR_FIELD);
9495
parser.declareObject(EsqlQueryRequest::filter, (p, c) -> AbstractQueryBuilder.parseTopLevelQuery(p), FILTER_FIELD);
96+
parser.declareBoolean(EsqlQueryRequest::acceptedPragmaRisks, ACCEPT_PRAGMA_RISKS);
9597
parser.declareObject(
9698
EsqlQueryRequest::pragmas,
9799
(p, c) -> new QueryPragmas(Settings.builder().loadFromMap(p.map()).build()),

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/action/EsqlQueryRequestTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,9 @@ public void testPragmasOnlyValidOnSnapshot() throws IOException {
302302
request.onSnapshotBuild(false);
303303
assertNotNull(request.validate());
304304
assertThat(request.validate().getMessage(), containsString("[pragma] only allowed in snapshot builds"));
305+
306+
request.acceptedPragmaRisks(true);
307+
assertNull(request.validate());
305308
}
306309

307310
public void testTablesKeyword() throws IOException {

0 commit comments

Comments
 (0)