Merge pull request #10303 from dragonchaser/grpc-checks

Grpc checks
This commit is contained in:
Christian Richter
2024-10-15 15:19:49 +00:00
committed by GitHub
4 changed files with 28 additions and 3 deletions

View File

@@ -0,0 +1,22 @@
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
}
}

View File

@@ -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(

View File

@@ -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(

View File

@@ -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(