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:
Seth Hoenig 2020-05-20 14:26:26 -06:00 committed by GitHub
parent 36c2ae0900
commit 7ea75263ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -10,6 +10,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
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")
@ -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
func (probe *GrpcHealthProbe) Check(target string) error {
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)
defer cancel()
connection, err := grpc.DialContext(ctx, server, probe.dialOptions...)
connection, err := grpc.DialContext(ctx, serverWithScheme, probe.dialOptions...)
if err != nil {
return err
}