From af40dc68f005778c5452e9b5255e25ebeb6c719d Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Thu, 8 Jun 2023 15:55:07 +0300 Subject: [PATCH] [#84] pool/tree: Allow to pass gRPC dial options Signed-off-by: Denis Kirillov --- pool/tree/pool.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pool/tree/pool.go b/pool/tree/pool.go index 3c6cdff..171a627 100644 --- a/pool/tree/pool.go +++ b/pool/tree/pool.go @@ -17,7 +17,6 @@ import ( "go.uber.org/zap" "go.uber.org/zap/zapcore" "google.golang.org/grpc" - "google.golang.org/grpc/credentials/insecure" ) const ( @@ -57,6 +56,7 @@ type InitParameters struct { healthcheckTimeout time.Duration clientRebalanceInterval time.Duration nodeParams []pool.NodeParam + dialOptions []grpc.DialOption } // Pool represents virtual connection to the FrostFS tree services network to communicate @@ -72,6 +72,7 @@ type Pool struct { cancel context.CancelFunc closedCh chan struct{} rebalanceParams rebalanceParameters + dialOptions []grpc.DialOption logger *zap.Logger startIndicesMtx sync.RWMutex @@ -165,8 +166,9 @@ func NewPool(options InitParameters) (*Pool, error) { fillDefaultInitParams(&options) p := &Pool{ - key: options.key, - logger: options.logger, + key: options.key, + logger: options.logger, + dialOptions: options.dialOptions, rebalanceParams: rebalanceParameters{ nodesGroup: nodesParams, nodeRequestTimeout: options.healthcheckTimeout, @@ -192,7 +194,7 @@ func (p *Pool) Dial(ctx context.Context) error { for i, nodes := range p.rebalanceParams.nodesGroup { clients := make([]client, len(nodes)) for j, node := range nodes { - clients[j] = newTreeClient(node.Address(), grpc.WithTransportCredentials(insecure.NewCredentials())) + clients[j] = newTreeClient(node.Address(), p.dialOptions...) if err := clients[j].dial(ctx); err != nil { p.log(zap.WarnLevel, "failed to build client", zap.String("address", node.Address()), zap.Error(err)) continue @@ -258,6 +260,11 @@ func (x *InitParameters) AddNode(nodeParam pool.NodeParam) { x.nodeParams = append(x.nodeParams, nodeParam) } +// SetGRPCDialOptions sets the gRPC dial options for new gRPC tree client connection. +func (x *InitParameters) SetGRPCDialOptions(opts ...grpc.DialOption) { + x.dialOptions = opts +} + // GetNodes invokes eponymous method from TreeServiceClient. // // Can return predefined errors: