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

Add method level guard for servlet filter and Its test code #282

Merged
merged 4 commits into from
Dec 9, 2018

Conversation

ro9er
Copy link
Contributor

@ro9er ro9er commented Dec 3, 2018

Describe what this PR does / why we need it

This PR makes Sentinel Servlet Filter support Http method level flow control if necessary

Does this pull request fix one issue?

Fixes #247

Describe how you did it

The implementation steps are as follows:

  1. I add a initial parameter for CommonFilter named "IS_METHOD_SPECIFY" to trigger the http method level guard.
  2. In filter logic, the "IS_METHOD_SPECIFY" is true, it will try to get the entry whose name is "Method: target URL" after getting the entry of the origin URL. If success, it will continue the filter chain or it will return block message.

Describe how to verify it

This PR include the test code to verify it. The test code is in the package "com.alibaba.csp.sentinel.adapter.servletmethod"

Special notes for reviews

In addition, I submit test code for the method scenario
@CLAassistant
Copy link

CLAassistant commented Dec 3, 2018

CLA assistant check
All committers have signed the CLA.

@codecov-io
Copy link

codecov-io commented Dec 4, 2018

Codecov Report

Merging #282 into master will increase coverage by 0.1%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##             master     #282     +/-   ##
===========================================
+ Coverage     46.27%   46.37%   +0.1%     
- Complexity      927      929      +2     
===========================================
  Files           181      181             
  Lines          5746     5753      +7     
  Branches        830      832      +2     
===========================================
+ Hits           2659     2668      +9     
+ Misses         2751     2741     -10     
- Partials        336      344      +8
Impacted Files Coverage Δ Complexity Δ
...aba/csp/sentinel/adapter/servlet/CommonFilter.java 74.41% <100%> (+7.75%) 9 <5> (+3) ⬆️
...a/csp/sentinel/slots/statistic/base/LeapArray.java 62.85% <0%> (-2.86%) 18% <0%> (-1%)
...a/csp/sentinel/slots/statistic/base/LongAdder.java 31.91% <0%> (-2.13%) 10% <0%> (ø)
...a/com/alibaba/csp/sentinel/node/StatisticNode.java 65.57% <0%> (-1.64%) 21% <0%> (-1%)
...a/csp/sentinel/slots/statistic/base/Striped64.java 56.25% <0%> (+5.2%) 8% <0%> (+1%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ad1d9f0...61a1b42. Read the comment docs.

@sczyh30 sczyh30 added the to-review To review label Dec 4, 2018
Copy link
Member

@sczyh30 sczyh30 left a comment

Choose a reason for hiding this comment

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

LGTM

@sczyh30 sczyh30 merged commit 6802f97 into alibaba:master Dec 9, 2018
@sczyh30
Copy link
Member

sczyh30 commented Dec 9, 2018

Thanks for contributing!

@sczyh30 sczyh30 removed the to-review To review label Dec 9, 2018
@sczyh30 sczyh30 added this to the 1.4.0 milestone Dec 12, 2018
Arlmls pushed a commit to Arlmls/Sentinel that referenced this pull request Jan 8, 2019
…lter (alibaba#282)

- Add HTTP method level support for servlet filter with a init parameter `HTTP_METHOD_SPECIFY` as the switch. This is useful for REST APIs.
- Add test cases and fix test bug by reset the cluster node in ClusterBuilderSlot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

servlet common filter should distinguish HTTP method ,CommonFilter 限流应区分HTTP方法
4 participants