Skip to content

Commit

Permalink
Return 429 for ConcurrencyLimitExceededException (#2428) (#2429)
Browse files Browse the repository at this point in the history
* Return 429 for ConcurrencyLimitExceededException



* add UT



---------


(cherry picked from commit 2c230be)

Signed-off-by: Peng Huo <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 4af150e commit d1ed772
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ private String fetchType() {
}

protected String fetchReason() {
if (status == RestStatus.TOO_MANY_REQUESTS.getStatus()) {
return "Too Many Requests";
}
return status == RestStatus.BAD_REQUEST.getStatus()
? "Invalid Request"
: "There was internal problem at backend";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.sql.datasources.exceptions;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Test;
import org.opensearch.core.rest.RestStatus;

class ErrorMessageTest {

@Test
void fetchReason() {
ErrorMessage errorMessage =
new ErrorMessage(new RuntimeException(), RestStatus.TOO_MANY_REQUESTS.getStatus());
assertEquals("Too Many Requests", errorMessage.getReason());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import static org.opensearch.core.rest.RestStatus.BAD_REQUEST;
import static org.opensearch.core.rest.RestStatus.SERVICE_UNAVAILABLE;
import static org.opensearch.core.rest.RestStatus.TOO_MANY_REQUESTS;
import static org.opensearch.rest.RestRequest.Method.DELETE;
import static org.opensearch.rest.RestRequest.Method.GET;
import static org.opensearch.rest.RestRequest.Method.POST;
Expand All @@ -29,6 +30,7 @@
import org.opensearch.sql.datasources.utils.Scheduler;
import org.opensearch.sql.legacy.metrics.MetricName;
import org.opensearch.sql.legacy.utils.MetricUtils;
import org.opensearch.sql.spark.leasemanager.ConcurrencyLimitExceededException;
import org.opensearch.sql.spark.rest.model.CreateAsyncQueryRequest;
import org.opensearch.sql.spark.transport.TransportCancelAsyncQueryRequestAction;
import org.opensearch.sql.spark.transport.TransportCreateAsyncQueryRequestAction;
Expand Down Expand Up @@ -175,6 +177,10 @@ private void handleException(
OpenSearchException exception = (OpenSearchException) e;
reportError(restChannel, exception, exception.status());
addCustomerErrorMetric(requestMethod);
} else if (e instanceof ConcurrencyLimitExceededException) {
LOG.error("Too many request", e);
reportError(restChannel, e, TOO_MANY_REQUESTS);
addCustomerErrorMetric(requestMethod);
} else {
LOG.error("Error happened during request handling", e);
if (isClientError(e)) {
Expand Down

0 comments on commit d1ed772

Please sign in to comment.