Watch
0
0
Fork
You've already forked hyperhive
0

wait for the gateway's reload before asking Grafana's /metrics

nginx's reload is graceful: workers on the old configuration answer until they
drain, so the request right after the credential unit's restart and the reload
could still meet the empty include file and answer 401. The subtest polls for
the 200 as the stores' subtests poll for their records.
This commit is contained in:
atlas 2026-11-28 05:55:57 +01:00
commit 4aa0a4cc2a

View file

@ -1826,6 +1826,19 @@ pkgs.testers.runNixOSTest {
body, _, code = out.rpartition("\n") body, _, code = out.rpartition("\n")
return int(code or 0), body return int(code or 0), body
def wait_gateway_metrics() -> None:
"""Waits for Grafana's `/metrics` through the gateway to answer with the
credential in place. A reload is graceful: workers on the old
configuration (an empty include file, a missing one) go on answering
until they drain, so a request right after it can still get the 401."""
deadline = time.monotonic() + 30
while True:
status, body = grafana_request("/metrics")
if status == 200 and "grafana_" in body:
return
assert time.monotonic() < deadline, ("the gateway does not send the credential", status, body[:200])
time.sleep(1)
def grafana_head(path: str, *args: str) -> tuple[str, str]: def grafana_head(path: str, *args: str) -> tuple[str, str]:
"""The status and the redirect target of one request through the gateway.""" """The status and the redirect target of one request through the gateway."""
out = machine.succeed(f"curl -sS --max-time 20 -o /dev/null -w '%{{http_code}} %{{redirect_url}}' {' '.join(args)} '{GRAFANA_GATEWAY}{path}'") out = machine.succeed(f"curl -sS --max-time 20 -o /dev/null -w '%{{http_code}} %{{redirect_url}}' {' '.join(args)} '{GRAFANA_GATEWAY}{path}'")
@ -1950,8 +1963,7 @@ pkgs.testers.runNixOSTest {
status, body = grafana_request("/metrics", f'--user "swarm-store:$(cat {GRAFANA_PASSWORD})"', gateway=False) status, body = grafana_request("/metrics", f'--user "swarm-store:$(cat {GRAFANA_PASSWORD})"', gateway=False)
assert status == 200 and "grafana_" in body, (status, body[:200]) assert status == 200 and "grafana_" in body, (status, body[:200])
# Through the gateway the same request needs no credential of the caller's. # Through the gateway the same request needs no credential of the caller's.
status, body = grafana_request("/metrics") wait_gateway_metrics()
assert status == 200 and "grafana_" in body, (status, body[:200])
# A gateway without the credential gets 401 from the pod. # A gateway without the credential gets 401 from the pod.
saved = machine.succeed(f"cat {GRAFANA_CONF}") saved = machine.succeed(f"cat {GRAFANA_CONF}")
assert "proxy_set_header Authorization" in saved assert "proxy_set_header Authorization" in saved
@ -1966,8 +1978,8 @@ pkgs.testers.runNixOSTest {
machine.succeed("systemctl restart swarm-bao-store-auth.service") machine.succeed("systemctl restart swarm-bao-store-auth.service")
store_credential_published() store_credential_published()
machine.succeed("systemctl reload logs-gateway") machine.succeed("systemctl reload logs-gateway")
assert machine.succeed(f"cat {GRAFANA_CONF}") == saved assert machine.succeed(f"cat {GRAFANA_CONF}") == saved, "the unit wrote another include file than the first run did"
assert grafana_request("/metrics")[0] == 200 wait_gateway_metrics()
# The health route and the health check of the kubelet stay open. # The health route and the health check of the kubelet stay open.
assert grafana_request("/api/health", gateway=False)[0] == 200 assert grafana_request("/api/health", gateway=False)[0] == 200