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

Make the slot as the SPI interface and add a @Order annotation for define slot order #411

Merged
merged 8 commits into from
Mar 26, 2020

Conversation

cdfive
Copy link
Collaborator

@cdfive cdfive commented Jan 12, 2019

Describe what this PR does / why we need it

Make it easier to add custorm slot and arrange its order for users.

Does this pull request fix one issue?

Fixes #316

Describe how you did it

1.Add a @Order annotation and define the order of default slots from -9000 to -1000
NodeSelectorSlot: -9000
ClusterBuilderSlot: -8000
LogSlot: -7000
StatisticSlot: -6000
ParamFlowSlot: -5000
SystemSlot: -4000
AuthoritySlot: -3000
FlowSlot: -2000
DegradeSlot: -1000

2.Add a loadOrderedInstanceList(Class<T>) method in SpiLoader,
to Load the ordered instance list by SPI

3.Modify the DefaultSlotChainBuilder
new XxxSlot changed to using SpiLoader.loadOrderedInstanceList(ProcessorSlot.class);

Describe how to verify it

Add unit test

Special notes for reviews

Please review its feasibility in this way,
if it is okay, maybe the InitOrder can also use Order annotation instead, for similar logic,
the InitOrder and InitExecutor didn't modified at present.

@codecov-io
Copy link

codecov-io commented Jan 12, 2019

Codecov Report

Merging #411 into master will increase coverage by 0.28%.
The diff coverage is 64.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #411      +/-   ##
============================================
+ Coverage     43.24%   43.52%   +0.28%     
- Complexity     1579     1676      +97     
============================================
  Files           338      364      +26     
  Lines          9905    10492     +587     
  Branches       1337     1409      +72     
============================================
+ Hits           4283     4567     +284     
- Misses         5093     5365     +272     
- Partials        529      560      +31     
Impacted Files Coverage Δ Complexity Δ
...l/adapter/gateway/common/slot/GatewayFlowSlot.java 0.00% <ø> (ø) 0.00 <0.00> (ø)
...r/gateway/common/slot/GatewaySlotChainBuilder.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
.../sentinel/slots/block/authority/AuthoritySlot.java 88.23% <ø> (ø) 7.00 <0.00> (ø)
.../csp/sentinel/slots/block/degrade/DegradeSlot.java 100.00% <ø> (ø) 3.00 <0.00> (ø)
...libaba/csp/sentinel/slots/block/flow/FlowSlot.java 100.00% <ø> (ø) 5.00 <0.00> (ø)
...tinel/slots/clusterbuilder/ClusterBuilderSlot.java 71.42% <ø> (ø) 8.00 <0.00> (ø)
...com/alibaba/csp/sentinel/slots/logger/LogSlot.java 73.33% <ø> (ø) 3.00 <0.00> (ø)
.../sentinel/slots/nodeselector/NodeSelectorSlot.java 94.73% <ø> (ø) 4.00 <0.00> (ø)
...ba/csp/sentinel/slots/statistic/StatisticSlot.java 67.18% <ø> (ø) 13.00 <0.00> (ø)
.../alibaba/csp/sentinel/slots/system/SystemSlot.java 100.00% <ø> (ø) 3.00 <0.00> (ø)
... and 60 more

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 c507155...68be55c. Read the comment docs.

@sczyh30 sczyh30 added the to-review To review label Jan 13, 2019
@sczyh30 sczyh30 added the size/L Indicate a PR that changes 100-499 lines. label Mar 4, 2019
@cdfive
Copy link
Collaborator Author

cdfive commented Apr 20, 2019

@sczyh30 Hi,
synchronize from master branch, I find @SpiOrder, so I use that instead of previous @Order.

Use SpiLoader.loadInstanceListSorted(Class<T> clazz) to get the sorted SPI instance list.

Since the ProcessorSlot need to create new instance in each DefaultSlotChainBuilder,
, so I modified the method, not use the SERVICE_LOADER_MAP but call ServiceLoader.load(clazz) directly, in order to get new instance each call.

Maybe the cached SERVICE_LOADER_MAP can be removed, I'm not sure about that.

Another concern is the performance of sort, if call the method frequently.
How about caching the sort of same SPI class?

@sczyh30
Copy link
Member

