Repository navigation
backend: serve /healthz and /api/healthz from a single handler - #656
Open
NopeCharon wants to merge 1 commit into
Open
NopeCharon wants to merge 1 commit into
NopeCharon wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #505. The backend had two separate health endpoints:
/healthz, registered inbackend.NewServerright after the web server is created, so it is always served. The Helm chart liveness/readiness probes use it./api/healthz, registered inhandler.AddRoutes, which only runs when the frontend is enabled. It returned an empty body, while/healthzreturnedokwithout the no-cache headers.This PR registers both paths in
http.NewServerand points them at onehandleHealthzfunction, which sets the no-cache headers and writesok. The duplicate implementation is gone, both paths respond the same way, and/api/healthznow 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.gochecks status, body and cache headers for both paths. It fails onmainwith a 404, because thereNewServerdoesn't register any health route.Testing:
go test ./backend/http/andgolangci-lint run ./backend/...with the repo config: 0 issues.framework.StartBackendagainst a local kcp workspace, once with the frontend enabled and once with--frontend-disabled. In both modes,GET /healthzandGET /api/healthzreturned200 "ok"withCache-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