From 981d24a493b2ede319e1d376308d7e206fe2c1b0 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Thu, 8 Jun 2023 15:54:48 +0300 Subject: [PATCH] [#84] pool: Allow to pass gRPC dial options Signed-off-by: Denis Kirillov --- pool/pool.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pool/pool.go b/pool/pool.go index d94f81b..b56c574 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -32,6 +32,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "go.uber.org/zap" "go.uber.org/zap/zapcore" + "google.golang.org/grpc" ) // client represents virtual connection to the single FrostFS network endpoint from which Pool is formed. @@ -238,6 +239,7 @@ type wrapperPrm struct { errorThreshold uint32 responseInfoCallback func(sdkClient.ResponseMetaInfo) error poolRequestInfoCallback func(RequestInfo) + dialOptions []grpc.DialOption } // setAddress sets endpoint to connect in FrostFS network. @@ -276,6 +278,11 @@ func (x *wrapperPrm) setResponseInfoCallback(f func(sdkClient.ResponseMetaInfo) x.responseInfoCallback = f } +// setGRPCDialOptions sets the gRPC dial options for new gRPC client connection. +func (x *wrapperPrm) setGRPCDialOptions(opts []grpc.DialOption) { + x.dialOptions = opts +} + // newWrapper creates a clientWrapper that implements the client interface. func newWrapper(prm wrapperPrm) *clientWrapper { var cl sdkClient.Client @@ -307,6 +314,7 @@ func (c *clientWrapper) dial(ctx context.Context) error { prmDial.SetServerURI(c.prm.address) prmDial.SetTimeout(c.prm.dialTimeout) prmDial.SetStreamTimeout(c.prm.streamTimeout) + prmDial.SetGRPCDialOptions(c.prm.dialOptions...) if err = cl.Dial(ctx, prmDial); err != nil { c.setUnhealthy() @@ -337,6 +345,7 @@ func (c *clientWrapper) restartIfUnhealthy(ctx context.Context) (healthy, change prmDial.SetServerURI(c.prm.address) prmDial.SetTimeout(c.prm.dialTimeout) prmDial.SetStreamTimeout(c.prm.streamTimeout) + prmDial.SetGRPCDialOptions(c.prm.dialOptions...) if err := cl.Dial(ctx, prmDial); err != nil { c.setUnhealthy() @@ -1054,6 +1063,7 @@ type InitParameters struct { errorThreshold uint32 nodeParams []NodeParam requestCallback func(RequestInfo) + dialOptions []grpc.DialOption clientBuilder clientBuilder } @@ -1113,6 +1123,11 @@ func (x *InitParameters) AddNode(nodeParam NodeParam) { x.nodeParams = append(x.nodeParams, nodeParam) } +// SetGRPCDialOptions sets the gRPC dial options for new gRPC client connection. +func (x *InitParameters) SetGRPCDialOptions(opts ...grpc.DialOption) { + x.dialOptions = opts +} + // setClientBuilder sets clientBuilder used for client construction. // Wraps setClientBuilderContext without a context. func (x *InitParameters) setClientBuilder(builder clientBuilder) { @@ -1735,6 +1750,7 @@ func fillDefaultInitParams(params *InitParameters, cache *sessionCache) { prm.setStreamTimeout(params.nodeStreamTimeout) prm.setErrorThreshold(params.errorThreshold) prm.setPoolRequestCallback(params.requestCallback) + prm.setGRPCDialOptions(params.dialOptions) prm.setResponseInfoCallback(func(info sdkClient.ResponseMetaInfo) error { cache.updateEpoch(info.Epoch()) return nil