sczyh30 commented Jun 5, 2019

Could you please fix the conflict?

@cdfive
Copy link
Collaborator Author

cdfive commented Jun 9, 2019

Sorry for late, the conflicts has fixed.

@sczyh30
Copy link
Member

sczyh30 commented Jan 19, 2020

@cdfive Could you please resolve the conflict?

@cdfive
Copy link
Collaborator Author

cdfive commented Jan 20, 2020

@cdfive Could you please resolve the conflict?
I'll do it these days.

@cdfive cdfive force-pushed the enhancement/slot-order branch 4 times, most recently from 60a4e7e to 7029867 Compare January 31, 2020 14:36
@cdfive
Copy link
Collaborator Author

cdfive commented Jan 31, 2020

@sczyh30 Sorry for late, The conflicts has been resolved.
I found that the ProcessorSlot(such as NodeSelectorSlot,ClusterBuilderSlot...) should create new instance in DefaultSlotChainBuilder, so add a method loadDifferentInstanceListSorted in SpiLoader class.

SpiLoaderTest#testLoadDifferentInstanceListSorted,DefaultSlotChainBuilderTest#testBuild
to verify it, please check.

@sczyh30
Copy link
Member

sczyh30 commented Feb 3, 2020

👍Great, I'll review the PR soon.

@CLAassistant
Copy link

CLA assistant check
All committers have signed the CLA.

@cdfive
Copy link
Collaborator Author

cdfive commented Mar 13, 2020

Now GatewaySlotChainBuilder,HotParamSlotChainBuilder are removed, DefaultSlotChainBuilder is the only implement class of SlotChainBuilder,
which can sovle #1306, since the SlotChainProvider#newSlotChain will use DefaultSlotChainBuilder.

All slots are marked with @SpiOrder, from -10000 to -1000:

slot @SpiOrder
NodeSelectorSlot -10000
ClusterBuilderSlot -9000
LogSlot -8000
StatisticSlot -7000
AuthoritySlot -6000
SystemSlot -5000
GatewayFlowSlot -4000
ParamFlowSlot -3000
FlowSlot -2000
DegradeSlot -1000

Test cases and comment has been improved, please take a review.

Is there any other suggestion? @sczyh30 @jasonjoo2010
Do we need to add the order values of Sentinel main slots into a Constant class, e.g. Constants?

like:

public static final String NODE_SELECTOR_SLOT_ORDER = -10000;
public static final String CLUSTER_BUILDER_SLOT_ORDER = NODE_SELECTOR_SLOT_ORDER + 1000;
...
public static final String SYSTEM_SLOT_ORDER = ...

and in extension GatewayFlowSlot:

@SpiOrder(Constants.SYSTEM_SLOT_ORDER + 1000)
public class GatewayFlowSlot {
}

Maybe it will be useful for user and developer to see the orders of slots more intuitively.

@jasonjoo2010
Copy link
Collaborator

I think maybe GatewaySlotChainBuilder and HotParamSlotChainBuilder should be preserved as legacy, declare them as deprecated, unlink their service declarations and rewrite them to inherit DefaultSlotChainBuilder to avoid that someone may reference or inherit them.

Thus we can allow users' customizations:

  • Implement new ProcessorSlot by extends AbstractProcessorSlot and define it in their own META-INF
  • Implement their own SlotChainBuilder and do all things in a different way (should be careful)

So provider of SlotChainBuilder maybe still need some adaption?

@cdfive
Copy link
Collaborator Author

cdfive commented Mar 18, 2020

GatewaySlotChainBuilder and HotParamSlotChainBuilder are reserved, marked as @Deprecated, the implement is not changed, and unlink their service declarations.
How about this? @jasonjoo2010 @sczyh30

