Skip to content

Commit

Permalink
Merge pull request #10303 from dragonchaser/grpc-checks
Browse files Browse the repository at this point in the history
Grpc checks
  • Loading branch information
dragonchaser authored Oct 15, 2024
2 parents fde6b4c + 49cf9b0 commit 4f8d0bb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
22 changes: 22 additions & 0 deletions ocis-pkg/handlers/checkgrpc.go
Original file line number Diff line number Diff line change
@@ -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
}
}
3 changes: 2 additions & 1 deletion services/search/pkg/server/debug/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion services/settings/pkg/server/debug/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion services/thumbnails/pkg/server/debug/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 4f8d0bb

Please sign in to comment.