Skip to content

Change gRPC client code to use grpc.NewClient #738

@nadiamoe

Description

@nadiamoe

grpc.Dial and grpc.DialContext are deprecated, although they will be supported throughout v1.x.x.

We use this to dial the API gRPC server during the agent initialization. The suggested way to do this is to replace this:

return grpc.DialContext(ctx, addr, opts...)

With something such as:

return grpc.NewClient(addr, opts...)

Or:

con, err := grpc.NewClient(addr, opts...)
if err != nil {
    return nil, fmt.Errorf("building client: %w", err)
}
con.Connect() // Although this does not block waiting for conn, and therefore never returns error
return con, nil

But this modifies our current behavior where we block and force the connection with the API before returning from the dialAPIServer function. This seems to be an anti pattern and we should just expect the connection to be established during the first rpc call, and be able to handle connection errors as a result of that call, which I believe we already do.
So, we can probably remove the blocking behavior from main and just expect the first gRPC service call to connect, because the agent will try to fetch data from the API when starting, that will happen early when initializing also, but I'm keeping this PR open by now to review this better.

Originally posted by @ka3de in #671 (comment)

Introduced in: #706

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions