-
Notifications
You must be signed in to change notification settings - Fork 2k
feat: add gRPC health check and reflection support to arbiter #21410
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,9 @@ import ( | |
| "time" | ||
|
|
||
| "google.golang.org/grpc" | ||
| "google.golang.org/grpc/health" | ||
| healthgrpc "google.golang.org/grpc/health/grpc_health_v1" | ||
| "google.golang.org/grpc/reflection" | ||
|
|
||
| "github.com/smartcontractkit/chainlink-common/pkg/services" | ||
| ringpb "github.com/smartcontractkit/chainlink-protos/ring/go" | ||
|
|
@@ -27,6 +30,7 @@ type arbiter struct { | |
| services.StateMachine | ||
|
|
||
| grpcServer *grpc.Server | ||
| healthServer *health.Server | ||
| grpcHandler *GRPCServer | ||
| ringArbiterHandler *RingArbiterHandler | ||
| state *State | ||
|
|
@@ -70,8 +74,16 @@ func New( | |
| ringpb.RegisterArbiterServer(grpcServer, grpcHandler) | ||
| ringpb.RegisterArbiterScalerServer(grpcServer, ringArbiterHandler) | ||
|
|
||
| // Register gRPC health check service | ||
| healthServer := health.NewServer() | ||
| healthgrpc.RegisterHealthServer(grpcServer, healthServer) | ||
|
|
||
| // Register gRPC server reflection (enables grpcurl and other tools) | ||
| reflection.Register(grpcServer) | ||
|
Comment on lines
+77
to
+82
|
||
|
|
||
| return &arbiter{ | ||
| grpcServer: grpcServer, | ||
| healthServer: healthServer, | ||
| grpcHandler: grpcHandler, | ||
| ringArbiterHandler: ringArbiterHandler, | ||
| state: state, | ||
|
|
@@ -103,6 +115,9 @@ func (a *arbiter) Start(ctx context.Context) error { | |
| "grpcAddr", a.grpcAddr, | ||
| ) | ||
|
|
||
| // Mark gRPC health as serving | ||
| a.healthServer.SetServingStatus("", healthgrpc.HealthCheckResponse_SERVING) | ||
|
|
||
|
Comment on lines
+118
to
+120
|
||
| return nil | ||
| }) | ||
| } | ||
|
|
@@ -145,6 +160,9 @@ func (a *arbiter) Close() error { | |
| // Signal stop | ||
| close(a.stopCh) | ||
|
|
||
| // Mark health as not serving before stopping | ||
| a.healthServer.SetServingStatus("", healthgrpc.HealthCheckResponse_NOT_SERVING) | ||
|
|
||
| // Graceful shutdown of gRPC server | ||
| a.grpcServer.GracefulStop() | ||
| a.lggr.Debug("gRPC server stopped gracefully") | ||
|
|
||
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.
reflection.Register(grpcServer)enables server reflection unconditionally. Since this repo otherwise appears not to enable gRPC reflection anywhere else, consider gating this behind a config/env flag (or restricting it to non-production) to avoid exposing service/method metadata on any reachable gRPC port.