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

Migrate from grpc.Dial to grpc.NewClient #5330

Closed
yurishkuro opened this issue Apr 5, 2024 · 9 comments · Fixed by #5443
Closed

Migrate from grpc.Dial to grpc.NewClient #5330

yurishkuro opened this issue Apr 5, 2024 · 9 comments · Fixed by #5443
Labels
good first issue Good for beginners help wanted Features that maintainers are willing to accept but do not have cycles to implement

Comments

@yurishkuro
Copy link
Member

yurishkuro commented Apr 5, 2024

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.

(Update) The only remaining place is

./cmd/jaeger/internal/integration/span_reader.go:45:	cc, err := grpc.DialContext(ctx, ports.PortToHostPort(port), opts...)

Validation:

  • make test
@yurishkuro yurishkuro added help wanted Features that maintainers are willing to accept but do not have cycles to implement good first issue Good for beginners labels Apr 5, 2024
@danish9039
Copy link
Contributor

working on it

@tico88612
Copy link
Contributor

It looks like this requires replacing grpc.Dial and grpc.DialContext with grpc.NewClient.

There are two problems encountered during the replacement process:

  1. grpc.NewClient will ignore WithTimeout DialOption. (https://pkg.go.dev/google.golang.org/grpc#NewClient) How can I solve the problem about grpc.DialContext (or any possible solutions?)
    here is example

    ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
    defer cancel()
    conn, err := grpc.DialContext(ctx, addr, grpc.WithTransportCredentials(insecure.NewCredentials()))

  2. In cmd/agent/app/configmanager/grpc/manager_test.go Line 51 if I replace grpc.Dial with grpc.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)

func TestSamplingManager_GetSamplingStrategy_error(t *testing.T) {
conn, err := grpc.Dial("foo", grpc.WithTransportCredentials(insecure.NewCredentials()))
defer close(t, conn)
require.NoError(t, err)
manager := NewConfigManager(conn)
resp, err := manager.GetSamplingStrategy(context.Background(), "any")
require.Nil(t, resp)
require.Error(t, err)
assert.Contains(t, err.Error(), "Error while dialing: dial tcp: address foo: missing port in address")
}

@yurishkuro
Copy link
Member Author

Can you find docs, tickets, or changelog that explains why they replaced Dial with NewClient and what migration path is suggested?

@tico88612
Copy link
Contributor

tico88612 commented Apr 6, 2024

I have searched for the relevant documents as far as I can.

Unfortunately, I didn't find any information about the migration path, and other grpc-go users weren't notified either.

@yurishkuro
Copy link
Member Author

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)

@tico88612
Copy link
Contributor

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.

@yurishkuro
Copy link
Member Author

May be worth splitting your pr into pieces that are known to work ( verify via go test on individual packages)

@tico88612
Copy link
Contributor

I can change the parts that don't affect the test first, and I'll mark TODO for the others that don't.

yurishkuro pushed a commit that referenced this issue Apr 9, 2024
…v1.64 (#5336)

## Which problem is this PR solving?
- Related #5330 

## Description of the changes
- Partial replace deprecated function in `grpc-go@v1.64`
  - `grpc.Dial` => `grpc.NewClient`
  - `grpc.DialContext` => `grpc.NewClient`
- FYI:
#5330 (comment)
- Refactor configmanager GetSamplingStrategy business logic
  - Fixed related test

## How was this change tested?
- make lint
- make test
- Try & Error

## Checklist
- [x] I have read
https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md
- [x] I have signed all commits
- [x] I have added unit tests for the new functionality
- [x] I have run lint and test steps successfully
  - for `jaeger`: `make lint test`
  - for `jaeger-ui`: `yarn lint` and `yarn test`

---------

Signed-off-by: tico88612 <17496418+tico88612@users.noreply.github.com>
@yurishkuro yurishkuro changed the title Upgrade google.golang.org 1.63.0 Upgrade google.golang.org 1.63.x Apr 28, 2024
@yurishkuro yurishkuro changed the title Upgrade google.golang.org 1.63.x Migrate from grpc.Dial to grpc.NewClient Apr 28, 2024
varshith257 pushed a commit to varshith257/jaeger that referenced this issue May 3, 2024
…v1.64 (jaegertracing#5336)

## Which problem is this PR solving?
- Related jaegertracing#5330 

## Description of the changes
- Partial replace deprecated function in `grpc-go@v1.64`
  - `grpc.Dial` => `grpc.NewClient`
  - `grpc.DialContext` => `grpc.NewClient`
- FYI:
jaegertracing#5330 (comment)
- Refactor configmanager GetSamplingStrategy business logic
  - Fixed related test

## How was this change tested?
- make lint
- make test
- Try & Error

## Checklist
- [x] I have read
https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md
- [x] I have signed all commits
- [x] I have added unit tests for the new functionality
- [x] I have run lint and test steps successfully
  - for `jaeger`: `make lint test`
  - for `jaeger-ui`: `yarn lint` and `yarn test`

---------

Signed-off-by: tico88612 <17496418+tico88612@users.noreply.github.com>
Signed-off-by: Vamshi Maskuri <gwcchintu@gmail.com>
yurishkuro added a commit that referenced this issue May 11, 2024
## Which problem is this PR solving?
- Part of #5330

## Description of the changes
- use grpc.NewClient
- add extra test

## How was this change tested?
- CI

---------

Signed-off-by: Yuri Shkuro <github@ysh.us>
@yurishkuro
Copy link
Member Author

Last one #5443

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for beginners help wanted Features that maintainers are willing to accept but do not have cycles to implement
Projects
None yet
3 participants