Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIXED] Healthz with details returns 200 OK even with errors #6248

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions server/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3241,10 +3241,11 @@ func (s *Server) HandleHealthz(w http.ResponseWriter, r *http.Request) {
Details: includeDetails,
})

code := http.StatusOK
code := hs.StatusCode
if hs.Error != _EMPTY_ {
s.Warnf("Healthcheck failed: %q", hs.Error)
code = hs.StatusCode
} else if len(hs.Errors) != 0 {
s.Warnf("Healthcheck failed: %d errors", len(hs.Errors))
}
// Remove StatusCode from JSON representation when responding via HTTP
// since this is already in the response.
Expand Down
13 changes: 11 additions & 2 deletions server/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5492,7 +5492,7 @@ func TestHealthzStatusUnavailable(t *testing.T) {
}{
{
"healthz",
fmt.Sprintf("http://%s/healthz", s.MonitorAddr().String()),
fmt.Sprintf("http://%s/healthz?", s.MonitorAddr().String()),
http.StatusServiceUnavailable,
"unavailable",
},
Expand All @@ -5510,7 +5510,16 @@ func TestHealthzStatusUnavailable(t *testing.T) {
},
} {
t.Run(test.name, func(t *testing.T) {
expectHealthStatus(t, test.url, test.statusCode, test.wantStatus)
t.Run("no-details", func(t *testing.T) {
expectHealthStatus(t, test.url, test.statusCode, test.wantStatus)
})
t.Run("with-details", func(t *testing.T) {
detailsUrl := fmt.Sprintf("%s&details=true", test.url)
if test.wantStatus != "ok" {
test.wantStatus = "error"
}
expectHealthStatus(t, detailsUrl, test.statusCode, test.wantStatus)
})
})
}
}
Expand Down
Loading