Skip to content

Commit c362aae

Browse files
committed
Update go docs of flow/isolation/system/circuitbreaker packages
Signed-off-by: Eric Zhao <[email protected]>
1 parent 2af8660 commit c362aae

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

core/circuitbreaker/doc.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
// Package circuitbreaker implements the circuit breaker.
16-
//
17-
// Sentinel circuit breaker module converts each Rule into a CircuitBreaker. Each CircuitBreaker has its own statistical structure.
15+
// Package circuitbreaker implements the circuit breaker pattern, which provides
16+
// stability and prevents cascading failures in distributed systems.
1817
//
1918
// Sentinel circuit breaker module supports three strategies:
2019
//
@@ -23,13 +22,15 @@
2322
// 2. ErrorRatio: the ratio of error entry exceeds the threshold. The following entry to resource will be broken.
2423
// 3. ErrorCount: the number of error entry exceeds the threshold. The following entry to resource will be broken.
2524
//
26-
// Sentinel circuit breaker is implemented based on state machines. There are three state:
25+
// Sentinel converts each circuit breaking Rule into a CircuitBreaker. Each CircuitBreaker has its own statistical structure.
26+
//
27+
// Sentinel circuit breaker is implemented based on state machines. There are three states:
2728
//
2829
// 1. Closed: all entries could pass checking.
2930
// 2. Open: the circuit breaker is broken, all entries are blocked. After retry timeout, circuit breaker switches state to Half-Open and allows one entry to probe whether the resource returns to its expected state.
3031
// 3. Half-Open: the circuit breaker is in a temporary state of probing, only one entry is allowed to access resource, others are blocked.
3132
//
32-
// Sentinel circuit breaker provides the listener to listen on the state changes.
33+
// Sentinel circuit breaker provides the listener to observe events of state changes.
3334
//
3435
// type StateChangeListener interface {
3536
// OnTransformToClosed(prev State, rule Rule)

core/flow/rule.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,12 @@ func (s TokenCalculateStrategy) String() string {
6363
}
6464
}
6565

66+
// ControlBehavior defines the behavior when requests have reached the capacity of the resource.
6667
type ControlBehavior int32
6768

6869
const (
6970
Reject ControlBehavior = iota
71+
// Throttling indicates that pending requests will be throttled, wait in queue (until free capacity is available)
7072
Throttling
7173
)
7274

core/isolation/rule.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
type MetricType int32
2424

2525
const (
26-
// Concurrency represents concurrency count.
26+
// Concurrency represents concurrency (in-flight requests).
2727
Concurrency MetricType = iota
2828
)
2929

@@ -36,11 +36,14 @@ func (s MetricType) String() string {
3636
}
3737
}
3838

39-
// Rule describes the concurrency num control, that is similar to semaphore
39+
// Rule describes the isolation policy (e.g. semaphore isolation).
4040
type Rule struct {
4141
// ID represents the unique ID of the rule (optional).
42-
ID string `json:"id,omitempty"`
43-
Resource string `json:"resource"`
42+
ID string `json:"id,omitempty"`
43+
// Resource represents the target resource definition.
44+
Resource string `json:"resource"`
45+
// MetricType indicates the metric type for checking logic.
46+
// Currently Concurrency is supported for concurrency limiting.
4447
MetricType MetricType `json:"metricType"`
4548
Threshold uint32 `json:"threshold"`
4649
}

core/system/rule.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ const (
2828
AvgRT
2929
// Concurrency represents the concurrency of all inbound requests.
3030
Concurrency
31+
// InboundQPS represents the QPS of all inbound requests.
3132
InboundQPS
33+
// CpuUsage represents the CPU usage percentage of the system.
3234
CpuUsage
35+
3336
// MetricTypeSize indicates the enum size of MetricType.
3437
MetricTypeSize
3538
)
@@ -55,7 +58,7 @@ type AdaptiveStrategy int32
5558

5659
const (
5760
NoAdaptive AdaptiveStrategy = -1
58-
// 1
61+
// BBR represents the adaptive strategy based on ideas of TCP BBR.
5962
BBR AdaptiveStrategy = iota
6063
)
6164

@@ -70,11 +73,17 @@ func (t AdaptiveStrategy) String() string {
7073
}
7174
}
7275

76+
// Rule describes the policy for system resiliency.
7377
type Rule struct {
74-
ID string `json:"id,omitempty"`
75-
MetricType MetricType `json:"metricType"`
76-
TriggerCount float64 `json:"triggerCount"`
77-
Strategy AdaptiveStrategy `json:"strategy"`
78+
// ID represents the unique ID of the rule (optional).
79+
ID string `json:"id,omitempty"`
80+
// MetricType indicates the type of the trigger metric.
81+
MetricType MetricType `json:"metricType"`
82+
// TriggerCount represents the lower bound trigger of the adaptive strategy.
83+
// Adaptive strategies will not be activated until target metric has reached the trigger count.
84+
TriggerCount float64 `json:"triggerCount"`
85+
// Strategy represents the adaptive strategy.
86+
Strategy AdaptiveStrategy `json:"strategy"`
7887
}
7988

8089
func (r *Rule) String() string {

0 commit comments

Comments
 (0)