fix: keep the postgres backfill from disabling telemetry or locking the table

This commit is contained in:
2026-07-31 10:42:55 -04:00
parent 32d7869043
commit 86fb4d5536
5 changed files with 126 additions and 18 deletions
+4 -3
View File
@@ -47,6 +47,8 @@ class PricingTable:
def __init__(self, prices: Mapping[str, ModelPrice]) -> None:
self._prices = dict(prices)
self._warned: set[str] = set()
# 独立集合: 与"未知 model"的告警去重键分开,避免 model 名恰好撞上时互相抑制
self._warned_clamp: set[str] = set()
@classmethod
def from_file(cls, path: Path | str) -> PricingTable:
@@ -111,9 +113,8 @@ class PricingTable:
"""命中数按输入总数夹取: 网关口径异常不得算出负成本(每 model 只警告一次)。"""
if cached <= prompt_tokens:
return cached
key = f"{model}:cached_over_prompt"
if key not in self._warned:
self._warned.add(key)
if model not in self._warned_clamp:
self._warned_clamp.add(model)
logger.warning(
"model {!r} 上报的缓存命中 {} 超过输入总数 {},按总数夹取计价",
model,