Skip to content

Commit

Permalink
pkg/loop: swap out deprecated grpc API
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 committed Aug 20, 2024
1 parent c0750da commit ea95009
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 25 deletions.
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ require (
github.com/shopspring/decimal v1.4.0
github.com/smartcontractkit/libocr v0.0.0-20240419185742-fd3cab206b2c
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.52.0
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.53.0
go.opentelemetry.io/otel v1.28.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0
go.opentelemetry.io/otel/sdk v1.28.0
go.opentelemetry.io/otel/trace v1.28.0
go.uber.org/goleak v1.3.0
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.25.0
golang.org/x/crypto v0.26.0
golang.org/x/exp v0.0.0-20240716175740-e3f259677ff7
gonum.org/v1/gonum v0.15.0
google.golang.org/grpc v1.65.0
Expand Down Expand Up @@ -77,12 +77,12 @@ require (
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.17.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240820151423-278611b39280 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

Expand Down
13 changes: 13 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ go.opencensus.io v0.23.0 h1:gqCw0LfLxScz8irSi8exQc7fyQ0fKQU/qnC/X8+V/1M=
go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.52.0 h1:vS1Ao/R55RNV4O7TA2Qopok8yN+X0LIP6RVWLFkprck=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.52.0/go.mod h1:BMsdeOxN04K0L5FNUBfjFdvwWGNe/rkmSwH4Aelu/X0=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.53.0 h1:9G6E0TXzGFVfTnawRzrPl83iHOAV7L8NJiR8RSGYV1g=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.53.0/go.mod h1:azvtTADFQJA8mX80jIH/akaE7h+dbm/sVuaHqN13w74=
go.opentelemetry.io/otel v1.28.0 h1:/SqNcYk+idO0CxKEUOtKQClMK/MimZihKYMruSMViUo=
go.opentelemetry.io/otel v1.28.0/go.mod h1:q68ijF8Fc8CnMHKyzqL6akLO46ePnjkgfIMIjUIX9z4=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 h1:3Q/xZUyC1BBkualc9ROb4G8qkH90LXEIICcs5zv1OYY=
Expand All @@ -252,6 +254,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20240716175740-e3f259677ff7 h1:wDLEX9a7YQoKdKNQt88rtydkqDxeGaBUTnIYc3iG/mA=
golang.org/x/exp v0.0.0-20240716175740-e3f259677ff7/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
Expand All @@ -274,6 +278,8 @@ golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLd
golang.org/x/net v0.0.0-20210331212208-0fccb6fa2b5c/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -283,6 +289,7 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand All @@ -301,13 +308,17 @@ golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
Expand All @@ -334,6 +345,8 @@ google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d h1:
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d/go.mod h1:mw8MG/Qz5wfgYr6VqVCiZcHe/GJEfI+oGGDCohaVgB0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d h1:JU0iKnSg02Gmb5ZdV8nYsKEKsP6o/FGVWTrw4i1DA9A=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240820151423-278611b39280 h1:XQMA2e105XNlEZ8NRF0HqnUOZzP14sUSsgL09kpdNnU=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240820151423-278611b39280/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
Expand Down
3 changes: 1 addition & 2 deletions pkg/loop/internal/net/test/simple_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ func (v *Broker) DialWithOptions(id uint32, opts ...grpc.DialOption) (conn *grpc
return nil, fmt.Errorf("listener with id %d does not exist", id)
}
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
//TODO https://smartcontract-it.atlassian.net/browse/BCF-3290
return grpc.Dial(l.Addr().String(), opts...) //nolint:staticcheck
return grpc.NewClient(l.Addr().String(), opts...)
}

// NextId implements net.Broker.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,9 @@ func (lst *loopServerTester) GetConn(t *testing.T) *grpc.ClientConn {
return lst.conn
}

