From c803194975e8b3d911723a1260631920531d20ff Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Tue, 15 Oct 2024 16:00:23 +0200 Subject: [PATCH 1/2] add generic grpc checker Signed-off-by: Christian Richter --- ocis-pkg/handlers/checkgrpc.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 ocis-pkg/handlers/checkgrpc.go diff --git a/ocis-pkg/handlers/checkgrpc.go b/ocis-pkg/handlers/checkgrpc.go new file mode 100644 index 00000000000..f871ae1d6eb --- /dev/null +++ b/ocis-pkg/handlers/checkgrpc.go @@ -0,0 +1,21 @@ +package handlers + +import ( + "context" + "fmt" + "google.golang.org/grpc/credentials/insecure" + + "google.golang.org/grpc" +) + +// NewGRPCCheck checks the reachability of a grpc server. +func NewGRPCCheck(address string) func(ctx context.Context) error { + return func(_ context.Context) error { + conn, err := grpc.NewClient(address, grpc.WithTransportCredentials(insecure.NewCredentials())) + if err != nil { + return fmt.Errorf("could not connect to grpc server: %v", err) + } + _ = conn.Close() + return nil + } +} From 49cf9b085998ecf20abd967204c1b8d00c7a7a12 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Tue, 15 Oct 2024 16:00:42 +0200 Subject: [PATCH 2/2] add grpc checker to search, settings & thumbnails Signed-off-by: Christian Richter --- ocis-pkg/handlers/checkgrpc.go | 1 + services/search/pkg/server/debug/server.go | 3 ++- services/settings/pkg/server/debug/server.go | 3 ++- services/thumbnails/pkg/server/debug/server.go | 3 ++- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ocis-pkg/handlers/checkgrpc.go b/ocis-pkg/handlers/checkgrpc.go index f871ae1d6eb..5018f42349f 100644 --- a/ocis-pkg/handlers/checkgrpc.go +++ b/ocis-pkg/handlers/checkgrpc.go @@ -3,6 +3,7 @@ package handlers import ( "context" "fmt" + "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc" diff --git a/services/search/pkg/server/debug/server.go b/services/search/pkg/server/debug/server.go index 85136a94de8..dc12c2b4b23 100644 --- a/services/search/pkg/server/debug/server.go +++ b/services/search/pkg/server/debug/server.go @@ -14,7 +14,8 @@ func Server(opts ...Option) (*http.Server, error) { checkHandler := handlers.NewCheckHandler( handlers.NewCheckHandlerConfiguration(). - WithLogger(options.Logger), + WithLogger(options.Logger). + WithCheck("grpc reachability", handlers.NewGRPCCheck(options.Config.GRPC.Addr)), ) return debug.NewService( diff --git a/services/settings/pkg/server/debug/server.go b/services/settings/pkg/server/debug/server.go index 99179d7d48b..242b1bfd044 100644 --- a/services/settings/pkg/server/debug/server.go +++ b/services/settings/pkg/server/debug/server.go @@ -15,7 +15,8 @@ func Server(opts ...Option) (*http.Server, error) { checkHandler := handlers.NewCheckHandler( handlers.NewCheckHandlerConfiguration(). WithLogger(options.Logger). - WithCheck("web reachability", handlers.NewHTTPCheck(options.Config.HTTP.Addr)), + WithCheck("web reachability", handlers.NewHTTPCheck(options.Config.HTTP.Addr)). + WithCheck("grpc reachability", handlers.NewGRPCCheck(options.Config.GRPC.Addr)), ) return debug.NewService( diff --git a/services/thumbnails/pkg/server/debug/server.go b/services/thumbnails/pkg/server/debug/server.go index 99179d7d48b..242b1bfd044 100644 --- a/services/thumbnails/pkg/server/debug/server.go +++ b/services/thumbnails/pkg/server/debug/server.go @@ -15,7 +15,8 @@ func Server(opts ...Option) (*http.Server, error) { checkHandler := handlers.NewCheckHandler( handlers.NewCheckHandlerConfiguration(). WithLogger(options.Logger). - WithCheck("web reachability", handlers.NewHTTPCheck(options.Config.HTTP.Addr)), + WithCheck("web reachability", handlers.NewHTTPCheck(options.Config.HTTP.Addr)). + WithCheck("grpc reachability", handlers.NewGRPCCheck(options.Config.GRPC.Addr)), ) return debug.NewService(