fix(governance): stabilize adr100 km growth slo
Some checks failed
Code Review / ai-code-review (push) Successful in 22s
Deploy Alert Rules / Deploy Prometheus Alert Rules (push) Successful in 25s
CD Pipeline / tests (push) Successful in 1m11s
CD Pipeline / post-deploy-checks (push) Has been cancelled
CD Pipeline / build-and-deploy (push) Has been cancelled

This commit is contained in:
Your Name
2026-05-14 19:33:52 +08:00
parent cdb8bf6802
commit d2a4a17969
9 changed files with 267 additions and 30 deletions

View File

@@ -654,6 +654,7 @@ class _FakePrometheusResponse:
class _FakePrometheusClient:
def __init__(self, value: str) -> None:
self._value = value
self.queries: list[str] = []
async def __aenter__(self):
return self
@@ -662,6 +663,7 @@ class _FakePrometheusClient:
return False
async def get(self, *args, **kwargs): # noqa: ANN002, ANN003
self.queries.append(str(kwargs.get("params", {}).get("query", "")))
return _FakePrometheusResponse(self._value)
@@ -683,3 +685,16 @@ class TestCheckSloCompliance:
assert result[name]["status"] == "skipped"
assert result[name]["reason"] == "prometheus_nan_or_inf"
assert result["_meta"]["status"] == "no_data"
@pytest.mark.asyncio
async def test_km_growth_prefers_db_derived_24h_gauge(self):
"""KM SLO 要優先使用 DB 24h gauge避免新 counter 暖機時誤報 0."""
agent = _make_agent()
client = _FakePrometheusClient("25")
with patch("httpx.AsyncClient", return_value=client):
result = await agent.check_slo_compliance()
assert "max(knowledge_entries_created_24h) or sli:km_growth_rate:24h" in client.queries
assert result["km_growth_rate"]["status"] == "ok"
assert result["km_growth_rate"]["value"] == 25