From f83159cc8d34dad45b5de97972f2ec566f46a142 Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Fri, 17 Sep 2021 12:20:59 +0200 Subject: [PATCH] client: Use first endpoint as http2 authority header This doesn't fully fix authority in multiple endpoint scenario, but should at least fixes single endpoint scenario. --- client/v3/client.go | 13 ++++++++++--- server/etcdserver/api/v3rpc/interceptor.go | 2 +- tests/e2e/ctl_v3_grpc_test.go | 4 ++-- tests/integration/clientv3/grpc_test.go | 4 ++-- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/client/v3/client.go b/client/v3/client.go index 530b0399f690..b7a34c74ba3d 100644 --- a/client/v3/client.go +++ b/client/v3/client.go @@ -297,9 +297,8 @@ func (c *Client) dial(creds grpccredentials.TransportCredentials, dopts ...grpc. dctx, cancel = context.WithTimeout(c.ctx, c.cfg.DialTimeout) defer cancel() // TODO: Is this right for cases where grpc.WithBlock() is not set on the dial options? } - - initialEndpoints := strings.Join(c.Endpoints(), ";") - target := fmt.Sprintf("%s://%p/#initially=[%s]", resolver.Schema, c, initialEndpoints) + // Using "scheme://endpoint/authority" format. Endpoint passed doesn't matter as we are using custom resolver. + target := fmt.Sprintf("%s://%p/%s", resolver.Schema, c, authority(c.endpoints[0])) conn, err := grpc.DialContext(dctx, target, opts...) if err != nil { return nil, err @@ -307,6 +306,14 @@ func (c *Client) dial(creds grpccredentials.TransportCredentials, dopts ...grpc. return conn, nil } +func authority(endpoint string) string { + spl := strings.SplitN(endpoint, "://", 2) + if len(spl) < 2 { + return endpoint + } + return spl[1] +} + func (c *Client) credentialsForEndpoint(ep string) grpccredentials.TransportCredentials { r := endpoint.RequiresCredentials(ep) switch r { diff --git a/server/etcdserver/api/v3rpc/interceptor.go b/server/etcdserver/api/v3rpc/interceptor.go index 97d7b511c351..b56f896d76e0 100644 --- a/server/etcdserver/api/v3rpc/interceptor.go +++ b/server/etcdserver/api/v3rpc/interceptor.go @@ -168,7 +168,7 @@ func logUnaryRequestStats(ctx context.Context, lg *zap.Logger, warnLatency time. reqCount = 1 reqSize = _req.Size() reqContent = pb.NewLoggablePutRequest(_req).String() - // redact value field from request content, see PR #9821 + // redact value field from RequestInfo content, see PR #9821 } if _resp != nil { respCount = 0 diff --git a/tests/e2e/ctl_v3_grpc_test.go b/tests/e2e/ctl_v3_grpc_test.go index afa3e74fa8ed..5d94278e8f9d 100644 --- a/tests/e2e/ctl_v3_grpc_test.go +++ b/tests/e2e/ctl_v3_grpc_test.go @@ -42,7 +42,7 @@ func TestCtlV3AuthoritySingleEndpoint(t *testing.T) { } executeWithTimeout(t, 5*time.Second, func() { - assertAuthority(t, "#initially=[http://localhost:20000]", epc.procs[0].Logs()) + assertAuthority(t, "localhost:20000", epc.procs[0].Logs()) }) assert.NoError(t, epc.Close()) } @@ -65,7 +65,7 @@ func TestCtlV3AuthorityMultipleEndpoints(t *testing.T) { } executeWithTimeout(t, 10*time.Second, func() { - assertAuthority(t, "#initially=[http://localhost:20000;http://localhost:20005;http://localhost:20010]", epc.procs[0].Logs(), epc.procs[1].Logs(), epc.procs[2].Logs()) + assertAuthority(t, "localhost:20000", epc.procs[0].Logs(), epc.procs[1].Logs(), epc.procs[2].Logs()) }) assert.NoError(t, epc.Close()) } diff --git a/tests/integration/clientv3/grpc_test.go b/tests/integration/clientv3/grpc_test.go index 735ca99fd06e..8b6df6f71379 100644 --- a/tests/integration/clientv3/grpc_test.go +++ b/tests/integration/clientv3/grpc_test.go @@ -38,7 +38,7 @@ func TestAuthoritySingleEndpoint(t *testing.T) { } reqs := clus.Members[0].RecordedRequests() - assert.ElementsMatch(t, []v3rpc.RequestInfo{{FullMethod: "/etcdserverpb.KV/Put", Authority: "#initially=[unix://localhost:m00]"}}, reqs) + assert.ElementsMatch(t, []v3rpc.RequestInfo{{FullMethod: "/etcdserverpb.KV/Put", Authority: "localhost:m00"}}, reqs) } func TestAuthorityMultipleEndpoints(t *testing.T) { @@ -62,5 +62,5 @@ func TestAuthorityMultipleEndpoints(t *testing.T) { for _, m := range clus.Members { reqs = append(reqs, m.RecordedRequests()...) } - assert.ElementsMatch(t, []v3rpc.RequestInfo{{FullMethod: "/etcdserverpb.KV/Put", Authority: "#initially=[unix://localhost:m00;unix://localhost:m10;unix://localhost:m20]"}}, reqs) + assert.ElementsMatch(t, []v3rpc.RequestInfo{{FullMethod: "/etcdserverpb.KV/Put", Authority: "localhost:m00"}}, reqs) }