-
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
Add ZooKeeper data source for Sentinel #33
Conversation
从alibaba/Sentinel更新
Codecov Report
@@ Coverage Diff @@
## master #33 +/- ##
============================================
- Coverage 46.54% 46.37% -0.17%
+ Complexity 544 541 -3
============================================
Files 105 105
Lines 3657 3657
Branches 519 519
============================================
- Hits 1702 1696 -6
- Misses 1751 1754 +3
- Partials 204 207 +3
Continue to review full report at Codecov.
|
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.
Thanks for contribution! Maybe using Curator is better? It's considered that Curator is better supported than zkclient.
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.
将zkclient替换为curator
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.
Good. Maybe a basic test case is required since Curator has a local test server for testing (curator-test module). Nacos integration does not have test cases because Nacos does not provide this kind of mechanism currently.
private CuratorFramework zkClient = null; | ||
private NodeCache nodeCache = null; | ||
|
||
public ZookeeperDataSource(final String serverAddr, final String groupId, final String dataId, |
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.
The groupId
and dataId
are concepts in Nacos. In ZooKeeper a path
is enough (should check to make sure it's started with /
).
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.
为了保持和nacos风格统一,groupId和dataId都不用以 / 开头,数据源里面会自动加。
String path = "/" + this.groupId + "/" + this.dataId;
Stat stat = this.zkClient.checkExists().forPath(path);
我感觉这里需要加一个只需传入 path 的构造函数: public ZookeeperDataSource(final String serverAddr, final String path, ConfigParser<String, T> parser) 然后 public ZookeeperDataSource(final String serverAddr, final String groupId, final String dataId, ConfigParser<String, T> parser) {
this(serverAddr, getPath(groupId, dataId), parser);
} 因为对 ZooKeeper 用户来说,没有 |
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
Describe what this PR does / why we need it
增加了zookeeper的数据源和测试demo
Resolves #29
Describe how you did it
参考nacos数据源,保持和nacos数据源风格一致,通过zkclient实现zookeeper的发布订阅功能,可以在规则变更的时候主动推送规则。
Describe how to verify it
sentinel-demo-zookeeper-datasource里面的ZookeeperDataSourceDemo是模拟微服务启动的时候注册数据源的场景,ZookeeperConfigSender是模拟Sentinel控制台在规则变更时,主动推送规则给微服务的场景。