From 02454df14a54d6e51e5f454ad1dcbaf65ddf2147 Mon Sep 17 00:00:00 2001 From: aarifullin Date: Wed, 15 Nov 2023 15:28:45 +0300 Subject: [PATCH] [#809] client: Refactor PrmInit, PrmDial usage Signed-off-by: Airat Arifullin --- cmd/frostfs-cli/internal/client/sdk.go | 26 ++++++++------- go.mod | 2 +- go.sum | Bin 328127 -> 328127 bytes pkg/network/cache/multi.go | 44 ++++++++++++------------- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/cmd/frostfs-cli/internal/client/sdk.go b/cmd/frostfs-cli/internal/client/sdk.go index 6923e4f1..b3e04e5f 100644 --- a/cmd/frostfs-cli/internal/client/sdk.go +++ b/cmd/frostfs-cli/internal/client/sdk.go @@ -43,26 +43,28 @@ func getSDKClientByFlag(cmd *cobra.Command, key *ecdsa.PrivateKey, endpointFlag // GetSDKClient returns default frostfs-sdk-go client. func GetSDKClient(ctx context.Context, cmd *cobra.Command, key *ecdsa.PrivateKey, addr network.Address) (*client.Client, error) { - var ( - c client.Client - prmInit client.PrmInit - prmDial client.PrmDial - ) + var c client.Client - prmInit.SetDefaultPrivateKey(*key) - prmDial.SetServerURI(addr.URIAddr()) + prmInit := client.PrmInit{ + Key: *key, + } + + prmDial := client.PrmDial{ + Endpoint: addr.URIAddr(), + GRPCDialOptions: []grpc.DialOption{ + grpc.WithChainUnaryInterceptor(tracing.NewUnaryClientInteceptor()), + grpc.WithChainStreamInterceptor(tracing.NewStreamClientInterceptor()), + }, + } if timeout := viper.GetDuration(commonflags.Timeout); timeout > 0 { // In CLI we can only set a timeout for the whole operation. // By also setting stream timeout we ensure that no operation hands // for too long. - prmDial.SetTimeout(timeout) - prmDial.SetStreamTimeout(timeout) + prmDial.DialTimeout = timeout + prmDial.StreamTimeout = timeout common.PrintVerbose(cmd, "Set request timeout to %s.", timeout) } - prmDial.SetGRPCDialOptions( - grpc.WithChainUnaryInterceptor(tracing.NewUnaryClientInteceptor()), - grpc.WithChainStreamInterceptor(tracing.NewStreamClientInterceptor())) c.Init(prmInit) diff --git a/go.mod b/go.mod index 120c05ff..7d2b9348 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.16.1-0.20231031104748-498877e378fd git.frostfs.info/TrueCloudLab/frostfs-contract v0.18.1-0.20231102065436-9ed3845aa989 git.frostfs.info/TrueCloudLab/frostfs-observability v0.0.0-20231101111734-b3ad3335ff65 - git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20231101144515-6fbe1595cb3d + git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20231114081800-3787477133f3 git.frostfs.info/TrueCloudLab/hrw v1.2.1 git.frostfs.info/TrueCloudLab/policy-engine v0.0.0-20231115094736-5db67021e10f git.frostfs.info/TrueCloudLab/tzhash v1.8.0 diff --git a/go.sum b/go.sum index 642280d950819800aadc41301fdbb7cf79ff5dc8..070c246ba1595a068387a9c154e33e718a84fd62 100644 GIT binary patch delta 125 zcmdnrEV92@q+tu=Ty7Ub69WrF3j+gPV{;306LWJzW8*Yqg$zThz(ixyBqvjgf*ju@ zLlYm*;>fB}qs*k#$h6`}qmo3oyrihgk}^xjd}H6~iQJ4fqF7C8H{xLgVkRJF-fqOh H()$$v21X-Y delta 124 zcmdnrEV92@q+tu=TyAFrLqii2Q$tf-v$UjCLsLuBp?mpVR>Nw7kmn5|gCl(7+<+^nmFJ+>ExOSPg17;$Z}0CLm_sZp6dV G`xO93E+nY{ diff --git a/pkg/network/cache/multi.go b/pkg/network/cache/multi.go index c9b13826..5dd20628 100644 --- a/pkg/network/cache/multi.go +++ b/pkg/network/cache/multi.go @@ -51,42 +51,40 @@ func newMultiClient(addr network.AddressGroup, opts ClientCacheOpts) *multiClien } func (x *multiClient) createForAddress(ctx context.Context, addr network.Address) (clientcore.Client, error) { - var ( - c client.Client - prmInit client.PrmInit - prmDial client.PrmDial - ) - - prmInit.DisableFrostFSFailuresResolution() - prmDial.SetServerURI(addr.URIAddr()) + var c client.Client + prmInit := client.PrmInit{ + DisableFrostFSErrorResolution: true, + } if x.opts.Key != nil { - prmInit.SetDefaultPrivateKey(*x.opts.Key) + prmInit.Key = *x.opts.Key } + prmDial := client.PrmDial{ + Endpoint: addr.URIAddr(), + GRPCDialOptions: []grpc.DialOption{ + grpc.WithChainUnaryInterceptor( + metrics.NewUnaryClientInterceptor(), + tracing.NewUnaryClientInteceptor(), + ), + grpc.WithChainStreamInterceptor( + metrics.NewStreamClientInterceptor(), + tracing.NewStreamClientInterceptor(), + ), + }, + } if x.opts.DialTimeout > 0 { - prmDial.SetTimeout(x.opts.DialTimeout) + prmDial.DialTimeout = x.opts.DialTimeout } if x.opts.StreamTimeout > 0 { - prmDial.SetStreamTimeout(x.opts.StreamTimeout) + prmDial.StreamTimeout = x.opts.StreamTimeout } if x.opts.ResponseCallback != nil { - prmInit.SetResponseInfoCallback(x.opts.ResponseCallback) + prmInit.ResponseInfoCallback = x.opts.ResponseCallback } - prmDial.SetGRPCDialOptions( - grpc.WithChainUnaryInterceptor( - metrics.NewUnaryClientInterceptor(), - tracing.NewUnaryClientInteceptor(), - ), - grpc.WithChainStreamInterceptor( - metrics.NewStreamClientInterceptor(), - tracing.NewStreamClientInterceptor(), - ), - ) - c.Init(prmInit) err := c.Dial(ctx, prmDial) if err != nil {