-
Notifications
You must be signed in to change notification settings - Fork 8k
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
Return status 429 in the default block handler #1112
Return status 429 in the default block handler #1112
Conversation
@@ -48,12 +48,14 @@ | |||
public static final String TOTAL_METRIC_FILE_COUNT = "csp.sentinel.metric.file.total.count"; | |||
public static final String COLD_FACTOR = "csp.sentinel.flow.cold.factor"; | |||
public static final String STATISTIC_MAX_RT = "csp.sentinel.statistic.max.rt"; | |||
public static final String BLOCK_PAGE_HTTP_STATUS = "csp.sentinel.web.servlet.block.page.http.status"; |
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.
Usually, we don't put the property key related to adapters and extensions to the SentinelConfig
in sentinel-core. We could put this to WebServletConfig
instead (like the former block page item). What do you think of it?
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.
That looks clearer, I had fix it, review code again, thanks~
* @return http status | ||
*/ | ||
public static int getBlockPageHttpStatus() { | ||
return Integer.parseInt(SentinelConfig.getConfig(BLOCK_PAGE_HTTP_STATUS)); |
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.
We need to handle the parsing error or empty value here. If an error occurs or the item is absent, then we could use the default 429.
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.
Make sense, thanks for guiding.
When csp.sentinel.web.servlet.block.page.http.status is empty or not number, the block page http status will be automatically set to 429(Too Many Requests).
Review code again, please~
Codecov Report
@@ Coverage Diff @@
## master #1112 +/- ##
============================================
- Coverage 42.91% 42.88% -0.03%
- Complexity 1502 1503 +1
============================================
Files 320 320
Lines 9400 9411 +11
Branches 1283 1284 +1
============================================
+ Hits 4034 4036 +2
- Misses 4870 4878 +8
- Partials 496 497 +1
Continue to review full report at Codecov.
|
…_in_the_default_block
@sczyh30 Please review again~ |
...-servlet/src/main/java/com/alibaba/csp/sentinel/adapter/servlet/config/WebServletConfig.java
Show resolved
Hide resolved
Friendly ping :) |
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.
LGTM
Thanks for contributing! |
…pter (alibaba#1112) * Return canonical status 429 in the default block handler of sentinel-web-servlet-adapter. * Add a `csp.sentinel.web.servlet.block.page.http.status` property to support customized block status configuration.
resolve #1110