Skip to content

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

Merged
abhishekagarwal87 merged 5 commits into
apache:masterfrom
oo007:master
Nov 22, 2023
Merged

Returning correct Response Code HTTP 429 when taskQueue reached maxSize#15409
abhishekagarwal87 merged 5 commits into
apache:masterfrom
oo007:master

Conversation

@oo007

@oo007 oo007 commented Nov 21, 2023

Copy link
Copy Markdown
Contributor

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.

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1

@oo007 oo007 Nov 21, 2023

Copy link
Copy Markdown
Contributor Author

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

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

Copy link
Copy Markdown
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
Copy Markdown
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

stateManager.recordThrowableEvent(e);
log.error("Tried to add task [%s] but it already exists", indexTask.getId());
}
catch (DruidException e) {

Copy link
Copy Markdown
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.


@Test
public void testDefault() throws EntryExistsException
public void testDefault() throws EntryExistsException, DruidException

Copy link
Copy Markdown
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
@abhishekagarwal87

Copy link
Copy Markdown
Contributor

Thank you @oo007 for your first contribution.

@shiv4289

shiv4289 commented Nov 22, 2023

Copy link
Copy Markdown

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
riovic918data pushed a commit to riovic918data/druid that referenced this pull request Jun 12, 2026
…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.
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