*/
public class GatewaySlotChainBuilder implements SlotChainBuilder {
@Deprecated
public class GatewaySlotChainBuilder extends DefaultSlotChainBuilder {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh if you take my advice keeping an empty legacy one you should make it a real EMPTY one.
According to the new DefaultSlotChainBuilder i think there is no need keeping overriding of build() here, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm sorry for misunderstanding the point.It has been fixed, please check.

… just extends from DefaultSlotChainBuilder,improve comment
Copy link
Collaborator

@jasonjoo2010 jasonjoo2010 left a comment

Choose a reason for hiding this comment

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

Okay i have no further question now.

@sczyh30 It's suggested that you make a quick review.

@sczyh30
Copy link
Member

sczyh30 commented Mar 26, 2020

Okay i have no further question now.

@sczyh30 It's suggested that you make a quick review.

I'll take a look.

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. The name loadDifferentInstanceListSorted might be confusing, maybe we could improve it later :)

@sczyh30 sczyh30 added the kind/enhancement Category issues or prs related to enhancement. label Mar 26, 2020
@sczyh30 sczyh30 merged commit be4d058 into alibaba:master Mar 26, 2020
@sczyh30 sczyh30 removed the to-review To review label Mar 26, 2020
@sczyh30
Copy link
Member

sczyh30 commented Mar 26, 2020

Nice work. Thanks!

@sczyh30
Copy link
Member

sczyh30 commented Mar 26, 2020

@sczyh30
Copy link
Member

sczyh30 commented Mar 26, 2020

And we may need to improve the logs here because it will yield a large number of logs every time a new chain is built:

2020-03-26 16:21:14.948 INFO Add child </metric/queryTopResourceMetric.json> to node <sentinel_web_servlet_context>
2020-03-26 16:21:36.215 INFO [SpiLoader] Found {0} SPI: {1} with order -10000
2020-03-26 16:21:36.216 INFO [SpiLoader] Found {0} SPI: {1} with order -9000
2020-03-26 16:21:36.217 INFO [SpiLoader] Found {0} SPI: {1} with order -8000
2020-03-26 16:21:36.217 INFO [SpiLoader] Found {0} SPI: {1} with order -7000
2020-03-26 16:21:36.217 INFO [SpiLoader] Found {0} SPI: {1} with order -5000
2020-03-26 16:21:36.217 INFO [SpiLoader] Found {0} SPI: {1} with order -6000
2020-03-26 16:21:36.217 INFO [SpiLoader] Found {0} SPI: {1} with order -2000
2020-03-26 16:21:36.218 INFO [SpiLoader] Found {0} SPI: {1} with order -1000
2020-03-26 16:21:36.218 INFO [SpiLoader] Found {0} SPI: {1} with order -3000
2020-03-26 16:21:36.219 INFO [SpiLoader] Found {0} SPI: {1} with order -4000
2020-03-26 16:21:36.219 INFO Add child </resource/machineResource.json> to node <sentinel_web_servlet_context>
2020-03-26 16:21:38.956 INFO [SpiLoader] Found {0} SPI: {1} with order -10000
2020-03-26 16:21:38.956 INFO [SpiLoader] Found {0} SPI: {1} with order -9000
2020-03-26 16:21:38.956 INFO [SpiLoader] Found {0} SPI: {1} with order -8000
2020-03-26 16:21:38.957 INFO [SpiLoader] Found {0} SPI: {1} with order -7000
2020-03-26 16:21:38.957 INFO [SpiLoader] Found {0} SPI: {1} with order -5000
2020-03-26 16:21:38.957 INFO [SpiLoader] Found {0} SPI: {1} with order -6000
2020-03-26 16:21:38.957 INFO [SpiLoader] Found {0} SPI: {1} with order -2000
2020-03-26 16:21:38.957 INFO [SpiLoader] Found {0} SPI: {1} with order -1000
2020-03-26 16:21:38.958 INFO [SpiLoader] Found {0} SPI: {1} with order -3000
2020-03-26 16:21:38.958 INFO [SpiLoader] Found {0} SPI: {1} with order -4000

@cdfive
Copy link
Collaborator Author

cdfive commented Mar 26, 2020

Here we need to replace the old placeholder with "{}":
https://github.com/alibaba/Sentinel/blob/master/sentinel-core/src/main/java/com/alibaba/csp/sentinel/util/SpiLoader.java#L222

I'm sorry not merge master before commit. May I post new PR to fix it?

@cdfive
Copy link
Collaborator Author

cdfive commented Mar 26, 2020

LGTM. The name loadDifferentInstanceListSorted might be confusing, maybe we could improve it later :)

How about naming the method loadPrototypeInstanceListSorted? In @scope of Spring,
there are singleton and prototype for singleton or multiple instances.

