Skip to content

Commit

Permalink
bug: grpc_health
Browse files Browse the repository at this point in the history
  • Loading branch information
moocss committed Sep 30, 2023
1 parent eee8fed commit 766850d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
7 changes: 7 additions & 0 deletions transport/grpc/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ func Middleware(m ...middleware.Middleware) ServerOption {
}
}

// CustomHealth Checks server.
func CustomHealth() ServerOption {
return func(s *Server) {
s.customHealth = true
}
}

// TLSConfig with TLS config.
func TLSConfig(c *tls.TLS) ServerOption {
return func(s *Server) {
Expand Down
14 changes: 2 additions & 12 deletions transport/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/apus-run/sea-kit/log"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/health/grpc_health_v1"
hapi "google.golang.org/grpc/health/grpc_health_v1"
"google.golang.org/grpc/reflection"

"github.com/apus-run/gaia/internal/endpoint"
Expand Down Expand Up @@ -60,25 +60,15 @@ func NewServer(opts ...ServerOption) *Server {
srv.Server = grpc.NewServer(grpcOpts...)
// internal register
if !srv.customHealth {
grpc_health_v1.RegisterHealthServer(srv.Server, srv.health)
}

// listen and endpoint
srv.err = srv.listenAndEndpoint()

if !srv.customHealth {
// see https://github.com/grpc/grpc/blob/master/doc/health-checking.md
grpc_health_v1.RegisterHealthServer(srv.Server, srv.health)
hapi.RegisterHealthServer(srv.Server, srv.health)
}

// register reflection and the interface can be debugged through the grpcurl tool
// https://github.com/grpc/grpc-go/blob/master/Documentation/server-reflection-tutorial.md#enable-server-reflection
// see https://github.com/fullstorydev/grpcurl
reflection.Register(srv.Server)

// admin register
srv.adminClean, _ = admin.Register(srv.Server)

return srv
}

Expand Down
3 changes: 1 addition & 2 deletions transport/grpc/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import (
"testing"
"time"

"google.golang.org/grpc"

"github.com/apus-run/gaia/internal/matcher"
pb "github.com/apus-run/gaia/internal/testdata/helloworld"
"github.com/apus-run/gaia/middleware"
"google.golang.org/grpc"
)

// server is used to implement helloworld.GreeterServer.
Expand Down

0 comments on commit 766850d

Please sign in to comment.