Skip to content

backend: serve /healthz and /api/healthz from a single handler - #656

Open
NopeCharon wants to merge 1 commit into
kbind-dev:mainfrom
NopeCharon:consolidate-healthz-endpoints
Open

NopeCharon wants to merge 1 commit into
kbind-dev:mainfrom
NopeCharon:consolidate-healthz-endpoints

Conversation

@NopeCharon

Copy link
Copy Markdown

Summary

Follow-up to #505. The backend had two separate health endpoints:

  • /healthz, registered in backend.NewServer right after the web server is created, so it is always served. The Helm chart liveness/readiness probes use it.
  • /api/healthz, registered in handler.AddRoutes, which only runs when the frontend is enabled. It returned an empty body, while /healthz returned ok without the no-cache headers.

This PR registers both paths in http.NewServer and points them at one handleHealthz function, which sets the no-cache headers and writes ok. The duplicate implementation is gone, both paths respond the same way, and /api/healthz now also works with --frontend-disabled. I kept both paths registered so existing probes and API clients don't break. The Helm chart uses /healthz, and the v2 proposal lists /api/healthz.

A new unit test in backend/http/server_test.go checks status, body and cache headers for both paths. It fails on main with a 404, because there NewServer doesn't register any health route.

Testing:

  • go test ./backend/http/ and golangci-lint run ./backend/... with the repo config: 0 issues.
  • I started the real backend through framework.StartBackend against a local kcp workspace, once with the frontend enabled and once with --frontend-disabled. In both modes, GET /healthz and GET /api/healthz returned 200 "ok" with Cache-Control: no-cache, no-store, must-revalidate, max-age=0.

What Type of PR Is This?

/kind cleanup

Related Issue(s)

Fixes #506

Release Notes

The backend now serves `/healthz` and `/api/healthz` from the same handler, and `/api/healthz` is also available when the frontend is disabled.

The backend had two independent health endpoints:

- /healthz, registered in backend.NewServer right after the web server
  is created, so it is always available. The Helm chart probes use it.
- /api/healthz, registered in handler.AddRoutes, which only runs when
  the frontend is enabled. It returned an empty body, while /healthz
  returned "ok" without the no-cache headers.

Register both paths in http.NewServer and point them at one
handleHealthz function that sets the no-cache headers and writes "ok".
This removes the duplicate implementation, makes both endpoints behave
the same, and keeps /api/healthz available in --frontend-disabled mode.
Both paths stay registered so existing probes and API clients keep
working.

Add a unit test that checks status, body and cache headers for both
paths on a freshly created server.

Signed-off-by: NopeCharon <115794254+NopeCharon@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Follow-up: merge/squash /api/healthz and /healthz endpoints

1 participant