Migrate from grpc.Dial to grpc.NewClient
yurishkuro opened this issue · comments
In 1.63.x grpc.Dial
is being replaced with grpc.NewClient
that does not attempt to make a connection. Need to make code fixes to use the new API.
This was originally breaking dependabot PR #5327, but gRPC later un-deprecated the Dial functions. Still, they will likely be deprecated in the future releases, so we need to migrate.
This was partially addressed in one of the PRs, but several places still remain:
$ grep -nr 'TODO.*grpc.Dial'
./cmd/query/app/grpc_handler_test.go:179: // TODO: Need to replace grpc.DialContext with grpc.NewClient and pass test
./cmd/query/app/server_test.go:424: // TODO: Need to replace grpc.DialContext with grpc.NewClient and pass test
./cmd/query/app/server_test.go:427: // TODO: Need to replace grpc.DialContext with grpc.NewClient and pass test
./plugin/storage/grpc/config/config.go:121: // TODO: Need to replace grpc.DialContext with grpc.NewClient and pass test
Validation:
- make test
working on it
It looks like this requires replacing grpc.Dial
and grpc.DialContext
with grpc.NewClient
.
There are two problems encountered during the replacement process:
-
grpc.NewClient
will ignoreWithTimeout
DialOption. (https://pkg.go.dev/google.golang.org/grpc#NewClient) How can I solve the problem aboutgrpc.DialContext
(or any possible solutions?)
here is example
jaeger/cmd/anonymizer/app/query/query.go
Lines 41 to 44 in 8a4748c
-
In
cmd/agent/app/configmanager/grpc/manager_test.go
Line 51 if I replacegrpc.Dial
withgrpc.NewClient
, should I change Line 58?
=== RUN TestSamplingManager_GetSamplingStrategy_error
manager_test.go:58:
Error Trace: /Users/jerry/working/jaeger/cmd/agent/app/configmanager/grpc/manager_test.go:58
Error: "rpc error: code = Unavailable desc = name resolver error: produced zero addresses" does not contain "Error while diali
ng: dial tcp: address foo: missing port in address"
Test: TestSamplingManager_GetSamplingStrategy_error
--- ❌ FAIL: TestSamplingManager_GetSamplingStrategy_error (0.32s)
jaeger/cmd/agent/app/configmanager/grpc/manager_test.go
Lines 50 to 59 in 8a4748c
Can you find docs, tickets, or changelog that explains why they replaced Dial with NewClient and what migration path is suggested?
I have searched for the relevant documents as far as I can.
- 2018's issue: grpc/grpc-go#1786
grpc-go
anti-pattern: https://github.com/grpc/grpc-go/blob/master/Documentation/anti-patterns.md- grpc/grpc-go#7010
Unfortunately, I didn't find any information about the migration path, and other grpc-go
users weren't notified either.
- No mention in the 1.63.0 release note grpc/grpc-go#7090
- The relevant documents are still being updated. grpc/grpc-go#7049
The existing docs do say that WithTimeout should not be used, so it's safe to refactor to use NewClient and drop the timeouts handling during that phase.
To your second question about the error string, my preference for testing errors like that is to wrap them in the business logic, e.g. return fmt.Errorf("our internal message/explanation: %w", err)
and then the test should only match on our part of the error string, not on what comes from the library (which could change across versions, as happens this time)
The current grpc-go
version v1.63.x removes the deprecated tags from Dial
and DialContext
.
CI has been passed.
But grpc-go
will add back the deprecated tag in v1.64, I will continue to study how to remove Dial
and DialContext
to NewClient
and fix the related test cases.
May be worth splitting your pr into pieces that are known to work ( verify via go test on individual packages)
I can change the parts that don't affect the test first, and I'll mark TODO
for the others that don't.