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

feat: Rest endoint /health for rln #2011

Merged
merged 5 commits into from
Sep 8, 2023
Merged

Conversation

NagyZoltanPeter
Copy link
Contributor

@NagyZoltanPeter NagyZoltanPeter commented Sep 7, 2023

Description

For RLN readiness /health rest endpoint is added.
It checks if wakunode is ready - currently it means rln is mounted correctly. returns proper http status upon.

Changes

  • New rest endpoint /health introduced
  • Test that supports rln is added to verify

How to test

  1. make test EXPERIMENTAL=true

or

  1. ./scripts/build_rln.sh ./vendor/zerokit
  2. nim c -r -d:chronicles_log_level=DEBUG -d:os=Linux --parallelBuild:2 --verbosity:1 -d:chronicles_log_level=DEBUG -d:release -d:rln --passL:./vendor/zerokit/target/release/librln.a --passL:-lm ./tests/wakunode_rest/test_rest_health.nim

Issue

feat(rest): Add /health endpoint to rest api

@github-actions
Copy link

github-actions bot commented Sep 7, 2023

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:2011

@github-actions
Copy link

github-actions bot commented Sep 7, 2023

You can find the experimental image built from this PR at

quay.io/wakuorg/nwaku-pr:2011-experimental

Copy link
Contributor

@alrevuelta alrevuelta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left some comments thanks! will manually test it later with onchain rln

waku/node/waku_node.nim Outdated Show resolved Hide resolved
tests/wakunode_rest/test_rest_health.nim Show resolved Hide resolved
waku/node/rest/health/client.nim Show resolved Hide resolved
waku/node/rest/health/openapi.yaml Show resolved Hide resolved
var status = Http200

if not isReadyStateFut.read():
msg = "Node is not inititialized"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps node is not ready?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you wish so?! :-) I will change!

msg = "Node is not inititialized"
status = Http503

return RestApiResponse.textResponse(msg, status)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsure about the best practices of health endpoints, but would it make sense to return a json that we can extend in the future? In case we want more granularity on the state of the services. For example, we may want to say that is not healthy, but provide a list on which services are not healthy.

No need to define it right now but allow for future extension. return json instead of textResponse?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can change it but in this case http status holds the information rather.
For meaningful message, text can be enough. Not sure what information we can structure into json later.
For checking status of different submodules or protocols sounds more like an admin interface than a health. Wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep indeed. http status code has the information.

i was suggesting to return a json in case we want to add more information in the future. so if for example its failing, you have information such as (example taken from prysm node): so you know which service is not healthy

/healthz

*rpc.Service: OK
*prometheus.Service: OK
*p2p.Server: OK
*powchain.Web3Service: OK
*attestation.Service: OK
*operations.Service: OK
*blockchain.ChainService: OK
*sync.Service: ERROR not initially synced

no need to do it now, but be prepared to extend it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was gonna add the same comment - let's use JSON rather than text - it is extensible and easier to process with tools than plain text

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with it, but will do in a separate PR is possible.
Also I think we need to enhance a bit client decoders (not just here) to accept json/text both due error cases returns text type, mixing them can cause exception. It's on my list already, but will do in all rest endpoints where necessary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this issue, obviously, but since we are talking about it - would it make more sense to always return json (even for errors)?

Copy link
Collaborator

@Ivansete-status Ivansete-status left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for it!. Just minor comments

waku/node/rest/health/handlers.nim Outdated Show resolved Hide resolved
waku/node/rest/health/handlers.nim Show resolved Hide resolved
Co-authored-by: Ivan Folgueira Bande <128452529+Ivansete-status@users.noreply.github.com>
Copy link
Contributor

@jm-clius jm-clius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks.


router.api(MethodGet, ROUTE_HEALTH) do () -> RestApiResponse:

let isReadyStateFut = node.isReady()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a comment to indicate what isReady() indicates? Does it mean the node has completed setup procedures and is listening for new connections?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add as there is one little stuff to fix in test.

Copy link
Contributor

@rymnc rymnc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for this!

Copy link
Contributor

@alrevuelta alrevuelta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! when ci passes

@NagyZoltanPeter NagyZoltanPeter merged commit fc6194b into master Sep 8, 2023
14 checks passed
@NagyZoltanPeter NagyZoltanPeter deleted the feat-1988-health-endpoint branch September 8, 2023 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants