fix(e2e): exclude unknown routes from upstream counters

This commit is contained in:
Yuneng Jiang 2026-09-15 19:32:50 -07:00
parent 3dda798c8a
commit 9170183087
No known key found for this signature in database
2 changed files with 13 additions and 6 deletions

View file

@ -434,22 +434,28 @@ def test_enabled_environment_reuses_store_across_fresh_backends(
configured_cache.cache_clear()
def test_duplicate_headers_bypass_cache_and_count_live_calls(store: RedisResponseStore, provider: Provider) -> None:
@pytest.mark.parametrize("known_mount", (True, False))
def test_duplicate_headers_bypass_cache_and_count_live_calls(
store: RedisResponseStore, provider: Provider, known_mount: bool,
) -> None:
cache: Final = CacheEdge(store, SECRET)
with edge(cache, provider) as url:
parsed: Final = urlsplit(url)
for _ in range(2):
connection = HTTPConnection(str(parsed.hostname), parsed.port, timeout=5)
try:
connection.putrequest("POST", parsed.path)
connection.putrequest("POST", parsed.path if known_mount else "/unknown/v1/chat/completions")
connection.putheader("content-length", str(len(BODY)))
connection.putheader("content-type", "application/json")
connection.putheader("x-duplicate", "first")
connection.putheader("x-duplicate", "second")
connection.endheaders(BODY)
assert connection.getresponse().read() == SUCCESS
response = connection.getresponse()
assert response.status == (200 if known_mount else 404)
payload = response.read()
assert payload == SUCCESS if known_mount else b"unknown provider mount" in payload
finally:
connection.close()
assert len(provider.hits) == 2
assert len(provider.hits) == (2 if known_mount else 0)
assert dict(cache.counters.counts)["duplicate_header_bypass"] == 2
assert dict(cache.counters.counts)["upstream_attempts"] == 2
assert dict(cache.counters.counts).get("upstream_attempts", 0) == (2 if known_mount else 0)

View file

@ -891,7 +891,8 @@ class _EdgeHandler(BaseHTTPRequestHandler):
)
if isinstance(edge_server.backend, CacheEdge) and duplicate_headers:
edge_server.backend.counters.increment("duplicate_header_bypass")
edge_server.backend.counters.increment("upstream_attempts")
if urlsplit(self.path).path.lstrip("/").partition("/")[0] in edge_server.mounts:
edge_server.backend.counters.increment("upstream_attempts")
outcome: Final = handle_edge_request(
selected_backend,
edge_server.mounts,