Skip to content

fix(cli): cluster service reads retry a transient 503 - #5549

Merged
dan-petty merged 3 commits into
mainfrom
fix/5532-retry-cluster-service-reads
Nov 13, 2026
Merged

dan-petty merged 3 commits into
mainfrom
fix/5532-retry-cluster-service-reads

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

A cluster service that is not ready for some seconds, such as Prometheus after a node drain, ended a devops command with a traceback. The Prometheus client, the Loki metric queries of devops roadmap eval grades, the Grafana client and get_json now read with one policy, SERVICE_READ_RETRY, on the retries option of http_client. It sends a GET again after 429, 502, 503, 504 or a failed connect or read: at most 4 attempts, jittered backoff, Retry-After, no attempt after 20 s. Other methods, other 4xx and egress refusals are sent once. service_error maps the last failure to one ServiceRequestError line with the attempts, the time and a hint. A Prometheus 400 shows its error (Refs #5487).

reaches_service, the forward poll and the telemetry panel keep one attempt: each must report down fast. The apply health gate keeps its wait loop. A release is necessary.

Closes #5532

Change: openspec/changes/archive/2026-11-13-5532-cluster-service-reads-retry-a-transient/

A short outage of a cluster service ended a devops command with a
traceback. Prometheus answered 503 for some seconds after its pod
started again after a node drain, and `devops prometheus query`
stopped with `httpx2.HTTPStatusError` (#5532).

- The `retries` option of `http_client` also takes a
  `ReadRetryPolicy`. `SERVICE_READ_RETRY` sends a GET, HEAD or OPTIONS
  request again after 429, 502, 503, 504 or a failed connect or read:
  at most 4 attempts, jittered backoff that obeys Retry-After, and no
  attempt after 20 s. It sends no other method again, and it gives
  the last reply or error as one attempt does. The loop is
  tenacity.Retrying; the pydantic-ai transport costs 0.55 s of imports
  and closes the reply of a failed status.
- `service_error` maps the last failure to one `ServiceRequestError`
  line: the service, the status or the network error, the attempts,
  the time and a hint. A reply with an error text adds it, so a
  refused PromQL query shows the error of Prometheus (#5487).
- PrometheusClient, the Loki metric queries, GrafanaClient and
  get_json use the policy. The health gate and the rollout gate catch
  the mapped error; the health gate keeps its own wait loop.
- reaches_service, the forward poll and the dashboard telemetry panel
  keep one attempt, because each must report down fast.
- A pooled client keys on its retry option.
…e line

devops k8s service-url --fetch printed the address of the service two
times, because it put a prefix before the line of ServiceRequestError.
The command now prints the line as it is.

An error text of a reply with line breaks, or with its own full stop,
made more than one line or two full stops. service_error now puts the
detail and the network error text on one line with no full stop at
the end.
@dan-petty dan-petty added type/bug Type bug: the code does not do what it must scope/cli Core CLI framework, Typer subcommands, options, and tables labels Nov 13, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Checks and review notes

Tests (rebased on origin/main 83f3656):

  • devops ci fail-to-pass --base origin/main (builder): 7 tests fail on base and 6 test modules do not import on base (no ServiceRequestError); all pass on head.
  • pytest -n 8 on the 16 test files of the change, tests/commands/k8s and the new tests of the review: 1064 passed.
  • pytest -n 8 tests/invariants: 851 passed.
  • devops ci --check --only lint,format,domain,constructs,swallowed-failures,test-tree,security,docs,openspec: pass.
  • devops ci --check --only typecheck (mypy): pass.
  • Known failure that is not related: tests/core/test_git_contract.py[review_window] (open issue fix(roadmap): the review_window git transcript does not match the code #4865).

Render diff: no path under k8s/ changes, so no kustomize or helm render diff applies and no workload restarts.

Fixes of the review (commit "print the service error line once and keep its detail on one line"):

  • devops k8s service-url --fetch put "Request to failed:" before the line of ServiceRequestError, which names the address too. The command now prints the line one time. Test: test_a_fetch_from_a_service_that_stays_down_prints_its_line_once (red before the fix).
  • An error text of a reply with line breaks or with its own full stop gave more than one line or two full stops. service_error now puts the detail and the network error text on one line. Test: test_an_error_text_with_line_breaks_is_one_sentence_of_the_line (red before the fix).
  • The docstring of ReadRetryPolicy and the design table now say that the 8 s cap includes the jitter, as tenacity.wait_exponential_jitter does.

Contracts that keep one attempt:

  • reaches_service: it must tell an API server that cannot dial the Service (503) apart from a Service that answers, at once.
  • The poll _answers of service_probe.forward_service: forward_service has its own wait loop.
  • The telemetry panel of the dashboard (get_json(..., retries=None)): a refresh falls back to the data of the process at once.
  • execute_loki_query keeps its fast fallback to kubectl logs. Grafana POST requests are sent one time.

Behavior changes:

  • query_loki_metrics now raises ServiceRequestError, not KubernetesLoggingError. The messages ERRORS.k8s.loki_unreachable and loki_query_failed are deleted. The specs roadmap-job-grades and infra-apply are MODIFIED to match.
  • A pooled client keys on its retries option. The pool key of the AI clients gets a suffix, but their behavior does not change.

#5487: its acceptance test is tests/commands/test_prometheus.py::test_a_query_that_prometheus_refuses_prints_its_error. The body names it with Refs, because devops pr check-readiness blocks a body that closes more than one issue. A person can close #5487 after the merge.

Live check after the release: stop the Prometheus pod, then run devops prometheus query up. Expected: one line with 4 attempts and exit 1, or the answer when the pod is ready again within the attempts.

@dan-petty
dan-petty marked this pull request as ready for review November 13, 2026 20:43
@dan-petty
dan-petty merged commit 0ae1ce5 into main Nov 13, 2026
24 checks passed
@dan-petty
dan-petty deleted the fix/5532-retry-cluster-service-reads branch November 13, 2026 20:45
dan-petty pushed a commit that referenced this pull request Nov 13, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.132.1](v0.132.0...v0.132.1)
(2026-11-13)


### Bug Fixes

* **cli:** cluster service reads retry a transient 503
([#5549](#5549))
([0ae1ce5](0ae1ce5))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/cli Core CLI framework, Typer subcommands, options, and tables type/bug Type bug: the code does not do what it must

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(http): cluster service reads retry a transient 503

1 participant