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

Using circuitbreaker.Rule to define slowRequest/errorRatio/errorCount Rule #205

Merged
merged 4 commits into from
Aug 24, 2020

Conversation

louyuting
Copy link
Collaborator

@louyuting louyuting commented Aug 17, 2020

Describe what this PR does / why we need it

Currently, there are three rules to define circuit breaker rule: slowRequest/errorRatio/errorCount Rule.
The rule definition of circuit breaker rule is complex and there are also limitations to scalability.
So this PR will consolidate these circuit breaker rules to circuitbreaker.Rule.

Does this pull request fix one issue?

Describe how you did it

Describe how to verify it

Special notes for reviews

@codecov-commenter
Copy link

codecov-commenter commented Aug 17, 2020

Codecov Report

Merging #205 into master will decrease coverage by 1.60%.
The diff coverage is 60.43%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #205      +/-   ##
==========================================
- Coverage   44.02%   42.41%   -1.61%     
==========================================
  Files          81       82       +1     
  Lines        4534     4406     -128     
==========================================
- Hits         1996     1869     -127     
+ Misses       2298     2297       -1     
  Partials      240      240              
Impacted Files Coverage Δ
core/circuitbreaker/slot.go 0.00% <0.00%> (ø)
core/hotspot/rule.go 66.25% <ø> (ø)
core/circuitbreaker/rule_manager.go 48.95% <50.00%> (-1.88%) ⬇️
core/circuitbreaker/circuit_breaker.go 22.96% <64.28%> (ø)
core/circuitbreaker/rule.go 66.66% <71.42%> (-17.44%) ⬇️
ext/datasource/helper.go 57.65% <100.00%> (-9.25%) ⬇️
util/math.go 100.00% <100.00%> (ø)

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 d12f611...cf5fdca. Read the comment docs.

@louyuting louyuting marked this pull request as ready for review August 17, 2020 14:20
@louyuting louyuting force-pushed the 20200817-refactor-circuit-breaker branch from 1e54526 to 812eaf2 Compare August 17, 2020 14:21
@louyuting louyuting requested a review from sczyh30 August 17, 2020 14:21
@louyuting louyuting added area/circuit-breaking Issues or PRs related to circuit breaking kind/enhancement Category issues or PRs related to enhancement to-review PRs to review labels Aug 17, 2020
}

func (b *RuleBase) IsApplicable() error {
if len(b.Resource) == 0 {
func (r *Rule) isApplicable() error {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Export this function is user-friendly?
How do you think of it?

Copy link
Member

Choose a reason for hiding this comment

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

Since the rule itself is not an interface anymore, maybe we could make it an exported util checking function (like IsValidFlowRule in flow/rule_manager.go) instead of a member function?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

make sense

@louyuting louyuting force-pushed the 20200817-refactor-circuit-breaker branch from 812eaf2 to 53b6b93 Compare August 24, 2020 14:32
if r.Threshold < 0 {
return errors.New("invalid Threshold")
}
if r.Strategy == SlowRequestRatio && (r.Threshold < 0.0 || r.Threshold > 1.0) {
Copy link
Member

Choose a reason for hiding this comment

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

r.Threshold < 0.0 is not needed as it has been checked before.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated

if r.Strategy == SlowRequestRatio && (r.Threshold < 0.0 || r.Threshold > 1.0) {
return errors.New("invalid slow request ratio threshold (valid range: [0.0, 1.0])")
}
if r.Strategy == ErrorRatio && (r.Threshold < 0.0 || r.Threshold > 1.0) {
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated

if int(r.Strategy) < int(SlowRequestRatio) || int(r.Strategy) > int(ErrorCount) {
return errors.New("invalid Strategy")
}
if r.StatIntervalMs <= 0 {
Copy link
Member

Choose a reason for hiding this comment

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

retryTimeout should also be positive

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated

@louyuting louyuting linked an issue Aug 24, 2020 that may be closed by this pull request
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 461e21b into alibaba:master Aug 24, 2020
@sczyh30
Copy link
Member

sczyh30 commented Aug 24, 2020

Nice work. Thanks!

@sczyh30 sczyh30 removed the to-review PRs to review label Aug 24, 2020
@louyuting louyuting added this to the 0.6.0 milestone Aug 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/circuit-breaking Issues or PRs related to circuit breaking kind/enhancement Category issues or PRs related to enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve the default JSON rule parsers in ext/datasource package
3 participants