Skip to content

Commit

Permalink
client: [Draft] Use first endpoint as target so authority has correct…
Browse files Browse the repository at this point in the history
… format

This doesn't fully fix authority as in multiple endpoint scenario,
authority is taken from first endpoint instead of being based on
endpoint called.

Not sure why Authority header has "/" prefix, should figure out where it
comes from.
  • Loading branch information
serathius committed Sep 17, 2021
1 parent 8a74d7d commit 15f87be
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
3 changes: 1 addition & 2 deletions client/v3/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,7 @@ func (c *Client) dial(creds grpccredentials.TransportCredentials, dopts ...grpc.
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)
target := fmt.Sprintf("%s://%s/", resolver.Schema, c.endpoints[0])
conn, err := grpc.DialContext(dctx, target, opts...)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion server/etcdserver/api/v3rpc/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/ctl_v3_grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand All @@ -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())
}
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/clientv3/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}

0 comments on commit 15f87be

Please sign in to comment.