mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-07-28 16:29:09 -04:00
22
ocis-pkg/handlers/checkgrpc.go
Normal file
22
ocis-pkg/handlers/checkgrpc.go
Normal 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
|
||||
}
|
||||
}
|
||||
@@ -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(
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user