feat: add rate-channel breaker config and health_aware default

Threshold auto-raise now uses per-source concurrency only (the M2
global-concurrency formula neutered the breaker at scale). Four new
optional keys: MIN_CALLS, FAIL_RATE, WINDOW_S, MAX_COOLDOWN_S.
This commit is contained in:
2026-07-21 08:49:36 -04:00
parent 8e2673487a
commit 72b25724d8
3 changed files with 83 additions and 10 deletions
+14 -1
View File
@@ -152,15 +152,28 @@ class RetryPolicy:
@dataclass(frozen=True)
class BreakerConfig:
"""熔断配置;probe_ttl_s 是半开探针租约时长(持有者死亡后自动回收)。"""
"""熔断配置;probe_ttl_s 是半开探针租约时长(持有者死亡后自动回收)。
M2.5 双通道: fail_threshold 是连续失败通道;min_calls/fail_rate/window_s
是失败率通道(窗口样本 ≥ min_calls 且失败率 ≥ fail_rate 即开路,429 不入);
开路时长按重开次数指数递增,封顶 max_cooldown_s(设计 2026-07-21-m25)。
"""
fail_threshold: int
cooldown_s: float
probe_ttl_s: float
min_calls: int = 10
fail_rate: float = 0.6
window_s: float = 60.0
max_cooldown_s: float = 300.0
def __post_init__(self) -> None:
if self.fail_threshold < 1 or self.cooldown_s <= 0 or self.probe_ttl_s <= 0:
raise ValueError("熔断配置要求 fail_threshold ≥ 1 且 cooldown_s/probe_ttl_s > 0")
if self.min_calls < 1 or not (0.0 < self.fail_rate <= 1.0) or self.window_s <= 0:
raise ValueError("失败率通道要求 min_calls ≥ 1、0 < fail_rate ≤ 1、window_s > 0")
if self.max_cooldown_s < self.cooldown_s:
raise ValueError("max_cooldown_s 不得小于 cooldown_s(退避封顶低于初值)")
@dataclass(frozen=True)