And we may need to improve the logs here because it will yield a large number of logs every time a new chain is built:

Yes, since every new chain need create new slot instance, here is not suitable for too many logs.
How about using RecordLog.debug instead of RecordLog.info here? Now I couldn't thought out a better way,is there any suggestions? @sczyh30 @jasonjoo2010

@jasonjoo2010
Copy link
Collaborator

LGTM. The name loadDifferentInstanceListSorted might be confusing, maybe we could improve it later :)

How about naming the method loadPrototypeInstanceListSorted? In @scope of Spring,
there are singleton and prototype for singleton or multiple instances.

And we may need to improve the logs here because it will yield a large number of logs every time a new chain is built:

Yes, since every new chain need create new slot instance, here is not suitable for too many logs.
How about using RecordLog.debug instead of RecordLog.info here? Now I couldn't thought out a better way,is there any suggestions? @sczyh30 @jasonjoo2010

I think it can be in trace or debug level

@jasonjoo2010
Copy link
Collaborator

And coming to the logging please use placeholders {} instead of joining of strings

@jasonjoo2010
Copy link
Collaborator

And coming to the logging please use placeholders {} instead of joining of strings

... and i noticed you mentioned about new PR. Have you ever used rebase ? You can rebase your branch with an up to date master. It's suggested that making a backup before that. eg.

git checkout master
git pull github master     <<<<< make master branch up to date
git checkout slot-order   <<<<< backup it to another temporary branch first
git rebase master   <<<< maybe you should solve some conflicts

Where github is a remote name of alibaba/Sentinel

@cdfive
Copy link
Collaborator Author

cdfive commented Mar 27, 2020

@jasonjoo2010 Thanks for detailed guideline! Previously I just use rebase in local, push -f to my forked repository and then post a PR in the UI of github site. Now the previous PR has been merged, could use rebase master? I'm worry about the safey.

@jasonjoo2010
Copy link
Collaborator

@jasonjoo2010 Thanks for detailed guideline! Previously I just use rebase in local, push -f to my forked repository and then post a PR in the UI of github site. Now the previous PR has been merged, could use rebase master? I'm worry about the safey.

Yes rebase in your own repo. Is it dangerous? But it has been merged so the only thing you can do is to remove it :)

More polishings should lead to a new PR as you mentioned.

@cdfive
Copy link
Collaborator Author

cdfive commented Mar 27, 2020

Very clear! Got it, thanks! @jasonjoo2010

@sczyh30 sczyh30 linked an issue Apr 3, 2020 that may be closed by this pull request
linlinisme added a commit to linlinisme/Sentinel that referenced this pull request Nov 24, 2020
* calculate process cpu usage to support application running in container environment

