Skip to content

Commit

Permalink
Fix query failed metric double count bug (#17454)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtuglu-netflix authored Nov 9, 2024
1 parent 0dcc2bc commit f906d0d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
38 changes: 21 additions & 17 deletions server/src/main/java/org/apache/druid/server/QueryResultPusher.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,24 +229,8 @@ private Response handleQueryException(ResultsWriter resultsWriter, QueryExceptio
return handleDruidException(resultsWriter, DruidException.fromFailure(new QueryExceptionCompat(e)));
}

private Response handleDruidException(ResultsWriter resultsWriter, DruidException e)
private void incrementQueryCounterForException(final DruidException e)
{
if (resultsWriter != null) {
resultsWriter.recordFailure(e);
counter.incrementFailed();

if (accumulator != null && accumulator.isInitialized()) {
// We already started sending a response when we got the error message. In this case we just give up
// and hope that the partial stream generates a meaningful failure message for our client. We could consider
// also throwing the exception body into the response to make it easier for the client to choke if it manages
// to parse a meaningful object out, but that's potentially an API change so we leave that as an exercise for
// the future.
trailerFields.put(QueryResource.ERROR_MESSAGE_TRAILER_HEADER, e.getMessage());
trailerFields.put(QueryResource.RESPONSE_COMPLETE_TRAILER_HEADER, "false");
return null;
}
}

switch (e.getCategory()) {
case INVALID_INPUT:
case UNAUTHORIZED:
Expand All @@ -264,6 +248,26 @@ private Response handleDruidException(ResultsWriter resultsWriter, DruidExceptio
counter.incrementTimedOut();
break;
}
}

private Response handleDruidException(ResultsWriter resultsWriter, DruidException e)
{
incrementQueryCounterForException(e);

if (resultsWriter != null) {
resultsWriter.recordFailure(e);

if (accumulator != null && accumulator.isInitialized()) {
// We already started sending a response when we got the error message. In this case we just give up
// and hope that the partial stream generates a meaningful failure message for our client. We could consider
// also throwing the exception body into the response to make it easier for the client to choke if it manages
// to parse a meaningful object out, but that's potentially an API change so we leave that as an exercise for
// the future.
trailerFields.put(QueryResource.ERROR_MESSAGE_TRAILER_HEADER, e.getMessage());
trailerFields.put(QueryResource.RESPONSE_COMPLETE_TRAILER_HEADER, "false");
return null;
}
}

if (response == null) {
final Response.ResponseBuilder bob = Response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,8 @@ public void testTooManyQuery() throws InterruptedException, ExecutionException
for (Future<Boolean> theFuture : back2) {
Assert.assertTrue(theFuture.get());
}
Assert.assertEquals(2, queryResource.getSuccessfulQueryCount());
Assert.assertEquals(1, queryResource.getFailedQueryCount());
}

@Test(timeout = 10_000L)
Expand Down

0 comments on commit f906d0d

Please sign in to comment.