-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7beaa3f
commit c3738e9
Showing
10 changed files
with
138 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package rest | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"net/http" | ||
|
||
"github.com/go-chi/chi/v5" | ||
"github.com/waku-org/go-waku/waku/v2/node" | ||
) | ||
|
||
type HealthService struct { | ||
node *node.WakuNode | ||
mux *chi.Mux | ||
} | ||
|
||
const routeHealth = "/health" | ||
|
||
func NewHealthService(node *node.WakuNode, m *chi.Mux) *HealthService { | ||
h := &HealthService{ | ||
node: node, | ||
mux: m, | ||
} | ||
|
||
m.Get(routeHealth, h.getHealth) | ||
|
||
return h | ||
} | ||
|
||
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) | ||
} | ||
return | ||
} | ||
|
||
if isReady { | ||
writeResponse(w, HealthResponse("Node is healthy"), http.StatusOK) | ||
} else { | ||
writeResponse(w, HealthResponse("Node is not ready"), http.StatusInternalServerError) | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
openapi: 3.0.3 | ||
info: | ||
title: Waku V2 node REST API | ||
version: 1.0.0 | ||
contact: | ||
name: VAC Team | ||
url: https://forum.vac.dev/ | ||
|
||
tags: | ||
- name: health | ||
description: Healt check REST API for WakuV2 node | ||
|
||
paths: | ||
/health: | ||
get: | ||
summary: Get node health status | ||
description: Retrieve readiness of a Waku v2 node. | ||
operationId: healthcheck | ||
tags: | ||
- health | ||
responses: | ||
'200': | ||
description: Waku v2 node is up and running. | ||
content: | ||
text/plain: | ||
schema: | ||
type: string | ||
example: Node is healty | ||
'500': | ||
description: Internal server error | ||
content: | ||
text/plain: | ||
schema: | ||
type: string | ||
'503': | ||
description: Node not initialized or having issues | ||
content: | ||
text/plain: | ||
schema: | ||
type: string | ||
example: Node is not initialized |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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