-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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 rule persistence support and refactor dashboard for better scalability #1453
base: master
Are you sure you want to change the base?
Conversation
…zookeeper...)/service/web etc.
Codecov Report
@@ Coverage Diff @@
## master #1453 +/- ##
============================================
+ Coverage 43.96% 44.36% +0.39%
- Complexity 1719 1750 +31
============================================
Files 376 376
Lines 10660 10752 +92
Branches 1418 1426 +8
============================================
+ Hits 4687 4770 +83
- Misses 5408 5414 +6
- Partials 565 568 +3 Continue to review full report at Codecov.
|
请问 网关的现在实现了吗?是否是我的gateway服务加入了 |
你好。我在使用过的过程中,你描述的 五大规则的确可以。非常棒。但是现在我想同时在网关层(gateway)做流控,会抛出异常:CommandNotFoundException: /gateway/getApiDefinitions |
记得没有修改网关规则处理,理论上不影响使用,只是规则是存在内存里的。 网关规则的持久化暂时还没实现,因为跟其它规则有些不同,有API分组和网关流控规则,还不太确定之前的抽象能否满足,还有集群流控规则也还没实现,社区看看一起讨论设计下哈,如果项目中有使用问题请多反馈和讨论。 |
Could you please resolve conflicts? |
@sczyh30 Sorry for late. Merged from master and the conflicts have been resolved, please check. |
Codecov Report
@@ Coverage Diff @@
## master #1453 +/- ##
============================================
- Coverage 44.58% 44.36% -0.23%
+ Complexity 1804 1750 -54
============================================
Files 382 376 -6
Lines 10912 10752 -160
Branches 1467 1426 -41
============================================
- Hits 4865 4770 -95
+ Misses 5451 5414 -37
+ Partials 596 568 -28
Continue to review full report at Codecov.
|
ParamFlowRuleEntity 这个类中代码 |
确实写错了,该段代码在PR已注释掉没有使用,上面的 |
…e_enhancement # Conflicts: # pom.xml # sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/AbstractRule.java # sentinel-dashboard/pom.xml # sentinel-dashboard/sentinel-dashboard-entity/src/main/java/com/alibaba/csp/sentinel/dashboard/entity/discovery/AppManagement.java # sentinel-dashboard/sentinel-dashboard-web/src/main/java/com/alibaba/csp/sentinel/dashboard/web/auth/AuthorizationInterceptor.java # sentinel-dashboard/sentinel-dashboard-web/src/main/java/com/alibaba/csp/sentinel/dashboard/web/auth/DefaultAuthorizationInterceptor.java # sentinel-dashboard/sentinel-dashboard-web/src/main/java/com/alibaba/csp/sentinel/dashboard/web/auth/DefaultLoginAuthenticationFilter.java # sentinel-dashboard/sentinel-dashboard-web/src/main/java/com/alibaba/csp/sentinel/dashboard/web/auth/FakeAuthServiceImpl.java # sentinel-dashboard/sentinel-dashboard-web/src/main/java/com/alibaba/csp/sentinel/dashboard/web/auth/LoginAuthenticationFilter.java # sentinel-dashboard/sentinel-dashboard-web/src/main/java/com/alibaba/csp/sentinel/dashboard/web/config/AuthConfiguration.java # sentinel-dashboard/sentinel-dashboard-web/src/main/java/com/alibaba/csp/sentinel/dashboard/web/config/AuthProperties.java # sentinel-dashboard/sentinel-dashboard-web/src/main/java/com/alibaba/csp/sentinel/dashboard/web/controller/MachineRegistryController.java # sentinel-dashboard/sentinel-dashboard-web/src/main/resources/application.properties # sentinel-dashboard/sentinel-dashboard-web/src/main/webapp/resources/app/views/degrade.html # sentinel-dashboard/sentinel-dashboard-web/src/main/webapp/resources/app/views/system.html # sentinel-dashboard/sentinel-dashboard-web/src/test/java/com/alibaba/csp/sentinel/dashboard/web/config/NoAuthConfigurationTest.java # sentinel-dashboard/sentinel-dashboard-web/src/test/java/com/alibaba/csp/sentinel/dashboard/web/controller/gateway/GatewayApiControllerTest.java # sentinel-dashboard/sentinel-dashboard-web/src/test/java/com/alibaba/csp/sentinel/dashboard/web/controller/gateway/GatewayFlowRuleControllerTest.java # sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/AuthorityRuleController.java # sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/DegradeController.java # sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/FlowControllerV1.java # sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/ParamFlowRuleController.java # sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/SystemController.java # sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/ParamFlowRuleEntity.java # sentinel-dashboard/src/main/webapp/resources/dist/js/app.js # sentinel-transport/pom.xml
Master code has been merged and conflicts fixed, PTAL. @sczyh30 @jasonjoo2010 @linlinisme |
Also cc @LearningGp |
sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/AbstractRule.java
Outdated
Show resolved
Hide resolved
…r for getting and setting rule id
Describe what this PR does / why we need it
Sentinel dashboard provide web UI where we can setting rules, viewing machines, viewing monitoring, etc, it's very useful and convenient for user, especially new coming user.
By default, rules are stored in memory, and users may need to persist the rule by different own way.
But at present, dashboard is a single module, and user-defined modification can only be made on the source code of the whole project, which is not very convenient for continuous upgrade and keep up with the latest version.
Does this pull request fix one issue?
Fixes #1241, #1257
Related #1375, #1415
Describe how you did it
To make it simple to use, a configuration parameter and a properties file is used to support one type of repository.For example, using nacos,
Add VM paramteter
-Drule.repository.type=nacos
,Add a properties file
Nacos.properties
in the same folder path assentinel-dashboard.jar
, and in the properties file we can configure settings for Nacos.Considering independence and extensibility, I tried to layer the dashboard project into the following separate modules:
In
sentinel-dashboard-common
, common use class(config, util) , such asDashboardConfig
,VersionUtils
etc.In
sentinel-dashboard-entity
, all entities used by dashboard, include rule entity, machine/app entity, metric entity.In
sentinel-dashboard-repository
, based onDynamicRuleProvider
/DynamicRulePublisher
interface, abstract the common logic for persist rules with two abstract classAbstractRuleProvider
/AbstractRulePublisher
, methods are reserved for the realization by specific sub modules of different repository type.AtractRuleProvider#fetchRules
AbstractRulePublisher#publishRules
The
encoder
/decoder
package include serialization/deserialization for rules of different type, and the logic is for common use.The
RuleKeyBuilder
interface define methodString buildRuleKey(String app, String ip, Integer port);
for generate the persistent key of rule.For example, the flow rule, in Nacos:
If it's applied to one machine instance, the rule key is
appName-ip-port-flow-rules
, such assentinel-dashboard-192.168.1.100-8719-flow-rules
.If we set the rule which take application as dimension, that is all machine instances of this application apply the same rule, if have four instances, we'll persist four properties with four key in Nacos, the keys are:
app-ip1-port1-flow-rules
app-ip2-port2-flow-rules
app-ip3-port3-flow-rules
app-ip4-port4-flow-rules
Pay attention to that the
RuleKeyBuilder#buildRuleKey
method is a default implementation to generate ruleKey, which is alternative, and user can customize it in specific repository modules.In specific repository modules, such as
sentinel-dashboard-repository-nacos
,sentinel-dashboard-repository-redis
etc, the implementation is simple, we just need to focus on how to get and push rules with the specific repository. For example,NacosRuleProvider
/NacosRulePublisher
class extendsAbstractRuleProvider
/AbstractRulePublisher
class, and overridefetchRules
/publishRules
method.NacosProperties
is used for reading properties from file.Pay attention to that there are two files, the first file are in /resources/repository/nacos.properties, which is convenient for debug in IDE environment, and the second file nacos.properties is useful
when package the sentinel-dashboard.jar, and it has higher priority.
In
sentinel-dashboard-service
, define vo(req/resp), api and implementation of CRUD functions for rule of different type, the key logic is encapsulated inAbstractRuleService
class.In
sentinel-dashboard-web
, are web UI(page/javascript/css), http RESTFul controller, web config and filters, it will be better if we split it into complete front and back-end separation in the furture.Previous we have flow_v1,flow_v2, which may confuse new users, hope to support both set rules via machine or whole application, so the flow_v1,flow_v2 are merged into one file, in this way it's flexible and could meet most scenes.
Describe how to verify it
Package sentinel-dashboard.jar, test with different type of repository(Nacos,Redis,Zookeeper etc)
For Nacos repository:
1.Start Nacos server
2.Start dashboard with
-Drule.repository.type=nacos
Copy
nacos.properties
file fromsentinel-dashboard/src/main/resource/repository/nacos.properties
to the same folder path of `sentinel-dashboard.jarnacos.properties
:Note that if Nacos server is in the same machine as sentinel-dashboard.jar, and use default setting
, the
nacos.properties
can be omitted.Start dashboard
java -jar -Dproject.name=sentinel-dashboard -Dcsp.sentinel.dashboard.server=localhost:8080
-Drule.repository.type=nacos sentinel-dashboard.jar
3.Test with dashboard application itself, test CRUD functions for rules of different type in
dashboard app, and view the rules in Nacos web console.
4.Test with demo project, start
sentinel-demo-annotation-spring-aop
application with two different instances, test CRUD functions for rules of different type via application or single machine.Test in IDE environment
Run test cases
Special notes for reviews
Now persistence for five types of rules have been completed(flow/degrade/system/authority/paramFlow), persistence for the gateway rule and cluster have not implement yet.
With the design of
sentinel-dashboard-repository
andsentinel-dashboard-service
, I find it easy to implement specific repository exceptsentinel-dashboard-repository-memory
, since it needs to communicate with sentinel-transport http api. For simplicity, I addid/app/ip/port
fields inAbstractRule
, but this class is in core module. Is there any better way, please give some help.A new module
sentinel-transport-client
is added, in order to implementsentinel-dashboard-repository-memory
, I prefer put the client module in transport module. In this way, it is an independent module, and easy to use and expand.Pay attention to the
id
field ofRuleEntity
, previous version useAtomicLong ids
and increment one when adding a new rule. This may have some problems when dashboard restart and memory data lost. To solve this I addIdGenerator
interface andDefaultIdGenerator
class, to generate unique and self increasing id for a new rule.