API: Tripper¶
이 페이지는 사용 가능한 Tripper를 문서화합니다. Tripper는 window의 Metric을 평가하여 회로가 상태를 변경해야 하는지 결정하는 역할을 합니다.
Tripper 선택 및 조합에 대한 개요는 Tripper 컴포넌트 가이드를 참조하십시오.
fluxgate.trippers.CallContext
dataclass
¶
CallContext(
*,
metric: Metric,
state: State,
consecutive_failures: int,
)
Snapshot passed to trippers on each evaluation.
Carries the window-derived :class:Metric together with the breaker's
immediate state and consecutive failure count.
fluxgate.trippers.Closed
¶
Bases: Tripper
Tripper that returns true only when circuit is in CLOSED state.
Used to compose conditions that should only apply when circuit is closed.
Examples:
>>> # Only check failure rate when circuit is closed
>>> tripper = Closed() & FailureRate(0.5)
__call__
¶
__call__(ctx: CallContext) -> bool
Source code in fluxgate/trippers.py
93 94 | |
fluxgate.trippers.HalfOpened
¶
Bases: Tripper
Tripper that returns true only when circuit is in HALF_OPEN state.
Used to compose conditions that should only apply when circuit is half-open.
Examples:
>>> # Only check failure rate when circuit is half-open
>>> tripper = HalfOpened() & FailureRate(0.3)
__call__
¶
__call__(ctx: CallContext) -> bool
Source code in fluxgate/trippers.py
107 108 | |
fluxgate.trippers.MinRequests
¶
MinRequests(count: int)
Bases: Tripper
Tripper that requires minimum number of calls before evaluating.
Prevents premature circuit opening when sample size is too small.
Examples:
>>> # Only trip after at least 10 calls
>>> tripper = MinRequests(10) & FailureRate(0.5)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
count
|
int
|
Minimum number of calls required |
required |
Source code in fluxgate/trippers.py
124 125 126 127 | |
__call__
¶
__call__(ctx: CallContext) -> bool
Source code in fluxgate/trippers.py
129 130 | |
fluxgate.trippers.FailureRate
¶
FailureRate(ratio: float)
Bases: Tripper
Tripper based on failure rate threshold.
Returns true when the ratio of failed calls exceeds the threshold.
Examples:
>>> # Trip when 50% or more calls fail
>>> tripper = FailureRate(0.5)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ratio
|
float
|
Failure rate threshold (0.0 to 1.0) |
required |
Source code in fluxgate/trippers.py
146 147 148 149 | |
__call__
¶
__call__(ctx: CallContext) -> bool
Source code in fluxgate/trippers.py
151 152 153 154 155 | |
fluxgate.trippers.AvgLatency
¶
AvgLatency(threshold: float)
Bases: Tripper
Tripper based on average latency threshold.
Returns true when average call duration reaches or exceeds the threshold.
Examples:
>>> # Trip when average latency reaches 2 seconds
>>> tripper = AvgLatency(2.0)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
threshold
|
float
|
Latency threshold in seconds |
required |
Source code in fluxgate/trippers.py
171 172 173 174 | |
__call__
¶
__call__(ctx: CallContext) -> bool
Source code in fluxgate/trippers.py
176 177 178 179 180 | |
fluxgate.trippers.SlowRate
¶
SlowRate(ratio: float, *, threshold: float)
Bases: Tripper
Tripper based on slow call rate against a duration threshold.
A call is "slow" when its duration is at least threshold seconds.
The tripper fires when the ratio of slow calls in the current window
reaches ratio. Several SlowRate instances with different
thresholds can coexist in the same tripper tree — the circuit breaker
walks the tree and registers each threshold with the window.
Examples:
>>> # Trip when 30% of calls take 1s or longer.
>>> tripper = SlowRate(0.3, threshold=1.0)
>>>
>>> # Combine layered thresholds for tiered alerts.
>>> tripper = SlowRate(0.3, threshold=1.0) | SlowRate(0.05, threshold=10.0)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ratio
|
float
|
Slow call rate threshold (0.0 to 1.0) |
required |
threshold
|
float
|
Duration in seconds at or above which a call counts as slow |
required |
Source code in fluxgate/trippers.py
204 205 206 207 208 209 210 | |
__call__
¶
__call__(ctx: CallContext) -> bool
Source code in fluxgate/trippers.py
212 213 214 215 216 | |
fluxgate.trippers.FailureStreak
¶
FailureStreak(count: int)
Bases: Tripper
Tripper based on consecutive failure count.
Returns true when the number of consecutive failures reaches the threshold. Useful for fast failure detection during cold start or when external service is completely down.
Examples:
>>> # Trip after 5 consecutive failures
>>> tripper = FailureStreak(5)
>>>
>>> # Combine with other trippers for comprehensive protection
>>> tripper = FailureStreak(5) | (MinRequests(20) & FailureRate(0.5))
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
count
|
int
|
Number of consecutive failures required to trip |
required |
Source code in fluxgate/trippers.py
237 238 239 240 | |
__call__
¶
__call__(ctx: CallContext) -> bool
Source code in fluxgate/trippers.py
242 243 | |