Repository: alibaba/sentinel-golang
Pull request #583 (2024-10-04 14:52:37)

[bug-fix] probeNum参数更新，loadRule生效


<!--  Thanks for submitting a pull request! Here are some tips for you:
1. Please make sure you have read and understood the contributing guidelines: https://github.com/alibaba/blob/master/CONTRIBUTING.md
2. Please make sure the PR has a corresponding issue.
-->

### Describe what this PR does / why we need it
bug-fix

### Does this pull request fix one issue?
Fixes 
- https://github.com/alibaba/sentinel-golang/issues/563
- typo
<!--If that, add "Fixes #xxxx" below in the next line. For example, Fixes #15. Otherwise, add "NONE" -->

### Describe how you did it
add more fields for compare

### Describe how to verify it
add one  more test case

### Special notes for reviews

CLAassistant: [![CLA assistant check](https://cla-assistant.io/pull/badge/not_signed)](https://cla-assistant.io/alibaba/sentinel-golang?pullRequest=583) <br/>Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our [Contributor License Agreement](https://cla-assistant.io/alibaba/sentinel-golang?pullRequest=583) before we can accept your contribution.<br/><hr/>**caicai** seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please [add the email address used for this commit to your account](https://help.github.com/articles/why-are-my-commits-linked-to-the-wrong-user/#commits-are-not-linked-to-any-user).<br/><sub>You have signed the CLA already but the status is still pending? Let us [recheck](https://cla-assistant.io/check/alibaba/sentinel-golang?pullRequest=583) it.</sub>

Patch:
diff --git a/core/circuitbreaker/rule.go b/core/circuitbreaker/rule.go
index 0886604..ed3773e 100644
--- a/core/circuitbreaker/rule.go
+++ b/core/circuitbreaker/rule.go
@@ -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.
@@ -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"`
 }
 
@@ -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 {
diff --git a/core/hotspot/rule.go b/core/hotspot/rule.go
index 6785410..b46f5fd 100644
--- a/core/hotspot/rule.go
+++ b/core/hotspot/rule.go
@@ -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.


Test patch:
diff --git a/core/circuitbreaker/rule_test.go b/core/circuitbreaker/rule_test.go
index 604ed26..7f34b4e 100644
--- a/core/circuitbreaker/rule_test.go
+++ b/core/circuitbreaker/rule_test.go
@@ -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 {