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:
parent
d007dfd7dc
commit
4aa0a4cc2a
1 changed files with 16 additions and 4 deletions
|
|
@ -1826,6 +1826,19 @@ pkgs.testers.runNixOSTest {
|
|||
body, _, code = out.rpartition("\n")
|
||||
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]:
|
||||
"""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}'")
|
||||
|
|
@ -1950,8 +1963,7 @@ pkgs.testers.runNixOSTest {
|
|||
status, body = grafana_request("/metrics", f'--user "swarm-store:$(cat {GRAFANA_PASSWORD})"', gateway=False)
|
||||
assert status == 200 and "grafana_" in body, (status, body[:200])
|
||||
# Through the gateway the same request needs no credential of the caller's.
|
||||
status, body = grafana_request("/metrics")
|
||||
assert status == 200 and "grafana_" in body, (status, body[:200])
|
||||
wait_gateway_metrics()
|
||||
# A gateway without the credential gets 401 from the pod.
|
||||
saved = machine.succeed(f"cat {GRAFANA_CONF}")
|
||||
assert "proxy_set_header Authorization" in saved
|
||||
|
|
@ -1966,8 +1978,8 @@ pkgs.testers.runNixOSTest {
|
|||
machine.succeed("systemctl restart swarm-bao-store-auth.service")
|
||||
store_credential_published()
|
||||
machine.succeed("systemctl reload logs-gateway")
|
||||
assert machine.succeed(f"cat {GRAFANA_CONF}") == saved
|
||||
assert grafana_request("/metrics")[0] == 200
|
||||
assert machine.succeed(f"cat {GRAFANA_CONF}") == saved, "the unit wrote another include file than the first run did"
|
||||
wait_gateway_metrics()
|
||||
# The health route and the health check of the kubelet stay open.
|
||||
assert grafana_request("/api/health", gateway=False)[0] == 200
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue