-
Notifications
You must be signed in to change notification settings - Fork 3.9k
health check service #1821
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
health check service #1821
Conversation
syntax = "proto3"; | ||
|
||
package grpc.health.v1; | ||
option java_package = "io.grpc.services.health"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also update the other copies of this file (so they are all identical):
https://github.com/grpc/grpc/blob/master/src/proto/grpc/health/v1/health.proto
https://github.com/grpc/grpc/blob/master/src/python/grpcio_health_checking/grpc/health/v1/health.proto
https://github.com/grpc/grpc-go/blob/master/health/grpc_health_v1/health.proto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We really should have a grpc/common to put protos, and just submodule this.
I've talked to @ctiller about doing this and he seemed to be in agreement. Maybe we can try it out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@carl-mastrangelo I am in favor of that.
I assume the planned usage right now is: HealthStatusManager manager =
new HealthStatusManager(HealthServiceFactory.newHealthService());
serverBuilder
.addService(new MyService1(manager))
.addService(new MyService2(manager))
.build()
.start(); Wondering if we should add i.e. |
@buchgr |
import org.mockito.InOrder; | ||
|
||
public class HealthStatusManagerTest { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dapengzhang0 yep!
PTAL |
respond(status, responseObserver); | ||
} | ||
|
||
private void respond(ServingStatus status, StreamObserver<HealthCheckResponse> responseObserver) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we usually create private methods either for re-using a piece of logic, or breaking down a large method to improve readability. Neither is the case here. It's probably better to merge it with check().
PTAL again |
LGTM |
|
||
package grpc.health.v1; | ||
option csharp_namespace = "Grpc.Health.V1"; | ||
option java_package = "io.grpc.services.health"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The package name must include 'v1'. We should probably use io.grpc.health.v1 as the package name. Let me look for the doc that can shed some more light on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The googleapis has some examples. https://github.com/googleapis/googleapis/blob/master/google/bigtable/v1/bigtable_service_messages.proto
The version number is part of the name to allow future versions without colliding. We probably will want to specify java_multiple_files and java_outer_classname as well. The reason it isn't the default is due to backward compatibility. Note that these changes have to be done sooner than later since these names are exposed to the user as part of the API (since ServingStatus is used directly).
The common convention for java_outer_classname is to use FileNameProto. So in this case it would be HealthProto.
|
||
import static io.grpc.services.health.HealthOuterClass.HealthCheckResponse; | ||
import static io.grpc.services.health.HealthOuterClass.HealthCheckResponse.ServingStatus; | ||
import static io.grpc.health.v1.HealthCheckResponse.ServingStatus; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, this can be a normal (non-static import). Doesn't matter which way you do it though.
@dapengzhang0 LGTM |
StreamObserver<HealthCheckResponse> responseObserver) { | ||
ServingStatus status = getStatus(request.getService()); | ||
if (status == null) { | ||
responseObserver.onError(new StatusException(Status.NOT_FOUND)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dapengzhang0 i am a bit confused about the default behavior here
from the grpc health check doc:
A client can query the server’s health status by calling the Check method, and a deadline should be set on the rpc. The client can OPTIONALLY set the service name it wants to query for health status.
with the current implementation, the server expects a service name to be COMPULSORILY specified in the request and returns a Status.NOT_FOUND for an empty service check. shouldn't it respond with the general health of the server, which should be counted as SERVING independent of the included service's statuses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nvm: the very next statement from the doc helped clarify it:
The server should register all the services manually and set the individual status, including an empty service name and its status.
#647
Implemented health service in grpc-java.
See
https://github.com/grpc/grpc/blob/d0fbba52d6e379b76a69016bc264b96a2318315f/src/ruby/pb/grpc/health/checker.rb
and
https://github.com/grpc/grpc/blob/c236a213ee10f549d328840bc21c307eedd4b545/src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs
for the main part of Ruby and C# implementations.