From 44ee818d46ceb1adf6e9250067afe13f7e2cb30b Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Wed, 20 May 2020 14:26:26 -0600 Subject: [PATCH] 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 --- agent/checks/grpc.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/agent/checks/grpc.go b/agent/checks/grpc.go index 4ad7b9f34b..dea6a84cff 100644 --- a/agent/checks/grpc.go +++ b/agent/checks/grpc.go @@ -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 }