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(health): Add tonic-health server impl #304

Merged
merged 1 commit into from
Mar 30, 2020
Merged

Conversation

jen20
Copy link
Collaborator

@jen20 jen20 commented Mar 27, 2020

This commit adds a new crate tonic-health which implements the standard GRPC Health Checking protocol, as per #135.

Currently there is only a server implementation, though others have alluded in the discussion in #135 that client implementations exist which could also be imported as necessary.

A example server has also been added - once the client work is done a client for this should be added also.

Some further work that needs doing:

  • Fix unnecessary tokio::spawn in implementation of Watch
  • Clean up Cargo.toml metadata
  • Add a transport feature which unlocks the various methods which use NamedService
  • Add some tests of both Check and Watch
  • Consider whether to write or import a client as part of this PR or separately.

@jen20 jen20 added C-enhancement Category: New feature or request A-examples labels Mar 27, 2020
@jen20 jen20 added this to the 0.2 milestone Mar 27, 2020
@jen20 jen20 requested a review from LucioFranco March 27, 2020 21:47
@jen20 jen20 self-assigned this Mar 27, 2020
@jen20 jen20 linked an issue Mar 27, 2020 that may be closed by this pull request
@rokadias rokadias mentioned this pull request Mar 27, 2020
Copy link
Member

@LucioFranco LucioFranco left a comment

Choose a reason for hiding this comment

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

Looks great! I think the only thing left is to add a feature flag for the transport so this can be used without that feature flag. Otherwise, I'll ship this with tonic 0.2.

tonic-health/Cargo.toml Outdated Show resolved Hide resolved
tonic-health/Cargo.toml Outdated Show resolved Hide resolved
tonic-health/Cargo.toml Show resolved Hide resolved
tonic-health/src/server.rs Outdated Show resolved Hide resolved
@jen20 jen20 force-pushed the jen20/tonic-health branch 2 times, most recently from c4f3eb9 to d6a7e07 Compare March 30, 2020 12:33
This commit adds a new crate `tonic-health` which implements the
[standard GRPC Health Checking][checking] protocol.

Currently there is only a server implementation, though others have
alluded in the discussion in #135 that client implementations exist
which could also be imported as necessary.

A example server has also been added - once the client work is done a
client for this should be added also.

[checking]: https://github.com/grpc/grpc/blob/master/doc/health-checking.md
@jen20
Copy link
Collaborator Author

jen20 commented Mar 30, 2020

I think we should address a client here in a separate PR, so this looks ready for re-review (at least the added tests) - everything else has been addressed.

@LucioFranco
Copy link
Member

@jen20 merge when you're ready!

@jen20 jen20 merged commit da92dbf into master Mar 30, 2020
@jen20 jen20 deleted the jen20/tonic-health branch March 30, 2020 14:33
@jen20
Copy link
Collaborator Author

jen20 commented Mar 30, 2020

Thanks for reviewing @LucioFranco!

@jcramb
Copy link

jcramb commented May 17, 2020

Is the tonic-health checking expected to be working right now because using the example provided only results in Error: Status { code: Unimplemented } being returned for every connection.

For reference I used the example health server and then compiled my own client invoking the health check in the following way,

let mut client = pb::health_client::HealthClient::new(channel);
let req = pb::HealthCheckRequest {
    service: "",
};
let resp = client.check(req).await?.into_inner();
println!("{}", resp.status);

This all compiled and connected successfully returning the error stated above. Am I using this incorrectly or do you have any idea on how to fix this? I've even printed out the service name as used by the tonic-health crate helloworld.Greeter and set this explicitly but it still returns the same result.

@jen20
Copy link
Collaborator Author

jen20 commented May 20, 2020

Hmm, that's curious - it is indeed expected to be working! I'll take a look and see if I can reproduce this...

@jen20
Copy link
Collaborator Author

jen20 commented May 20, 2020

I've just tried this on the current master of tonic making use of grpcurl. Some of the paths are specific to my checkout directory, and I had to change the port of the server owing to a conflict on my machine, but all seems to be well overall:

$ cargo run --bin health-server
   Compiling examples v0.1.0 (/Users/James/Code/rust/tonic/examples)
    Finished dev [unoptimized + debuginfo] target(s) in 4.89s
     Running `/Users/James/Code/rust/tonic/target/debug/health-server`
HealthServer + GreeterServer listening on [::1]:50057
$ grpcurl -plaintext \
        -proto=/Users/James/Code/rust/tonic/tonic-health/proto/health.proto \
        -import-path=/Users/James/Code/rust/tonic/tonic-health/proto \
        -format=json \
        -d='{"service": "helloworld.Greeter"}' \
        '[::1]:50057' \
        grpc.health.v1.Health.Check
{
  "status": "SERVING"
}

If I try a service which is not registered (including "", which is not special cased) I get a NotFound status code rather than an Unimplemented status code.

If you have grpcurl available (it's in Homebrew on macOS, but not sure on other platforms), could you try a similar command line modified for your checkout directories to try to narrow down what is going on here, @jcramb?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-examples C-enhancement Category: New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement gRPC standard health checking service
3 participants