feat(grpc): add healthz support#5218
Conversation
8502715 to
a06e72f
Compare
a06e72f to
e37590c
Compare
d29ca5e to
0c067b6
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5218 +/- ##
==========================================
+ Coverage 33.51% 35.38% +1.87%
==========================================
Files 250 241 -9
Lines 28908 31681 +2773
==========================================
+ Hits 9688 11211 +1523
- Misses 18609 19757 +1148
- Partials 611 713 +102
🚀 New features to boost your workflow:
|
| // Register health service only if enabled | ||
| if s.healthService != nil { | ||
| healthpb.RegisterHealthServer(grpcServer, s.healthService.Server()) | ||
| go s.healthService.StartMonitor(ctx) |
There was a problem hiding this comment.
Just a doubt, this go routine spawning could race with the line 84 somehow (inside other spawning)?
There was a problem hiding this comment.
Just a doubt, this go routine spawning could race with the line 84 somehow (inside other spawning)?
No race here. The RegisterHealthServer call on line 78 completes synchronously before either goroutine is spawned. After that, the two goroutines operate on independent concerns:
StartMonitoronly callshealth.Server.SetServingStatus(), which is internally synchronized with a mutex in the standard gRPC health server implementation.grpcServer.Serve()starts accepting connections and dispatching RPCs, reading the health status through the same mutex-protectedCheck/Watchhandlers.
So even if Serve starts accepting connections before StartMonitor sets the initial NOT_SERVING status, a health check arriving in that window would get SERVICE_UNKNOWN (the default for unregistered services), which Kubernetes treats as unhealthy — same practical effect as NOT_SERVING.
0c067b6 to
7e7e24c
Compare
Fix #5217
Add gRPC Health Checking Service
This PR adds support for the standard gRPC health checking protocol (
grpc.health.v1) to Tracee's gRPC server, enabling Kubernetes gRPC probes for health checks.Changes
HealthServicethat wraps the standard gRPC health server and integrates with Tracee's existing heartbeat mechanism--server healthzflag is passed (same behavior as HTTP healthz endpoint)SERVINGandNOT_SERVINGbased on heartbeat livenessTechnical Details
NOT_SERVINGand transitions toSERVINGonce heartbeat confirms health"") for overall server health, which is sufficient for Kubernetes gRPC probesInvokeHeartbeatfunction to sharedpkg/server/heartbeat.goto be accessible by both HTTP and gRPC serversTesting