//TODO https://smartcontract-it.atlassian.net/browse/BCF-3290
//nolint:staticcheck
conn, err := grpc.Dial("bufnet",
conn, err := grpc.NewClient("bufnet",
grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) { return lst.lis.Dial() }),
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithBlock())
grpc.WithTransportCredentials(insecure.NewCredentials()))
require.NoError(t, err)
lst.conn = conn
return conn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ func (p *ProviderServer) Close() error {
}

func (p *ProviderServer) GetConn() (grpc.ClientConnInterface, error) {
//TODO https://smartcontract-it.atlassian.net/browse/BCF-3290
cc, err := grpc.Dial(p.lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials())) //nolint:staticcheck
cc, err := grpc.NewClient(p.lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
p.conns = append(p.conns, cc)
return cc, err
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/loop/internal/test/grpc_scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ func NewGRPCScaffold[T Client, S any](t *testing.T, serverFn SetupGRPCServer[S],
require.NoError(t, grpcServer.Serve(lis))
}()

//TODO https://smartcontract-it.atlassian.net/browse/BCF-3290
conn, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials())) //nolint:staticcheck
conn, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
require.NoError(t, err, "failed to dial %s", lis.Addr().String())
t.Cleanup(func() { require.NoError(t, conn.Close(), "failed to close connection") })

Expand Down
10 changes: 3 additions & 7 deletions pkg/loop/telem.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ func SetupTracing(config TracingConfig) (err error) {
creds = insecure.NewCredentials()
}

//TODO https://smartcontract-it.atlassian.net/browse/BCF-3290
//nolint:staticcheck
conn, err := grpc.DialContext(ctx, config.CollectorTarget,
conn, err := grpc.NewClient(config.CollectorTarget,
// Note the potential use of insecure transport here. TLS is recommended in production.
grpc.WithTransportCredentials(creds),
grpc.WithContextDialer(func(ctx context.Context, s string) (net.Conn, error) {
Expand Down Expand Up @@ -146,15 +144,14 @@ func dialOptions(r prometheus.Registerer) []grpc.DialOption {
r.MustRegister(cm)
ctxExemplar := grpcprom.WithExemplarFromContext(exemplarFromContext)
return []grpc.DialOption{
grpc.WithStatsHandler(otelgrpc.NewClientHandler()),
// Order matters e.g. tracing interceptor have to create span first for the later exemplars to work.
grpc.WithChainUnaryInterceptor(
//TODO https://smartcontract-it.atlassian.net/browse/BCF-3290
otelgrpc.UnaryClientInterceptor(), //nolint:staticcheck
cm.UnaryClientInterceptor(ctxExemplar),
),
grpc.WithChainStreamInterceptor(
//TODO https://smartcontract-it.atlassian.net/browse/BCF-3290
otelgrpc.StreamClientInterceptor(), //nolint:staticcheck
cm.StreamClientInterceptor(ctxExemplar),
),
}
Expand All @@ -168,15 +165,14 @@ func newServerFn(r prometheus.Registerer) func(opts []grpc.ServerOption) *grpc.S
r.MustRegister(srvMetrics)
ctxExemplar := grpcprom.WithExemplarFromContext(exemplarFromContext)
interceptors := []grpc.ServerOption{
grpc.StatsHandler(otelgrpc.NewServerHandler()),
// Order matters e.g. tracing interceptor have to create span first for the later exemplars to work.
grpc.ChainUnaryInterceptor(
//TODO https://smartcontract-it.atlassian.net/browse/BCF-3290
otelgrpc.UnaryServerInterceptor(), //nolint:staticcheck
srvMetrics.UnaryServerInterceptor(ctxExemplar),
),
grpc.ChainStreamInterceptor(
//TODO https://smartcontract-it.atlassian.net/browse/BCF-3290
otelgrpc.StreamServerInterceptor(), //nolint:staticcheck
srvMetrics.StreamServerInterceptor(ctxExemplar),
),
}
Expand Down

0 comments on commit ea95009

Please sign in to comment.