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

Exposing GET handler for health check #762

Closed
tarrencev opened this issue May 10, 2022 · 6 comments
Closed

Exposing GET handler for health check #762

tarrencev opened this issue May 10, 2022 · 6 comments

Comments

@tarrencev
Copy link

Is there a recommended approach to exposing a GET handler for i.e. health checks or metrics on the base server? It doesn't seem possible to register additional handlers today. I has hoping build_from_hyper would help with this but it still doesn't give access to the underlying service builder.

Related eqlabs/pathfinder#194

@niklasad1
Copy link
Member

niklasad1 commented May 10, 2022

You referring to the HTTP server correct?

So currently, we have the middleware that you can use to collect metrics based on the timings but not a health API or any mean to register additional handlers.

However, I have nothing against to expose a health API on the HTTP server sounds like a good idea.

If you want to implement it that would be great.

@tarrencev
Copy link
Author

Yes thats correct. Awesome. It seems like a health check would be quite specific to the consumer service, since it might depend on the service implementation. Do you have an idea of what an interface might look like?

@niklasad1
Copy link
Member

niklasad1 commented May 10, 2022

I think the jsonrpc crate health API looks quite clean.

I'm not exactly sure if how likely it's that folks would want to provide their own HTTP status codes, jsonrpc for instance let you define a RPC call and if that fails it will be converted to status code 500. That's quite simple to use at least.

Would be neat to have something a bit more flexible such as (a closure could work too):

trait HealthApi {
    fn health(&self) -> (StatusCode, Body);
}

server impl

 builder.health_api(set_handler());

 match (request.method(), server.get_health_api()) {
    (handler, Method::GET)  {
       let (status_code, body) = handler.health();
       send_http_response(status_code, body);
    }
 }  

@niklasad1
Copy link
Member

niklasad1 commented May 11, 2022

sorry @tarrencev I realized that we need this ASAP too.

So I have opened #763 I hope that will fix things for you, sorry for not letting you implement that.

we could revisit the API at a later point, if someone comes up with something more better.

@niklasad1
Copy link
Member

Closed by #763

@tarrencev
Copy link
Author

Awesome appreciate you taking care of this!

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

No branches or pull requests

2 participants