feat: add postgres telemetry recorder with two-tier degradation

This commit is contained in:
2026-07-21 00:50:33 -04:00
parent 0e22fcf433
commit abb65c2324
5 changed files with 359 additions and 12 deletions
+16
View File
@@ -130,6 +130,22 @@ class TestFactories:
with pytest.raises(ValueError, match="glm"):
GatewayClient.from_env("LLM", env=env)
def test_from_env_builds_redis_governance_backends(self):
"""M2: 配置取 redis 时装配出 Redis 后端(构造不连库,unit 可测)。"""
from polygateway.backends.redis.breaker import RedisGate
from polygateway.backends.redis.limiter import RedisLimiter
from polygateway.client import _build_breaker, _build_limiter
env = dict(
_ENV,
PGW_LIMITER_BACKEND="redis",
PGW_BREAKER_BACKEND="redis",
REDIS_URL="redis://:pw@10.0.0.1:6379/3",
)
settings = GatewaySettings.from_env("LLM", env=env)
assert isinstance(_build_limiter(settings, list(settings.sources)), RedisLimiter)
assert isinstance(_build_breaker(settings), RedisGate)
def test_from_settings_respects_injection(self):
settings = GatewaySettings.from_env("LLM", env=_ENV)
shared = InMemoryLimiter(
+5 -1
View File
@@ -266,5 +266,9 @@ def test_single_emitter_discipline():
text=True,
cwd=Path(__file__).resolve().parents[2],
).stdout.splitlines()
callers = [p for p in out if not p.endswith(("ports.py", "telemetry/sqlite.py"))]
callers = [
p
for p in out
if not p.endswith(("ports.py", "telemetry/sqlite.py", "telemetry/postgres.py"))
]
assert callers == ["src/polygateway/middleware/telemetry.py"]