mirror of https://github.com/status-im/consul.git
grpc: use default resolver scheme for grpc dialing (#7617)
Currently checks of type gRPC will emit log messages such as, 2020/02/12 13:48:22 [INFO] parsed scheme: "" 2020/02/12 13:48:22 [INFO] scheme "" not registered, fallback to default scheme Without adding full support for using custom gRPC schemes (maybe that's right long-term path) we can just supply the default scheme as provided by the grpc library. Fixes https://github.com/hashicorp/consul/issues/7274 and https://github.com/hashicorp/nomad/issues/7415
This commit is contained in:
parent
c02d4e1390
commit
352ed2c13b
|
@ -10,6 +10,7 @@ import (
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/credentials"
|
"google.golang.org/grpc/credentials"
|
||||||
hv1 "google.golang.org/grpc/health/grpc_health_v1"
|
hv1 "google.golang.org/grpc/health/grpc_health_v1"
|
||||||
|
"google.golang.org/grpc/resolver"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrGRPCUnhealthy = fmt.Errorf("gRPC application didn't report service healthy")
|
var ErrGRPCUnhealthy = fmt.Errorf("gRPC application didn't report service healthy")
|
||||||
|
@ -52,12 +53,12 @@ func NewGrpcHealthProbe(target string, timeout time.Duration, tlsConfig *tls.Con
|
||||||
// If nil is returned, target is healthy, otherwise target is not healthy
|
// If nil is returned, target is healthy, otherwise target is not healthy
|
||||||
func (probe *GrpcHealthProbe) Check(target string) error {
|
func (probe *GrpcHealthProbe) Check(target string) error {
|
||||||
serverAndService := strings.SplitN(target, "/", 2)
|
serverAndService := strings.SplitN(target, "/", 2)
|
||||||
server := serverAndService[0]
|
serverWithScheme := fmt.Sprintf("%s:///%s", resolver.GetDefaultScheme(), serverAndService[0])
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), probe.timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), probe.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
connection, err := grpc.DialContext(ctx, server, probe.dialOptions...)
|
connection, err := grpc.DialContext(ctx, serverWithScheme, probe.dialOptions...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue