-
Notifications
You must be signed in to change notification settings - Fork 3.8k
add configs to enable fast request failure on broker and historical #4540
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
391e615
add configs to enable fast request failure on broker
himanshug 7058495
address review comments
himanshug c501806
Merge remote-tracking branch 'druidio/master' into broker_rate_limit
himanshug 410bcb7
Merge remote-tracking branch 'druidio/master' into broker_rate_limit
himanshug 26e89db
fix styling error
himanshug 12ece52
fix style error
himanshug 7dedbd6
have enableRequestLimit config instead of having user specify max limit
himanshug f0509d0
add comment
himanshug ea6dbe9
fix style error
himanshug ff71391
add UT fo LimitRequestsFilter
himanshug 1d16220
address review comments
himanshug 57298e9
fix test
himanshug 43f4e8d
Merge remote-tracking branch 'druidio/master' into broker_rate_limit
himanshug c243607
make LimitRequestsFilterTest more robust
himanshug 2534586
fix JettyQosTest
himanshug File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
server/src/main/java/io/druid/server/initialization/jetty/LimitRequestsFilter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| /* | ||
| * Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. Metamarkets licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package io.druid.server.initialization.jetty; | ||
|
|
||
| import com.google.common.base.Preconditions; | ||
|
|
||
| import javax.servlet.Filter; | ||
| import javax.servlet.FilterChain; | ||
| import javax.servlet.FilterConfig; | ||
| import javax.servlet.ServletException; | ||
| import javax.servlet.ServletRequest; | ||
| import javax.servlet.ServletResponse; | ||
| import javax.servlet.http.HttpServletResponse; | ||
| import java.io.IOException; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
|
|
||
| /** | ||
| */ | ||
| public class LimitRequestsFilter implements Filter | ||
| { | ||
| private final int maxActiveRequests; | ||
|
|
||
| private final AtomicInteger activeRequestsCount = new AtomicInteger(); | ||
|
|
||
| public LimitRequestsFilter(int maxActiveRequests) | ||
| { | ||
| Preconditions.checkArgument( | ||
| maxActiveRequests > 0 && maxActiveRequests < Integer.MAX_VALUE, | ||
| "maxActiveRequests must be > 0 and < Integer.MAX_VALUE." | ||
| ); | ||
| this.maxActiveRequests = maxActiveRequests; | ||
| } | ||
|
|
||
| @Override | ||
| public void init(FilterConfig filterConfig) throws ServletException | ||
| { | ||
| } | ||
|
|
||
| @Override | ||
| public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | ||
| throws IOException, ServletException | ||
| { | ||
|
|
||
| int curr = activeRequestsCount.incrementAndGet(); | ||
| try { | ||
| if (curr <= maxActiveRequests) { | ||
| chain.doFilter(request, response); | ||
| } else { | ||
| // See https://tools.ietf.org/html/rfc6585 for status code 429 explanation. | ||
| ((HttpServletResponse) response).sendError(429, "Too Many Requests"); | ||
| } | ||
| } | ||
| finally { | ||
| activeRequestsCount.decrementAndGet(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void destroy() | ||
| { | ||
|
|
||
| } | ||
|
|
||
| public int getActiveRequestsCount() | ||
| { | ||
| return activeRequestsCount.get(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will swallow interrupted exceptions, is it needed to catch all exceptions here?
Also, is there a reason the ProvisionException wouldn't be able to just take a "caused by"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
at this point server startup would fail so it doesn't matter as we would do same for interrupted exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and, no ProvidsionException does not take caused by.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's special about
ProvisionException? Losing the actual stacktrace of an exception generally sucks (especially if this is going to kill the process start). Can we just wrap into aRuntimeExceptioninstead?[Himanshu] changed, that works too.