From 6f64557a4bf57d69aafe010cb8f0d05a8b572c07 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 14 Jun 2023 11:27:33 +0300 Subject: [PATCH] [#60] Use gRPC interceptor from observability package Previous SDK implementation had implicit gRPC interceptor for tracing. Now pool constructors allow any dial options, so gateway should manually pass tracing interceptors from observability package. Signed-off-by: Alex Vanin --- settings.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/settings.go b/settings.go index eec014c..3b2cba9 100644 --- a/settings.go +++ b/settings.go @@ -13,6 +13,7 @@ import ( "time" "git.frostfs.info/TrueCloudLab/frostfs-http-gw/resolver" + grpctracing "git.frostfs.info/TrueCloudLab/frostfs-observability/tracing/grpc" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/pool" treepool "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/pool/tree" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" @@ -454,6 +455,19 @@ func getPools(ctx context.Context, logger *zap.Logger, cfg *viper.Viper) (*pool. prm.SetLogger(logger) prmTree.SetLogger(logger) + var apiGRPCDialOpts []grpc.DialOption + var treeGRPCDialOpts = []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())} + if cfg.GetBool(cfgTracingEnabled) { + interceptors := []grpc.DialOption{ + grpc.WithUnaryInterceptor(grpctracing.NewUnaryClientInteceptor()), + grpc.WithStreamInterceptor(grpctracing.NewStreamClientInterceptor()), + } + treeGRPCDialOpts = append(treeGRPCDialOpts, interceptors...) + apiGRPCDialOpts = append(apiGRPCDialOpts, interceptors...) + } + prm.SetGRPCDialOptions(apiGRPCDialOpts...) + prmTree.SetGRPCDialOptions(treeGRPCDialOpts...) + p, err := pool.NewPool(prm) if err != nil { logger.Fatal("failed to create connection pool", zap.Error(err)) @@ -463,7 +477,6 @@ func getPools(ctx context.Context, logger *zap.Logger, cfg *viper.Viper) (*pool. logger.Fatal("failed to dial connection pool", zap.Error(err)) } - prmTree.SetGRPCDialOptions(grpc.WithTransportCredentials(insecure.NewCredentials())) treePool, err := treepool.NewPool(prmTree) if err != nil { logger.Fatal("failed to create tree pool", zap.Error(err))