-
Notifications
You must be signed in to change notification settings - Fork 431
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
[feature] integrate datasource of OpenSergo by OpenSergo Go SDK #489
base: master
Are you sure you want to change the base?
Conversation
217aa0c
to
9990e57
Compare
9990e57
to
1dd4b2d
Compare
176b9ad
to
7bcc31e
Compare
f929da7
to
a347f50
Compare
6bd449c
to
3afd07c
Compare
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.
And please update with the latest Go SDK commit (with the new model).
@binbin0325 @louyuting @luckyxiaoqiang Any further suggestions? |
pkg/datasource/opensergo/opensergo_faulttolerance_rule_subscriber.go
Outdated
Show resolved
Hide resolved
pkg/datasource/opensergo/opensergo_flowrule_strategy_subscriber.go
Outdated
Show resolved
Hide resolved
We might need to discuss the model of the OpenSergo data-source soon (to make it clear). |
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.
- 数据源实现看一下是不是可以完全实现 Sentinel DataSource 接口,做到标准化;
- 去除目前数据源内部的增量变更逻辑,后续可以和 Sentinel Go 社区一起来看这个设计;
- 订阅/取消订阅相关的 API 遵循 Sentinel 的语义;
- 可以添加一下熔断规则的支持,看看目前的模型是否满足 多种规则转换,及多种 strategy 转到同种 Sentinel 规则的需要。
- update apply 时做好更新范围管理
…oDataSouce Signed-off-by: Jiangnan Jia <jnan0806@gmail.com>
Signed-off-by: Jiangnan Jia <jnan0806@gmail.com>
…fd77bd6ce Signed-off-by: Jiangnan Jia <jnan0806@gmail.com>
df4a242
to
f28ec80
Compare
cc @binbin0325 for update |
f28ec80
to
20320de
Compare
Signed-off-by: Jiangnan Jia <jnan0806@gmail.com>
20320de
to
1d99c71
Compare
Cloud you help me to check and complete the You can commit into the branch jnan806/sentinel-golang/fix#483-datasource-opensergo directly. |
func (ds *OpenSergoDataSource) ReadSource() ([]byte, error) { | ||
// assemble updated MixedRule | ||
mixedRule := new(MixedRule) | ||
if ds.opensergoRuleAggregator.mixedRuleCache.updateFlagMap[RuleType_FlowRule] { |
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.
感觉这个mixedRuleCache 可以去掉, 在doUpdate func 中接收更新的RuleType参数,在ReadSource根据更新的RuleType 参数设置到mixedRule即可。
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.
我是这么想的,mixedRule 就仅作为 rule 的一个集合,不带业务属性比较好。用另外的mixedRuleCache这个结构体来包含 更新标志,这样结构体的功能区分会更加清晰。
Signed-off-by: Jiangnan Jia <jnan0806@gmail.com>
// TODO fill field-mapping between sentinel-rule and pb-message | ||
flowRule.Threshold = float64(pbStrategy.Threshold) | ||
flowRule.TokenCalculateStrategy = flow.Direct | ||
flowRule.ControlBehavior = flow.Reject | ||
|
||
return flowRule |
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.
@binbin0325
Cloud you help me to check and complete the field-mapping
And then delete the // TODO
comment line.
You can commit into the branch jnan806/sentinel-golang/fix#483-datasource-opensergo directly.
I have already invite you into this repo.
// TODO fill field-mapping between sentinel-rule and pb-message | ||
flowRule.Threshold = float64(1000 / pbStrategy.MinIntervalMillisOfRequests) | ||
flowRule.TokenCalculateStrategy = flow.Direct | ||
flowRule.ControlBehavior = flow.Throttling | ||
flowRule.MaxQueueingTimeMs = uint32(pbStrategy.QueueTimeoutMillis) | ||
|
||
return flowRule |
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.
@binbin0325 the same as above
// TODO fill field-mapping between sentinel-rule and pb-message | ||
isolationRule.Threshold = uint32(pbStrategy.MaxConcurrency) | ||
isolationRule.MetricType = isolation.Concurrency | ||
|
||
return isolationRule |
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.
@binbin0325 the same as above
// TODO fill field-mapping between sentinel-rule and pb-message | ||
switch pbStrategy.Strategy { | ||
case faulttolerancePb.CircuitBreakerStrategy_STRATEGY_SLOW_REQUEST_RATIO: | ||
circuitbreakerRule.Threshold = float64(pbStrategy.SlowCondition.MaxAllowedRtMillis) | ||
break | ||
case faulttolerancePb.CircuitBreakerStrategy_STRATEGY_ERROR_REQUEST_RATIO: | ||
circuitbreakerRule.Threshold = pbStrategy.TriggerRatio | ||
break | ||
default: | ||
logging.Info("[OpenSergoDatasource] unknow CircuitBreakerStrategy.", "resourceName", circuitbreakerRule.Resource, "pbStrategy", pbStrategy) | ||
} | ||
circuitbreakerRule.MinRequestAmount = uint64(pbStrategy.MinRequestAmount) | ||
|
||
return circuitbreakerRule |
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.
@binbin0325 the same as above
logging.Info("[OpenSergoDatasource] un-subscribing OpenSergo ConcurrencyLimitStrategy.", "namespace", ds.namespace, "app", ds.app) | ||
} | ||
|
||
func (ds *OpenSergoDataSource) subscribeCircuitBreakerRule() { |
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.
These subscribe/unsubscribe methods for Sentinel rules should be public.
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.
And please pay attention to error handling. Do not ignore the error here.
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.
These subscribe/unsubscribe methods for Sentinel rules should be public.
i make it private because i have no idea about how to avoid re-invoking this functions.
The subscribe functions have been invoked in Initialize()
. If make them public , users would invoke twice, also unsubscribe twice will be invoked twice.
Does this pull request fix one issue?
fixed #483
Special notes for reviews
### Prepare Environment for Test Version- Prepare theOpenSergo GO SDK
.Because of the
OpenSergo GO SDK
has no published version, so should download the sourcecode ofOpenSergo GO SDK
jnan806/opensergo-go-sdk/tree/initial-version, and move it into youGOPATH
.- Rename the right version in directory name ofOpenSergo GO SDK
sourcecode.Make sure the version in sourcecode directory name is the same with go.mod.
eg.
$GOPATH/pkg/mod/github.com/opensergo/opensergo-go@v0.0.0-20220331070310-e5b01fee4d1c
The jnan806/opensergo-go-sdk/tree/initial-version has been merged into opensergo/opensergo-go-sdk.
So this step of
Prepare the
OpenSergo GO SDK` is unnecessary.It's only need to add use sentinel-go with the opensergo-datasource.
Samples