-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
balancer: set RPC metadata in address attributes, instead of Metadata field #4041
Conversation
… instead of Metadata field This metadata will be sent with all RPCs on the created SubConn
83fe271
to
3330db0
Compare
@@ -164,7 +162,7 @@ func (lb *lbBalancer) refreshSubConns(backendAddrs []resolver.Address, fallback | |||
// Create new SubConns. | |||
for _, addr := range backendAddrs { | |||
addrWithoutMD := addr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/MD/Attributes/ (or Attrs)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
balancer/grpclb/grpclb_util.go
Outdated
@@ -125,7 +125,7 @@ func (ccc *lbCacheClientConn) NewSubConn(addrs []resolver.Address, opts balancer | |||
return nil, fmt.Errorf("grpclb calling NewSubConn with addrs of length %v", len(addrs)) | |||
} | |||
addrWithoutMD := addrs[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
internal/metadata/metadata.go
Outdated
if !ok { | ||
return nil | ||
} | ||
return md |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just return md, ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need ok
. Just return md
should work.
internal/metadata/metadata.go
Outdated
if addr.Attributes == nil { | ||
addr.Attributes = attributes.New(mdKey, md) | ||
return addr | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be deleted, as WithValues
handles a nil
receiver.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
test/balancer_test.go
Outdated
r := manual.NewBuilderWithScheme("whatever") | ||
t.Logf("Registered manual resolver with scheme %s...", r.Scheme()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this registering? It doesn't need to (WithResolvers
) right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not registered. So we will need WithResolvers
. Removed this line.
test/balancer_test.go
Outdated
select { | ||
case <-testMDChan: | ||
default: | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed. Made it a switch with context.Done().
test/balancer_test.go
Outdated
@@ -601,6 +598,7 @@ func (s) TestMetadataInAddressAttributes(t *testing.T) { | |||
} | |||
defer ss.Stop() | |||
|
|||
r := manual.NewBuilderWithScheme("whatever") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you know? You can inject this into the stubserver and Dial
will use it:
Lines 5197 to 5200 in 230166b
if ss.r != nil { | |
ss.target = ss.r.Scheme() + ":///" + ss.address | |
opts = append(opts, grpc.WithResolvers(ss.r)) | |
} |
Maybe we should delete that feature since it seems to be well hidden and nonobvious? Or you should use it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I knew it. But you cannot set balancer/init service config.
I didn't want to add all the fields just to pass the dial options.
I'm OK with removing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not seeing where your test needs to set balancer/init service config, though. You are using a default service config, and then doing the same resolver update that stubServer would do automatically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm dumb. I need to set the balancer in init service config, to use the balancer that sets the attributes. But ss.Start
works. Fixed now. (But github hates me?)
… field (grpc#4041) This metadata will be sent with all RPCs on the created SubConn
This metadata will be sent with all RPCs on the created SubConn