콘텐츠로 이동

API: Tripper

이 페이지는 사용 가능한 Tripper를 문서화합니다. Tripper는 window의 Metric을 평가하여 회로가 상태를 변경해야 하는지 결정하는 역할을 합니다.

Tripper 선택 및 조합에 대한 개요는 Tripper 컴포넌트 가이드를 참조하십시오.


fluxgate.trippers.Closed

Bases: TripperBase

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__(
    _metric: Metric,
    state: StateEnum,
    _consecutive_failures: int,
) -> bool
Source code in fluxgate/trippers.py
76
77
78
79
def __call__(
    self, _metric: Metric, state: StateEnum, _consecutive_failures: int
) -> bool:
    return state == StateEnum.CLOSED

fluxgate.trippers.HalfOpened

Bases: TripperBase

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__(
    _metric: Metric,
    state: StateEnum,
    _consecutive_failures: int,
) -> bool
Source code in fluxgate/trippers.py
92
93
94
95
def __call__(
    self, _metric: Metric, state: StateEnum, _consecutive_failures: int
) -> bool:
    return state == StateEnum.HALF_OPEN

fluxgate.trippers.MinRequests

MinRequests(count: int)

Bases: TripperBase

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
111
112
113
114
def __init__(self, count: int) -> None:
    if count <= 0:
        raise ValueError("Count must be greater than zero")
    self._count = count

__call__

__call__(
    metric: Metric,
    _state: StateEnum,
    _consecutive_failures: int,
) -> bool
Source code in fluxgate/trippers.py
116
117
118
119
def __call__(
    self, metric: Metric, _state: StateEnum, _consecutive_failures: int
) -> bool:
    return metric.total_count >= self._count

fluxgate.trippers.FailureRate

FailureRate(ratio: float)

Bases: TripperBase

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
135
136
137
138
def __init__(self, ratio: float) -> None:
    if ratio <= 0 or ratio > 1:
        raise ValueError("Ratio must be between 0 and 1")
    self._ratio = ratio

__call__

__call__(
    metric: Metric,
    _state: StateEnum,
    _consecutive_failures: int,
) -> bool
Source code in fluxgate/trippers.py
140
141
142
143
144
145
146
def __call__(
    self, metric: Metric, _state: StateEnum, _consecutive_failures: int
) -> bool:
    if metric.total_count == 0:
        return False
    failure_rate = metric.failure_count / metric.total_count
    return failure_rate >= self._ratio

fluxgate.trippers.AvgLatency

AvgLatency(threshold: float)

Bases: TripperBase

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
162
163
164
165
def __init__(self, threshold: float) -> None:
    if threshold <= 0:
        raise ValueError("Threshold must be greater than 0")
    self._threshold = threshold

__call__

__call__(
    metric: Metric,
    _state: StateEnum,
    _consecutive_failures: int,
) -> bool
Source code in fluxgate/trippers.py
167
168
169
170
171
172
173
def __call__(
    self, metric: Metric, _state: StateEnum, _consecutive_failures: int
) -> bool:
    if metric.total_count == 0:
        return False
    avg_duration = metric.total_duration / metric.total_count
    return avg_duration >= self._threshold

fluxgate.trippers.SlowRate

SlowRate(ratio: float)

Bases: TripperBase

Tripper based on slow call rate threshold.

Returns true when the ratio of slow calls exceeds the threshold. Slow calls are determined by the circuit breaker's slow_threshold.

Examples:

>>> # Trip when 30% or more calls are slow
>>> tripper = SlowRate(0.3)

Parameters:

Name Type Description Default
ratio float

Slow call rate threshold (0.0 to 1.0)

required
Source code in fluxgate/trippers.py
190
191
192
193
def __init__(self, ratio: float) -> None:
    if ratio <= 0 or ratio > 1:
        raise ValueError("Ratio must be between 0 and 1")
    self._ratio = ratio

__call__

__call__(
    metric: Metric,
    _state: StateEnum,
    _consecutive_failures: int,
) -> bool
Source code in fluxgate/trippers.py
195
196
197
198
199
200
201
def __call__(
    self, metric: Metric, _state: StateEnum, _consecutive_failures: int
) -> bool:
    if metric.total_count == 0:
        return False
    slow_rate = metric.slow_count / metric.total_count
    return slow_rate >= self._ratio