Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returning correct Response Code HTTP 429 when taskQueue reached maxSize #15409

Merged
merged 5 commits into from Nov 22, 2023

Conversation

oo007
Copy link
Contributor

@oo007 oo007 commented Nov 21, 2023

Fixes #15380

Description

Currently when we submit a task to druid and number of currently active tasks has already reached (druid.indexer.queue.maxSize) then 500 ISE is thrown as per shown in the screenshot in #15380.

This fix will return HTTP 429 Too Many Requests(with proper error message) instead of 500 ISE, when we submit a task and queueSize has reached.

Tested and attached the screenshot
Screenshot 2023-11-21 at 12 37 34 PM

Release note

Returning correct Response Code HTTP 429 when taskQueue reached maxSize

Key changed/added classes in this PR
  • TooManyTasksException
  • TaskQueue
  • OverlordResource
  • SeekableStreamSupervisor
  • TaskQueueTest
  • KinesisSupervisorTest
  • TaskLockConfigTest
  • SeekableStreamSupervisorStateTest

This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • a release note entry in the PR description.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added or updated version, license, or notice information in licenses.yaml
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • added integration tests.
  • been tested in a test Druid cluster.

@@ -520,7 +521,10 @@ public boolean add(final Task task) throws EntryExistsException
try {
Preconditions.checkState(active, "Queue is not active!");
Preconditions.checkNotNull(task, "task");
Preconditions.checkState(tasks.size() < config.getMaxSize(), "Too many tasks (max = %s)", config.getMaxSize());
if (tasks.size() >= config.getMaxSize()) {
throw new TooManyTasksException(StringUtils.format("Too many tasks (maxQueueSize = %d), " +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of TooManyTasksException, you can create a failure type similar to Forbidden. This failure type can be called TooManyRequests. The failure will have an error code set to 429.

In here, you can create DruidException.fromFailure(TooManyRequests).forPersona(Operator).message()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "dropping" is misleading. We are not dropping anything, just rejecting the extra task. So lets just say that and please add to "retry later or increase the limit" in the error message.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once you get rid of TooManyException class, the PR will also have less changes IMO

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Contributor Author

@oo007 oo007 Nov 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added all review changes suggested.

  1. Removed TooManyTasksException
  2. added DruidException with status code 429
  3. modified the error msg as well

Tested and attached screenshot.
Screenshot 2023-11-21 at 5 05 10 PM

@@ -3735,7 +3736,7 @@ public void testGetCurrentTotalStats()

@Test
public void testDoNotKillCompatibleTasks()
throws InterruptedException, EntryExistsException
throws InterruptedException, EntryExistsException, DruidException
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am curious as to why you declared DruidException here. It's a runtime exception.

Comment on lines 229 to 232
catch (DruidException e) {
return Response.status(e.getResponseCode())
.entity(ImmutableMap.of("error", e.getMessage()))
.build();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still need to retain this, unfortunately. The other DruidException could be caught here as well. You can remove the other deprecated DruidException in a follow-up clean up PR

@@ -3954,6 +3954,10 @@ private void createTasksForGroup(int groupId, int replicas)
stateManager.recordThrowableEvent(e);
log.error("Tried to add task [%s] but it already exists", indexTask.getId());
}
catch (DruidException e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets not catch this exception here as we were not doing it before too.

@@ -51,7 +52,7 @@ public void setup()
}

@Test
public void testDefault() throws EntryExistsException
public void testDefault() throws EntryExistsException, DruidException
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these changes are not needed.

@abhishekagarwal87 abhishekagarwal87 merged commit 2f269fe into apache:master Nov 22, 2023
83 checks passed
@abhishekagarwal87
Copy link
Contributor

Thank you @oo007 for your first contribution.

@shiv4289
Copy link

shiv4289 commented Nov 22, 2023

That was fast. Thank you for all the support @abhishekagarwal87 . Much appreciated :-)

yashdeep97 pushed a commit to yashdeep97/druid that referenced this pull request Dec 1, 2023
…ize (apache#15409)

Currently when we submit a task to druid and number of currently active tasks has already reached (druid.indexer.queue.maxSize) then 500 ISE is thrown as per shown in the screenshot in apache#15380.

This fix will return HTTP 429 Too Many Requests(with proper error message) instead of 500 ISE, when we submit a task and queueSize has reached.
@LakshSingla LakshSingla added this to the 29.0.0 milestone Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Overlord return 500 Internal Server Error when queue.maxSize is reached
5 participants