Skip to content

Commit

Permalink
chore: update gRPC library and enable shared write buffers
Browse files Browse the repository at this point in the history
Fixes siderolabs#7576

See grpc/grpc-go#6309

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
  • Loading branch information
smira committed Sep 13, 2023
1 parent 9e78fec commit a096f05
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 16 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ require (
golang.org/x/text v0.12.0
golang.org/x/time v0.3.0
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20230429144221-925a1e7659e6
google.golang.org/grpc v1.57.0
google.golang.org/grpc v1.58.0
google.golang.org/protobuf v1.31.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/klog/v2 v2.100.1
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@ github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5y
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/envoyproxy/protoc-gen-validate v0.10.1 h1:c0g45+xCJhdgFGw7a5QAfdS4byAbud7miNWJ1WwEVf8=
github.com/envoyproxy/protoc-gen-validate v0.10.1/go.mod h1:DRjgyB0I43LtJapqN6NiRwroiAU2PaFuvk/vjgh61ss=
github.com/envoyproxy/protoc-gen-validate v1.0.2 h1:QkIBuU5k+x7/QXPvPPnWXWlCdaBFApVqftFV6k087DA=
github.com/envoyproxy/protoc-gen-validate v1.0.2/go.mod h1:GpiZQP3dDbg4JouG/NNS7QWXpgx6x8QiMKdmN72jogE=
github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch v5.6.0+incompatible h1:jBYDEEiFBPxA0v50tFdvOzQQTCvpL6mnFh5mB2/l16U=
github.com/evanphx/json-patch v5.6.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
Expand Down Expand Up @@ -1688,8 +1688,8 @@ google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA5
google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34=
google.golang.org/grpc v1.57.0 h1:kfzNeI/klCGD2YPMUlaGNT3pxvYfga7smW3Vth8Zsiw=
google.golang.org/grpc v1.57.0/go.mod h1:Sd+9RMTACXwmub0zcNY2c4arhtrbBYD1AUHI/dt16Mo=
google.golang.org/grpc v1.58.0 h1:32JY8YpPMSR45K+c3o6b8VL73V+rR8k+DeMIr4vRH8o=
google.golang.org/grpc v1.58.0/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
Expand Down
1 change: 1 addition & 0 deletions internal/app/apid/pkg/backend/apid.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func (a *APID) GetConnection(ctx context.Context, fullMethodName string) (contex
MinConnectTimeout: 20 * time.Second,
}),
grpc.WithCodec(proxy.Codec()), //nolint:staticcheck
grpc.WithSharedWriteBuffer(true),
)

return outCtx, a.conn, err
Expand Down
7 changes: 6 additions & 1 deletion internal/app/machined/pkg/controllers/runtime/events_sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,12 @@ func (ctrl *EventsSinkController) Run(ctx context.Context, r controller.Runtime,
// establish connection
logger.Debug("establishing connection to event sink", zap.String("endpoint", cfg.TypedSpec().Endpoint))

conn, err = grpc.DialContext(ctx, cfg.TypedSpec().Endpoint, grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err = grpc.DialContext(
ctx,
cfg.TypedSpec().Endpoint,
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithSharedWriteBuffer(true),
)
if err != nil {
return fmt.Errorf("error establishing connection to event sink: %w", err)
}
Expand Down
7 changes: 6 additions & 1 deletion internal/app/machined/pkg/controllers/siderolink/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,12 @@ func (ctrl *ManagerController) Run(ctx context.Context, r controller.Runtime, lo
connCtx, connCtxCancel := context.WithTimeout(ctx, 10*time.Second)
defer connCtxCancel()

conn, connErr := grpc.DialContext(connCtx, parsedEndpoint.Host, grpc.WithTransportCredentials(transportCredentials))
conn, connErr := grpc.DialContext(
connCtx,
parsedEndpoint.Host,
grpc.WithTransportCredentials(transportCredentials),
grpc.WithSharedWriteBuffer(true),
)
if connErr != nil {
return nil, fmt.Errorf("error dialing SideroLink endpoint %q: %w", stringEndpoint, connErr)
}
Expand Down
4 changes: 3 additions & 1 deletion internal/app/machined/pkg/system/services/apid.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ func (o *APID) PreFunc(ctx context.Context, r runtime.Runtime) error {
return err
}

o.runtimeServer = grpc.NewServer()
o.runtimeServer = grpc.NewServer(
grpc.SharedWriteBuffer(true),
)
v1alpha1.RegisterStateServer(o.runtimeServer, server.NewState(resources))

go o.runtimeServer.Serve(listener) //nolint:errcheck
Expand Down
4 changes: 3 additions & 1 deletion internal/app/machined/pkg/system/services/trustd.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ func (t *Trustd) PreFunc(ctx context.Context, r runtime.Runtime) error {
return err
}

t.runtimeServer = grpc.NewServer()
t.runtimeServer = grpc.NewServer(
grpc.SharedWriteBuffer(true),
)
v1alpha1.RegisterStateServer(t.runtimeServer, server.NewState(resources))

go t.runtimeServer.Serve(listener) //nolint:errcheck
Expand Down
6 changes: 5 additions & 1 deletion internal/app/trustd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ func trustdMain() error {

var err error

runtimeConn, err := grpc.Dial("unix://"+constants.TrustdRuntimeSocketPath, grpc.WithTransportCredentials(insecure.NewCredentials()))
runtimeConn, err := grpc.Dial(
"unix://"+constants.TrustdRuntimeSocketPath,
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithSharedWriteBuffer(true),
)
if err != nil {
return fmt.Errorf("failed to dial runtime connection: %w", err)
}
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/cri/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func NewClient(endpoint string, connectionTimeout time.Duration) (*Client, error
grpc.WithBackoffMaxDelay(3*time.Second), //nolint:staticcheck
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMsgSize)),
grpc.WithContextDialer(dialer.DialUnix()),
grpc.WithSharedWriteBuffer(true),
)
if err != nil {
return nil, fmt.Errorf("error connecting to CRI: %w", err)
Expand Down
7 changes: 6 additions & 1 deletion internal/pkg/encryption/keys/kms.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,10 @@ func (h *KMSKeyHandler) getConn(ctx context.Context) (*grpc.ClientConn, error) {
transportCredentials = credentials.NewTLS(&tls.Config{})
}

return grpc.DialContext(ctx, endpoint.Host, grpc.WithTransportCredentials(transportCredentials))
return grpc.DialContext(
ctx,
endpoint.Host,
grpc.WithTransportCredentials(transportCredentials),
grpc.WithSharedWriteBuffer(true),
)
}
2 changes: 1 addition & 1 deletion internal/pkg/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func NewClient(ctx context.Context, endpoints []string, dialOpts ...grpc.DialOpt
Endpoints: endpoints,
DialTimeout: 5 * time.Second,
Context: ctx,
DialOptions: dialOpts,
DialOptions: append(dialOpts, grpc.WithSharedWriteBuffer(true)),
TLS: tlsConfig,
Logger: zap.NewNop(),
})
Expand Down
1 change: 1 addition & 0 deletions pkg/grpc/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ func NewDefaultOptions(setters ...Option) *Options {
grpc.InitialConnWindowSize(65535*16),
grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(opts.UnaryInterceptors...)),
grpc.StreamInterceptor(grpc_middleware.ChainStreamServer(opts.StreamInterceptors...)),
grpc.SharedWriteBuffer(true),
)

