Skip to content

Commit

Permalink
[bug-fix] probeNum参数更新,loadRule生效
Browse files Browse the repository at this point in the history
[bug-fix] probeNum参数更新,loadRule生效
  • Loading branch information
binbin0325 authored Oct 10, 2024
2 parents 7100e5b + 566193d commit 64cf448
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
14 changes: 8 additions & 6 deletions core/circuitbreaker/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type Rule struct {
// that can trigger circuit breaking.
MinRequestAmount uint64 `json:"minRequestAmount"`
// StatIntervalMs represents statistic time interval of the internal circuit breaker (in ms).
// Currently the statistic interval is collected by sliding window.
// Currently, the statistic interval is collected by sliding window.
StatIntervalMs uint32 `json:"statIntervalMs"`
// StatSlidingWindowBucketCount represents the bucket count of statistic sliding window.
// The statistic will be more precise as the bucket count increases, but the memory cost increases too.
Expand All @@ -78,10 +78,10 @@ type Rule struct {
// for ErrorRatio, it represents the max error request ratio
// for ErrorCount, it represents the max error request count
Threshold float64 `json:"threshold"`
//ProbeNum is number of probes required when the circuit breaker is half-open.
//when the probe num are set and circuit breaker in the half-open state.
//if err occurs during the probe, the circuit breaker is opened immediately.
//otherwise,the circuit breaker is closed only after the number of probes is reached
// ProbeNum is number of probes required when the circuit breaker is half-open.
// when the probe num are set and circuit breaker in the half-open state.
// if err occurs during the probe, the circuit breaker is opened immediately.
// otherwise,the circuit breaker is closed only after the number of probes is reached
ProbeNum uint64 `json:"probeNum"`
}

Expand All @@ -103,12 +103,14 @@ func (r *Rule) ResourceName() string {
return r.Resource
}

// Check whether the fields shared by all rule strategy types are consistent
func (r *Rule) isEqualsToBase(newRule *Rule) bool {
if newRule == nil {
return false
}
return r.Resource == newRule.Resource && r.Strategy == newRule.Strategy && r.RetryTimeoutMs == newRule.RetryTimeoutMs &&
r.MinRequestAmount == newRule.MinRequestAmount && r.StatIntervalMs == newRule.StatIntervalMs && r.StatSlidingWindowBucketCount == newRule.StatSlidingWindowBucketCount
r.MinRequestAmount == newRule.MinRequestAmount && r.StatIntervalMs == newRule.StatIntervalMs && r.StatSlidingWindowBucketCount == newRule.StatSlidingWindowBucketCount &&
r.ProbeNum == newRule.ProbeNum
}

func (r *Rule) isEqualsTo(newRule *Rule) bool {
Expand Down
24 changes: 24 additions & 0 deletions core/circuitbreaker/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,30 @@ func TestRuleIsEqualsToBase(t *testing.T) {
},
expectedResult: false,
},
// different ProbeNum
{
rule1: &Rule{
Resource: "abc",
Strategy: ErrorCount,
RetryTimeoutMs: 3000,
MinRequestAmount: 10,
StatIntervalMs: 10000,
StatSlidingWindowBucketCount: 2,
Threshold: 1.0,
ProbeNum: 10,
},
rule2: &Rule{
Resource: "abc",
Strategy: ErrorCount,
RetryTimeoutMs: 3000,
MinRequestAmount: 10,
StatIntervalMs: 10000,
StatSlidingWindowBucketCount: 2,
Threshold: 1.0,
ProbeNum: 11,
},
expectedResult: false,
},
}

for i, c := range cases {
Expand Down
2 changes: 1 addition & 1 deletion core/hotspot/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type Rule struct {
// ControlBehavior only takes effect when MetricType is QPS
ControlBehavior ControlBehavior `json:"controlBehavior"`
// ParamIndex is the index in context arguments slice.
// if ParamIndex is great than or equals to zero, ParamIndex means the <ParamIndex>-th parameter
// if ParamIndex is greater than or equals to zero, ParamIndex means the <ParamIndex>-th parameter
// if ParamIndex is the negative, ParamIndex means the reversed <ParamIndex>-th parameter
ParamIndex int `json:"paramIndex"`
// ParamKey is the key in EntryContext.Input.Attachments map.
Expand Down

0 comments on commit 64cf448

Please sign in to comment.