Skip to content

Commit 61f3bc5

Browse files
committed
fix(metrics): publish failure metrics for SQL analytics engine path
The SQL analytics router in SQLPlugin handled errors by sending a raw BytesRestResponse without incrementing FAILED_REQ_COUNT_CUS or FAILED_REQ_COUNT_SYS, so SQL+AE failures were invisible in stats. Unlike the PPL path, the router owns the channel and never routes failures back to RestSqlAction's terminal error handler. Make RestSqlAction.handleException public static and call it from the analytics router onFailure callbacks so failure metrics and proper error formatting are applied consistently. The PPL+AE path already publishes metrics via RestPPLQueryAction's listener, so no change is needed there. Signed-off-by: Chen Dai <daichen@amazon.com>
1 parent ec433f4 commit 61f3bc5

2 files changed

Lines changed: 7 additions & 8 deletions

File tree

legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSqlAction.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,14 @@ private void delegateToV2Engine(
197197
handleException(restChannel, e);
198198
}
199199
},
200-
this::handleException)
200+
RestSqlAction::handleException)
201201
.accept(channel);
202202
} catch (Exception e) {
203203
handleException(channel, e);
204204
}
205205
}
206206

207-
private void handleException(RestChannel restChannel, Exception exception) {
207+
public static void handleException(RestChannel restChannel, Exception exception) {
208208
RestStatus status = getRestStatus(exception);
209209
logAndPublishMetrics(status, exception);
210210
reportError(restChannel, exception, status);
@@ -337,12 +337,13 @@ private static boolean isClientError(Exception e) {
337337
|| e instanceof ExpressionEvaluationException;
338338
}
339339

340-
private void sendResponse(
340+
private static void sendResponse(
341341
final RestChannel channel, final String message, final RestStatus status) {
342342
channel.sendResponse(new BytesRestResponse(status, message));
343343
}
344344

345-
private void reportError(final RestChannel channel, final Exception e, final RestStatus status) {
345+
private static void reportError(
346+
final RestChannel channel, final Exception e, final RestStatus status) {
346347
sendResponse(
347348
channel, ErrorMessageFactory.createErrorMessage(e, status.getStatus()).toString(), status);
348349
}

plugin/src/main/java/org/opensearch/sql/plugin/SQLPlugin.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,7 @@ protected Object buildJsonObject(ExplainResponse resp) {
263263

264264
@Override
265265
public void onFailure(Exception e) {
266-
channel.sendResponse(
267-
new BytesRestResponse(RestSqlAction.getRestStatus(e), e.getMessage()));
266+
RestSqlAction.handleException(channel, e);
268267
}
269268
});
270269
} else {
@@ -282,8 +281,7 @@ public void onResponse(TransportPPLQueryResponse response) {
282281

283282
@Override
284283
public void onFailure(Exception e) {
285-
channel.sendResponse(
286-
new BytesRestResponse(RestSqlAction.getRestStatus(e), e.getMessage()));
284+
RestSqlAction.handleException(channel, e);
287285
}
288286
});
289287
}

0 commit comments

Comments
 (0)