return opts
Expand Down
1 change: 1 addition & 0 deletions pkg/grpc/middleware/auth/basic/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func NewConnection(address string, creds credentials.PerRPCCredentials, ca *x509
grpcOpts := []grpc.DialOption{
grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig)),
grpc.WithPerRPCCredentials(creds),
grpc.WithSharedWriteBuffer(true),
}

conn, err = grpc.Dial(address, grpcOpts...)
Expand Down
2 changes: 1 addition & 1 deletion pkg/grpc/proxy/backend/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (l *Local) GetConnection(ctx context.Context, fullMethodName string) (conte
"unix:"+l.socketPath,
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithCodec(proxy.Codec()), //nolint:staticcheck

grpc.WithSharedWriteBuffer(true),
)

return outCtx, l.conn, err
Expand Down
1 change: 1 addition & 0 deletions pkg/machinery/client/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func (c *Client) getConn(ctx context.Context, opts ...grpc.DialOption) (*grpcCon
// grpc.UseCompressor(gzip.Name),
grpc.MaxCallRecvMsgSize(constants.GRPCMaxMessageSize),
),
grpc.WithSharedWriteBuffer(true),
}
dialOpts = append(dialOpts, c.options.grpcDialOptions...)
dialOpts = append(dialOpts, opts...)
Expand Down
2 changes: 1 addition & 1 deletion pkg/machinery/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
github.com/siderolabs/protoenc v0.2.0
github.com/stretchr/testify v1.8.4
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d
google.golang.org/grpc v1.57.0
google.golang.org/grpc v1.58.0
google.golang.org/protobuf v1.31.0
gopkg.in/yaml.v3 v3.0.1
)
Expand Down
4 changes: 2 additions & 2 deletions pkg/machinery/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ google.golang.org/genproto/googleapis/api v0.0.0-20230726155614-23370e0ffb3e h1:
google.golang.org/genproto/googleapis/api v0.0.0-20230726155614-23370e0ffb3e/go.mod h1:rsr7RhLuwsDKL7RmgDDCUc6yaGr1iqceVb5Wv6f6YvQ=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d h1:uvYuEyMHKNt+lT4K3bN6fGswmK8qSvcreM3BwjDh+y4=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M=
google.golang.org/grpc v1.57.0 h1:kfzNeI/klCGD2YPMUlaGNT3pxvYfga7smW3Vth8Zsiw=
google.golang.org/grpc v1.57.0/go.mod h1:Sd+9RMTACXwmub0zcNY2c4arhtrbBYD1AUHI/dt16Mo=
google.golang.org/grpc v1.58.0 h1:32JY8YpPMSR45K+c3o6b8VL73V+rR8k+DeMIr4vRH8o=
google.golang.org/grpc v1.58.0/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
Expand Down

0 comments on commit a096f05

Please sign in to comment.