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

Grpc healthcheck docs are unclear #1977

Closed
Pryanishnik opened this issue Feb 17, 2021 · 5 comments
Closed

Grpc healthcheck docs are unclear #1977

Pryanishnik opened this issue Feb 17, 2021 · 5 comments

Comments

@Pryanishnik
Copy link

https://grpc-ecosystem.github.io/grpc-gateway/docs/operations/health_check/

From this doc I can not understand where I have to put imports and register service.
Also, I don't understand if I have to make separate healthcheck service.
Why we can not use DefaultHealthCheck?
It probab;y make sense to make "transparent" call of default healthcheck from outer REST. I.E. Amazon Load Balancer uses it for determining instance state.
Or if we can, please clarify how to enable it

@johanbrandhorst
Copy link
Collaborator

Hi @Pryanishnik, thanks for your issue. The docs are talking about implementing the gRPC health check protocol, which may not be what you want. If you want to simply add a /health handler to your Go service, you can do that using a normal http.ServeMux where you add a handler explicitly and pass in our runtime.ServeMux separately. For example:

gwmux := runtime.NewServeMux()
err := gw.RegisterYourServiceHandlerFromEndpoint(ctx, gwmux,  *grpcServerEndpoint, opts)
if err != nil {
    log.Fatalln("failed to register gateway:", err)
}
mux := http.NewServeMux()
mux.Handle("/", gwmux)
mux.Handle("/health", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    w.WriteHeader(http.StatusOK)
})
http.ListenAndServe(":3000", mux)

Does that make sense?

@Pryanishnik
Copy link
Author

Pryanishnik commented Feb 18, 2021

Thank you for reply @johanbrandhorst. Not exactly. I want to use gRPC healthcheck protocol. ACtually, how I do it now using
https://github.com/salrashid123/grpc_health_proxy.
image

In this case, architecture becomes pretty complicated. I want to remove this health proxy and am wondering if I can get health proxy functionality in gRPC gateway "from the box"? So, if grpc gateway can reroute outer REST to default grpc health check?

@johanbrandhorst
Copy link
Collaborator

The grpc-gateway doesn't have any built in functionality to translate this. You could take the existing grpc health check protofile and generate some REST annotations for it using the generate_unbound_methods option and then serve that. It may not give you the signature that you want though, in which case you either have to define your own proto service wrapper or just use a custom handler as I suggested in my first reply. Does that make sense?

@Pryanishnik
Copy link
Author

Yes, it clarifies a bit, thank you! But for future it makes sense to implement this translation. I.E. AWS Load Balancer will not work with server for autosacling, coz it needs healthchecks. If we use REST we can not do default grpc healthchecks, and in this case we have to implement own workaround for REST healthchecks. But anyway, thank you!

@johanbrandhorst
Copy link
Collaborator

If you'd like to contribute something to the docs I'd be very grateful. I agree that the health checks section is pretty poor. I've never implemented it myself though so I don't know what to put.

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