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

Fix /health REST API panic #763

Merged
merged 3 commits into from
Sep 21, 2023
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
2 changes: 1 addition & 1 deletion cmd/waku/server/rest/debug_api.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
openapi: 3.0.3
info:
title: Waku V2 node REST API
title: Waku V2 node Debug REST API
version: 1.0.0
contact:
name: VAC Team
Expand Down
26 changes: 15 additions & 11 deletions cmd/waku/server/rest/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,23 @@ func NewHealthService(node *node.WakuNode, m *chi.Mux) *HealthService {
type HealthResponse string

func (d *HealthService) getHealth(w http.ResponseWriter, r *http.Request) {
isReady, err := d.node.RLNRelay().IsReady(r.Context())
if err != nil {
if errors.Is(err, context.DeadlineExceeded) {
writeResponse(w, HealthResponse("Health check timed out"), http.StatusInternalServerError)
} else {
writeResponse(w, HealthResponse(err.Error()), http.StatusInternalServerError)
if d.node.RLNRelay() != nil {
isReady, err := d.node.RLNRelay().IsReady(r.Context())
if err != nil {
if errors.Is(err, context.DeadlineExceeded) {
writeResponse(w, HealthResponse("Health check timed out"), http.StatusInternalServerError)
} else {
writeResponse(w, HealthResponse(err.Error()), http.StatusInternalServerError)
}
return
}
return
}

if isReady {
writeResponse(w, HealthResponse("Node is healthy"), http.StatusOK)
if isReady {
writeResponse(w, HealthResponse("Node is healthy"), http.StatusOK)
} else {
writeResponse(w, HealthResponse("Node is not ready"), http.StatusInternalServerError)
}
} else {
writeResponse(w, HealthResponse("Node is not ready"), http.StatusInternalServerError)
writeResponse(w, HealthResponse("Non RLN healthcheck is not implemented"), http.StatusNotImplemented)
}
}
2 changes: 1 addition & 1 deletion cmd/waku/server/rest/health_api.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
openapi: 3.0.3
info:
title: Waku V2 node REST API
title: Waku V2 node Health REST API
version: 1.0.0
contact:
name: VAC Team
Expand Down
2 changes: 1 addition & 1 deletion cmd/waku/server/rest/relay_api.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
openapi: 3.0.3
info:
title: Waku V2 node REST API
title: Waku V2 node Relay REST API
version: 1.0.0
contact:
name: VAC Team
Expand Down
2 changes: 1 addition & 1 deletion cmd/waku/server/rest/store_api.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
openapi: 3.0.3
info:
title: Waku V2 node REST API
title: Waku V2 node Store REST API
version: 1.0.0
contact:
name: VAC Team
Expand Down