Skip to content
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

Use withResolver API in gRPC reporter #3078

Merged
merged 4 commits into from
Jun 11, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions cmd/agent/app/reporter/grpc/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ func (b *ConnBuilder) CreateConnection(logger *zap.Logger, mFactory metrics.Fact
return nil, errors.New("at least one collector hostPort address is required when resolver is not available")
}
if len(b.CollectorHostPorts) > 1 {
r, _ := generateAndRegisterManualResolver()
r := manual.NewBuilderWithScheme(strconv.FormatInt(time.Now().UnixNano(), 36))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can somebody explain why are we using a random scheme and what it does?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/grpc/grpc-go/blob/master/dialoptions.go#L609

will be matched against the current scheme...

Is the random scheme to prevent it from ever being matched? Can this code just be removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the test suite failed when I didn't call WithResolvers.

Copy link
Member

@joe-elliott joe-elliott Jun 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, not 100% sure but i've done some code diving:

https://github.com/grpc/grpc-go/blob/b1f7648a9fc72ce76cbcd42d8e2c60d9d9bed9fc/clientconn.go#L251

when the dialer wants to choose its resolver it looks for one matching the scheme of the target. On this line we're just using the resolver scheme when creating the target:

dialTarget = r.Scheme() + ":///round_robin"

This basically guarantees that our target scheme lines up with the resolver scheme and the right resolver is chosen. I believe it's a random number so it never conflicts with a "real resolver":

https://github.com/grpc/grpc-go/blob/master/internal/resolver/passthrough/passthrough.go#L25
https://github.com/grpc/grpc-go/blob/master/internal/resolver/dns/dns_resolver.go#L158

We could leave it as a random number or we could change it to something like jaeger_manual if we're feeling fancy.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's feel fancy in this case, I like the predictability :)

dialOptions = append(dialOptions, grpc.WithResolvers(r))
var resolvedAddrs []resolver.Address
for _, addr := range b.CollectorHostPorts {
resolvedAddrs = append(resolvedAddrs, resolver.Address{Addr: addr})
Expand Down Expand Up @@ -125,12 +126,3 @@ func (b *ConnBuilder) CreateConnection(logger *zap.Logger, mFactory metrics.Fact

return conn, nil
}

// generateAndRegisterManualResolver was removed from grpc.
// Copied here to keep behavior the same.
func generateAndRegisterManualResolver() (*manual.Resolver, func()) {
scheme := strconv.FormatInt(time.Now().UnixNano(), 36)
r := manual.NewBuilderWithScheme(scheme)
resolver.Register(r)
return r, func() { resolver.UnregisterForTesting(scheme) }
}