@@ -3,18 +3,20 @@ package server
33
44import (
55 "context"
6+ "fmt"
67 "net/http"
78 "time"
89
910 "github.com/prometheus/client_golang/prometheus/promhttp"
10- "google.golang.org/grpc/health"
11+ "google.golang.org/grpc"
12+ "google.golang.org/grpc/credentials/insecure"
1113 healthpb "google.golang.org/grpc/health/grpc_health_v1"
1214)
1315
1416var defaultCheckTimeout = 2 * time .Second
1517
1618// Register default HTTP handlers specific to the hybrid server configuration.
17- func DefaultHybridHandlers (s * httpServer , hs * health. Server ) []Handler {
19+ func DefaultHybridHandlers (s * httpServer , port int ) []Handler {
1820 return []Handler {
1921 {
2022 path : "/get-online-features" ,
@@ -26,25 +28,36 @@ func DefaultHybridHandlers(s *httpServer, hs *health.Server) []Handler {
2628 },
2729 {
2830 path : "/health" ,
29- handlerFunc : http .HandlerFunc (combinedHealthCheck (hs )),
31+ handlerFunc : http .HandlerFunc (combinedHealthCheck (port )),
3032 },
3133 }
3234}
3335
3436// This function wraps an http.Handler that is registered during hybrid server creation.
3537// Calls the grpc.server healthcheck check endpoint
36- func combinedHealthCheck (hs * health. Server ) http.HandlerFunc {
38+ func combinedHealthCheck (port int ) http.HandlerFunc {
3739 return func (w http.ResponseWriter , r * http.Request ) {
3840 ctx , cancel := context .WithTimeout (r .Context (), defaultCheckTimeout )
3941 defer cancel ()
4042
41- req := & healthpb.HealthCheckRequest {
42- Service : "" , // Empty string means that it will simply check overall servingStatus
43+ target := fmt .Sprintf ("localhost:%d" , port )
44+ conn , err := grpc .DialContext (
45+ ctx ,
46+ target ,
47+ grpc .WithTransportCredentials (insecure .NewCredentials ()),
48+ grpc .WithBlock (),
49+ )
50+
51+ if err != nil {
52+ http .Error (w , fmt .Sprintf ("gRPC server connectivity check failed: %v" , err ), http .StatusServiceUnavailable )
53+ return
4354 }
55+ defer conn .Close ()
4456
45- resp , err := hs .Check (ctx , req )
57+ hc := healthpb .NewHealthClient (conn )
58+ resp , err := hc .Check (ctx , & healthpb.HealthCheckRequest {Service : "" })
4659 if err != nil {
47- http .Error (w , "gRPC health check failed" , http .StatusInternalServerError )
60+ http .Error (w , fmt . Sprintf ( "gRPC health check failed: %v" , err ) , http .StatusInternalServerError )
4861 return
4962 }
5063
0 commit comments