* Enhance reliability and performance of InMemoryMetricsRepository (alibaba#1319)

* Fix InMemoryMetricsRepository can't keep the last five minutes metrics data problem and Improve read-write performance
* Use TimeUtil.currentTimeMillis() replace System.currentTimeMillis() for better performance

* dashboard: Support setting value pattern for client IP and host in gateway flow rule dialog (alibaba#1325)

* doc: Update JDK requirement of the dashboard in README.md (alibaba#1316)

* Following discussions in alibaba#1315

* Add "web-context-unify" config in Spring WebMVC adapter to support "chain" relation flow strategy (alibaba#1328)

* Fix the parsing issue in large post request for sentinel-transport-simple-http (alibaba#1255)

* Add gateway adapter for Zuul 2.x (alibaba#1138)

- also add demo for Zuul 2.x adapter

* Polish code and demo of Sentinel Zuul 2.x adapter

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* Polish code of transport command centers and heartbeat senders

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* Polish logging SPI related code and add general JUL adapter for Logger SPI (alibaba#1338)

* Move the legacy JUL methods from LogBase to BaseJulLogger.
* Add a JavaLoggingAdapter as the general JUL adapter for the Logger SPI, which makes it convenient to use (as the default logger).
* Add LoggerSpiProvider to resolve Logger SPI.
* Polish the logback demo.

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* Move CommandCenterLog to sentinel-transport-common and polish related code (alibaba#1341)

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* Polish placeholders in logging content to slf4j convention (alibaba#1342)

* Polish placeholders in logging content to "{}"

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* Fix timezone problem of sentinel-block.log

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* dashboard: Fix NoNodeException problem of FlowRuleZookeeperProvider example (alibaba#1352)

* Introduce logging extension: slf4j (alibaba#1344)

* Regroup packages related to logging into a separate module and polish document (alibaba#1355)

* Fix CI failure in JDK 11 environment (alibaba#1360)

* Supplement missing javax.annotation-api to sentinel-cluster-server-envoy-rls and sentinel-demo-zuul2-gateway
* Upgrade mockito-core to 2.28.2 (up to date)

* Fix the bug that context was not released when blocked in Spring Web adapter (alibaba#1353)

* Improve standard output message in LogBase (alibaba#1357)

* Complete the unit tests for sentinel-logging-slf4j module (alibaba#1358)

* refactor: Make the ProcessorSlot itself as SPI and deprecate legacy slot chain builder (alibaba#411)

* Make slots loaded by SPI, mark all slots with @SpiOrder from -10000 to -1000, improve comment
* Reserve gateway and param slot chain builder (just extends DefaultSlotChainBuilder) and mark them as @deprecated

* Force modifyRule command handler to fail if an incompatible old fastjson found (alibaba#1377)

* Note that this is only a temporary solution.

* Set default log level of JDK logging to INFO and polish code of SpiLoader (alibaba#1365)

* Improve log info in SpiLoader, improve comment and test case
* Use error level in catch block, init ArrayList with capacity and improve add item to list

* doc: Polish README.md of sentinel-cluster-server-envoy-rls module

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* dashboard: Hide advanced options in flow rule dialog when cluster mode is enabled (alibaba#1367)

* doc: Update README.md

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* Update fastjson to 1.2.68

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* Bump version to 1.7.2

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* Fix the bug of extracting request cookie in Spring Cloud Gateway adapter (alibaba#1400)

* Bump version to 1.8.0-SNAPSHOT

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* Add JAX-RS adapter (alibaba#1396)

* Fix the bug of misplaced locks in ContextUtil and ClusterNode (alibaba#1429)

- which may lead to IllegalMonitorStateException in unlock() when unchecked error occurs during lock()

* fix: Tracer does not trace exception to DefaultNode (alibaba#1068)

* Support setting project.name via the properties file and deprecate legacy config path (alibaba#1412)

* Update resolving logic of project name and polish SentinelConfig (alibaba#1437)

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* Refactor the mechanism of recording error in Entry and StatisticSlot

* Also polish related complete callbacks

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* Polish Tracer with entry.setError(ex) mechanism

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* dashboard: Remove duplicate code in MetricEntity (alibaba#1441)

* dashboard: Fix the bug that cookie may have conflict with web applications under the same domain (alibaba#1443)

* Improve deprecated ParameterMetric purge mechanism (alibaba#1372)

* Clear useless data in ParameterMetric for all removed rules

* Polish code comments of the fundamental Sph/SphO/SphU class

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* Add OkHttp integration (alibaba#1456)

* dashboard: Fix historical version compatibility problem for auth check via localStorage (alibaba#1473)

* Add exceptionPredicate in Tracer for customized exception filtering logic (alibaba#1496)

* test: Add test cases for Tuple2 (alibaba#1501)

Signed-off-by: yunfeiyanggzq <yunfeiyang@buaa.edu.cn>

* Add support for extracting param from complex object (alibaba#1491)

* This could enable specified parameter flow control for customized objects.

* Support setting class-level defaultFallback for annotation extension (alibaba#1493)

* Add unit test for logging/TokenBucket (alibaba#1504)

Signed-off-by: yunfeiyanggzq <yunfeiyang@buaa.edu.cn>

* Fix sentinel-apache-dubbo-adapter full GC bug (alibaba#1431)

* Polish RocketMQ PullConsumerDemo to make code clear (alibaba#1528)

* Add unit test for cluster/FlowResponseDataDecoder (alibaba#1514)

Signed-off-by: yunfeiyanggzq <yunfeiyang@buaa.edu.cn>

* Improve consumer filter of Dubbo 2.6.x and 2.7.x adapter (alibaba#1532)

* entry and exit with params in consumer filter

* Polish sentinel-opensource-eco-landscape-en.png

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* Add annotation extension for Java EE CDI (alibaba#1541)

* Add Sentinel annotation and JAX-RS plugins for Quarkus (alibaba#1542)

* Add sentinel-quarkus-adapter module, which provides sentinel-annotation-quarkus-adapter and sentinel-jax-rs-quarkus-adapter to adapt sentinel-annotation-cdi-interceptor and sentinel-jax-rs-adapter for Quarkus. It also provides sentinel-native-image-quarkus-adapter to support running Sentinel with Quarkus in native image mode.

* Polish document and code of Sentinel annotation CDI extension

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* Upgrade fastjson to 1.2.71 (alibaba#1545)

* Add file.encoding JVM args in maven-surefire-plugin to avoid charset problem (alibaba#1550)

* Add annotation CDI demo and Quarkus adapter demo (alibaba#1543)

* Polish document and rearrange package for Quarkus and JAX-RS adapter

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* Support customized origin parser in legacy Dubbo 2.6.x adapter (alibaba#1555)

* Add Eureka data-source extension (alibaba#1502)

* Upgrade nacos-client version to 1.3.0 in sentinel-datasource-nacos (alibaba#1576)

* demo: Update slot chain SPI demo (alibaba#1581)

Signed-off-by: yunfeiyanggzq <yunfeiyang@buaa.edu.cn>

* Add explicit null checking for charset in SimpleHttpClient#encodeRequestParams (alibaba#1589)

* Adapter: Support Apache HttpClient (alibaba#1455)

Introduce support through a customized client builder `SentinelApacheHttpClientBuilder`.

* doc: Fix mistakes in README.md of sentinel-zuul-adapter (alibaba#1593)

* Fix incorrect protocol description in FlowRequestData writer/decoder (alibaba#1607)

Signed-off-by: yunfeiyanggzq <yunfeiyang@buaa.edu.cn>

* Refactor config mechanism for OkHttp adapter and polish related code

- One config per interceptor instead of the global config
- Polish document and demo

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* test: Add unit test for sentinel-cluster-server and polish code (alibaba#1529)

Signed-off-by: yunfeiyanggzq <yunfeiyang@buaa.edu.cn>

* Refactor degrade hierarchy with new circuit breaker mechanism and improve strategy

* Add `CircuitBreaker` abstraction (with half-open state) and add circuit breaker state change event observer support.
* Improve circuit breaking strategy (avg RT → slow request ratio) and make statistics of each rule dependent (to support arbitrary statistic interval).
* Add simple "trial" mechanism (aka. half-open).
* Refactor mechanism of metric recording and state change handling for circuit breakers: record RT and error when requests have completed (i.e. `onExit`, based on alibaba#1420).

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* Update test cases for circuit breaking

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* Update demo for circuit breaking (DegradeRule)

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* test: Update test cases with new degrade mechanism in sentinel-demo-quarkus

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* Remove deprecated passCheck() in Rule and polish interface

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* Polish cluster flow control demo: add port in Nacos address (alibaba#1655)

Signed-off-by: yunfeiyanggzq <yunfeiyang@buaa.edu.cn>

* Polish boolean checking in test cases and dashboard (alibaba#1664)

* Remove unused code in TokenServerHandler#channelActive (alibaba#1667)

Signed-off-by: cj <power4j@outlook.com>

* Optimize the order of slots in ProcessorSlot SPI config (alibaba#1649)

* Fix the bug of circuit breaker half-open state transformation when request is blocked by upcoming rules (alibaba#1645)

* Refactor the workflow to fix the bug that circuit breaker may remain half-open state forever when the request is blocked by upcoming rules: revert the state change in exit handler (as a temporary workaround)
* Add exit handler in Entry as a per-invocation hook.

* Polish CircuitBreaker interface and update comments

- Only carry context in tryPass/onComplete method (this might be generic in upcoming versions)

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* Refactor exit handler mechanism of Entry

- Rename: whenComplete -> whenTerminate
- Execute the exit handler directly after the onExit hook of all slots

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* Add extended interface for metric extension hook to support distinguishing traffic type (alibaba#1665)

- Add EntryType args to all hook methods

* dashboard: Refactor degrade service/controller and adapt to new features

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* Polish Dubbo 2.6.x adapter and unify callback registry into DubboAdapterGlobalConfig (alibaba#1572)

* Unify Dubbo callback registry (for fallback and origin parser) into DubboAdapterGlobalConfig
* Polish default fallback implementation (wrap exception with RpcResult rather than directly throw it out)

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* Refactor extended MetricExtension interface (matching events in Sentinel)

- Unify the extended interface as a few event handlers: onPass, onBlocked, onComplete and onError
- Polish related code

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* Support customized origin parser in Apache Dubbo 2.7.x adapter and unify config (alibaba#1617)

* Support customized origin parser in Apache Dubbo 2.7.x adapter
* Unify Dubbo callback registry (for fallback and origin parser) into DubboAdapterGlobalConfig
* Polish default fallback implementation (wrap exception with RpcResult rather than directly throw it out)

* Polish code and README.md of sentinel-datasource-eureka

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* webmvc-adapter: improve to avoid ErrorEntryFreeException (alibaba#1533)

If entry already exists in request just skip creation.

* adapter: Add test cases for Spring WebFlux HandlerFunction (alibaba#1678)

* Add RuntimeException converting method in BlockException and polish logic for validation

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* Fix NPE bug and improve default fallback in Dubbo 2.7.x adapter

- Fix NPE bug in consumer filter (when non-biz error occurred)
- Improve default fallback in Dubbo 2.7.x adapter: convert the BlockException to a simple RuntimeException (with necessary message)
- Polish code and comments

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* Improve compatibility for dispatched servlet request in Spring Web adapter (alibaba#1681)

* Bump version to 1.8.0

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* Update README.md

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* Bump version to 1.8.1-SNAPSHOT

Signed-off-by: Eric Zhao <sczyh16@gmail.com>

* Fix typo in CircuitBreakingIntegrationTest (alibaba#1688)

Signed-off-by: yunfeiyanggzq <yunfeiyang@buaa.edu.cn>

* Pre-calculate intervalInSecond in LeapArray to reduce redundant calculation (alibaba#1700)

* doc: Fix typo in code comments (alibaba#1721)

* Solve the URI fetching bug in sentinel-zuul-adapter alibaba#1109 (alibaba#1605)

Use `getRequestURI` instead of `getServletPath` to get URI of current request(Both in prefix and regex matching).

* Fix NPE bug when updating gateway flow rules before the route/API has been requested once (alibaba#1729)

* Make NettyTransportClient.getCurrentId() thread safe (alibaba#1707)

Fix issue alibaba#1705.

- Use CAS to make it thread safe and limited in the declared range.

Signed-off-by: cj <power4j@outlook.com>

* Add attributes of cluster concurrency limiting in ClusterFlowConfig

Signed-off-by: yunfeiyanggzq <yunfeiyang@buaa.edu.cn>

* Add concurrency token request/release operation in TokenService

Signed-off-by: yunfeiyanggzq <yunfeiyang@buaa.edu.cn>

* Add basic cluster concurrency limiting impl in token server module

Signed-off-by: yunfeiyanggzq <yunfeiyang@buaa.edu.cn>

* Add unit tests for cluster concurrent limiting checker

Signed-off-by: yunfeiyanggzq <yunfeiyang@buaa.edu.cn>

* doc: Fix content in README.md of sentinel-dashboard (alibaba#1737)

* Fix the dependency conflict issue

* Optimize logging statements using placeholder (alibaba#1736)

* Optimize logging statements using placeholder to avoid unnecessary concatenation (issue alibaba#1735)

* Polish document and name of parameter (alibaba#1738)

- doc: Fix a typo in description of booting options for sentinel-dashboard
- Fix mismatched name of parameter to its comment for VersionUtils.parseVersion()

* Fix potential concurrency issue when updating flow rules (alibaba#1783)

* test: Fix overrunning test `FlowRuleManagerTest.testLoadAndGetRules` (alibaba#1823)

Signed-off-by: Jason Joo <hblzxsj@163.com>

* Improve default block fallback logic in Dubbo 2.6.x adapter to avoid serialization problem  (alibaba#1794)

- convert BlockException to a simple RuntimeException (with necessary message)

* Fix the problem that requests will never be blocked when slowRatioThreshold = 100% (alibaba#1779)

* CI: Polish dependencies for ARM64 and add ARM64 job to Travis CI (alibaba#1765)

1. Added ARM64 architecture in .travis.yml
2. Updated 'embedded-consul' version to 2.2.0, 'consul-api' version to 1.4.5 for ARM64 support.
3. Updated grpc.version for 'io.grpc:protoc-gen-grpc-java' to 1.30.2, for ARM64 support.

Signed-off-by: odidev <odidev@puresoftware.com>

* [feat alibaba#1839]: Make dashboard support deploying under subpath (alibaba#1851)

* dashboard: Add statIntervalMs field in DegradeRule dialog (alibaba#1781)

Co-authored-by: tianhao <tianhao@kuaishou.com>
Co-authored-by: jy2156121 <zry11@163.com>
Co-authored-by: Olof <olof.nord@tutanota.com>
Co-authored-by: cdfive <31885791+cdfive@users.noreply.github.com>
Co-authored-by: Jason Joo <hblzxsj@163.com>
Co-authored-by: tao.zhang <waves_Max@163.com>
Co-authored-by: Eric Zhao <sczyh16@gmail.com>
Co-authored-by: WongTheo <61610981+WongTheo@users.noreply.github.com>
Co-authored-by: 于玉桔 <zhaoyuguang@apache.org>
Co-authored-by: Zhiguo.Chen <chenzhiguo@live.com>
Co-authored-by: seasidesky <62706379+seasidesky@users.noreply.github.com>
Co-authored-by: haifeng <haifeng_yang@163.com>
Co-authored-by: johnli <joooohnli@gmail.com>
Co-authored-by: zhenxianyimeng <1920405993@qq.com>
Co-authored-by: pleasecheckhere2016 <707748808@qq.com>
Co-authored-by: ZhiQiang Gu <43897640+yunfeiyanggzq@users.noreply.github.com>
Co-authored-by: zechao zheng <15869103363@163.com>
Co-authored-by: yangy <root@jcod3r.com>
Co-authored-by: xiby <15555438336@163.com>
Co-authored-by: iron_city <55343460+DogBaoBao@users.noreply.github.com>
Co-authored-by: Bo <15528330581@163.com>
Co-authored-by: HupJ <576811031@qq.com>
Co-authored-by: Peine <peineliang@163.com>
Co-authored-by: cj <jclazz@outlook.com>
Co-authored-by: Bill Yip <yezaifei@163.com>
Co-authored-by: liqiangz <liqiang.zjhz@gmail.com>
Co-authored-by: mikawudi <mikawudi@qq.com>
Co-authored-by: dani3lWong <danielw0ng@foxmail.com>
Co-authored-by: cj <power4j@outlook.com>
Co-authored-by: yunfeiyanggzq <yunfeiyang@buaa.edu.cn>
Co-authored-by: Luke <gdjiegz@gmail.com>
Co-authored-by: HelloCoCooo <46306510+HelloCoCooo@users.noreply.github.com>
Co-authored-by: nickChenyx <nickChenyx@gmail.com>
Co-authored-by: Weihua <vip_wangweihua@163.com>
Co-authored-by: 王振广 <wzg923@126.com>
Co-authored-by: Lynx <65679911+xierunzi@users.noreply.github.com>
Co-authored-by: odidev <odidev@puresoftware.com>
Co-authored-by: Brent <xuande@inspur.com>
hughpearse pushed a commit to hughpearse/Sentinel that referenced this pull request Jun 2, 2021
…lot chain builder (alibaba#411)

* Make slots loaded by SPI, mark all slots with @SpiOrder from -10000 to -1000, improve comment
* Reserve gateway and param slot chain builder (just extends DefaultSlotChainBuilder) and mark them as @deprecated
CST11021 pushed a commit to CST11021/Sentinel that referenced this pull request Nov 3, 2021
… the store (alibaba#423)

* Fixed issue alibaba#411

* fix cast in getAllDelayOffset

* Update AdminBrokerProcessor.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Category issues or prs related to enhancement. size/L Indicate a PR that changes 100-499 lines.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Design of SlotChainBuilder Slot chain SPI should target slot itself rather than the entire builder
5 participants