mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-31 15:31:20 +00:00
Return 503 on healthz with error (#6754)
* Return 503 on healthz with error * fix other test * Update shared/prometheus/service_test.go Co-authored-by: Victor Farazdagi <simple.square@gmail.com>
This commit is contained in:
parent
3a609f44b9
commit
1a1c1bb813
@ -61,6 +61,7 @@ func (s *Service) healthzHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
Status bool `json:"status"`
|
Status bool `json:"status"`
|
||||||
Err string `json:"error"`
|
Err string `json:"error"`
|
||||||
}
|
}
|
||||||
|
var hasError bool
|
||||||
var statuses []serviceStatus
|
var statuses []serviceStatus
|
||||||
for k, v := range s.svcRegistry.Statuses() {
|
for k, v := range s.svcRegistry.Statuses() {
|
||||||
s := serviceStatus{
|
s := serviceStatus{
|
||||||
@ -70,11 +71,18 @@ func (s *Service) healthzHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
if v != nil {
|
if v != nil {
|
||||||
s.Status = false
|
s.Status = false
|
||||||
s.Err = v.Error()
|
s.Err = v.Error()
|
||||||
|
if s.Err != "" {
|
||||||
|
hasError = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
statuses = append(statuses, s)
|
statuses = append(statuses, s)
|
||||||
}
|
}
|
||||||
response.Data = statuses
|
response.Data = statuses
|
||||||
|
|
||||||
|
if hasError {
|
||||||
|
w.WriteHeader(http.StatusServiceUnavailable)
|
||||||
|
}
|
||||||
|
|
||||||
// Handle plain text content.
|
// Handle plain text content.
|
||||||
if contentType := negotiateContentType(r); contentType == contentTypePlainText {
|
if contentType := negotiateContentType(r); contentType == contentTypePlainText {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
|
@ -94,8 +94,8 @@ func TestHealthz(t *testing.T) {
|
|||||||
rr = httptest.NewRecorder()
|
rr = httptest.NewRecorder()
|
||||||
handler.ServeHTTP(rr, req)
|
handler.ServeHTTP(rr, req)
|
||||||
|
|
||||||
if status := rr.Code; status != http.StatusOK {
|
if status := rr.Code; status != http.StatusServiceUnavailable {
|
||||||
t.Errorf("expected OK status but got %v", rr.Code)
|
t.Errorf("expected StatusServiceUnavailable status but got %v", rr.Code)
|
||||||
}
|
}
|
||||||
|
|
||||||
body = rr.Body.String()
|
body = rr.Body.String()
|
||||||
@ -185,5 +185,8 @@ func TestContentNegotiation(t *testing.T) {
|
|||||||
if !strings.Contains(body, expectedJSON) {
|
if !strings.Contains(body, expectedJSON) {
|
||||||
t.Errorf("Unexpected data, want: %q got %q", expectedJSON, body)
|
t.Errorf("Unexpected data, want: %q got %q", expectedJSON, body)
|
||||||
}
|
}
|
||||||
|
if rr.Code < 500 {
|
||||||
|
t.Errorf("Expected a server error response code, but got %d", rr.Code)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user