forked from TrueCloudLab/frostfs-node
[#809] client: Refactor PrmInit, PrmDial usage
Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
This commit is contained in:
parent
76ff26039c
commit
02454df14a
4 changed files with 38 additions and 38 deletions
|
@ -43,26 +43,28 @@ func getSDKClientByFlag(cmd *cobra.Command, key *ecdsa.PrivateKey, endpointFlag
|
||||||
|
|
||||||
// GetSDKClient returns default frostfs-sdk-go client.
|
// GetSDKClient returns default frostfs-sdk-go client.
|
||||||
func GetSDKClient(ctx context.Context, cmd *cobra.Command, key *ecdsa.PrivateKey, addr network.Address) (*client.Client, error) {
|
func GetSDKClient(ctx context.Context, cmd *cobra.Command, key *ecdsa.PrivateKey, addr network.Address) (*client.Client, error) {
|
||||||
var (
|
var c client.Client
|
||||||
c client.Client
|
|
||||||
prmInit client.PrmInit
|
|
||||||
prmDial client.PrmDial
|
|
||||||
)
|
|
||||||
|
|
||||||
prmInit.SetDefaultPrivateKey(*key)
|
prmInit := client.PrmInit{
|
||||||
prmDial.SetServerURI(addr.URIAddr())
|
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 {
|
if timeout := viper.GetDuration(commonflags.Timeout); timeout > 0 {
|
||||||
// In CLI we can only set a timeout for the whole operation.
|
// In CLI we can only set a timeout for the whole operation.
|
||||||
// By also setting stream timeout we ensure that no operation hands
|
// By also setting stream timeout we ensure that no operation hands
|
||||||
// for too long.
|
// for too long.
|
||||||
prmDial.SetTimeout(timeout)
|
prmDial.DialTimeout = timeout
|
||||||
prmDial.SetStreamTimeout(timeout)
|
prmDial.StreamTimeout = timeout
|
||||||
|
|
||||||
common.PrintVerbose(cmd, "Set request timeout to %s.", timeout)
|
common.PrintVerbose(cmd, "Set request timeout to %s.", timeout)
|
||||||
}
|
}
|
||||||
prmDial.SetGRPCDialOptions(
|
|
||||||
grpc.WithChainUnaryInterceptor(tracing.NewUnaryClientInteceptor()),
|
|
||||||
grpc.WithChainStreamInterceptor(tracing.NewStreamClientInterceptor()))
|
|
||||||
|
|
||||||
c.Init(prmInit)
|
c.Init(prmInit)
|
||||||
|
|
||||||
|
|
2
go.mod
2
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-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-contract v0.18.1-0.20231102065436-9ed3845aa989
|
||||||
git.frostfs.info/TrueCloudLab/frostfs-observability v0.0.0-20231101111734-b3ad3335ff65
|
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/hrw v1.2.1
|
||||||
git.frostfs.info/TrueCloudLab/policy-engine v0.0.0-20231115094736-5db67021e10f
|
git.frostfs.info/TrueCloudLab/policy-engine v0.0.0-20231115094736-5db67021e10f
|
||||||
git.frostfs.info/TrueCloudLab/tzhash v1.8.0
|
git.frostfs.info/TrueCloudLab/tzhash v1.8.0
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -732,8 +732,8 @@ git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0 h1:FxqFDhQYYgpe41qsIHVOcdzSV
|
||||||
git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0/go.mod h1:RUIKZATQLJ+TaYQa60X2fTDwfuhMfm8Ar60bQ5fr+vU=
|
git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0/go.mod h1:RUIKZATQLJ+TaYQa60X2fTDwfuhMfm8Ar60bQ5fr+vU=
|
||||||
git.frostfs.info/TrueCloudLab/frostfs-observability v0.0.0-20231101111734-b3ad3335ff65 h1:PaZ8GpnUoXxUoNsc1qp36bT2u7FU+neU4Jn9cl8AWqI=
|
git.frostfs.info/TrueCloudLab/frostfs-observability v0.0.0-20231101111734-b3ad3335ff65 h1:PaZ8GpnUoXxUoNsc1qp36bT2u7FU+neU4Jn9cl8AWqI=
|
||||||
git.frostfs.info/TrueCloudLab/frostfs-observability v0.0.0-20231101111734-b3ad3335ff65/go.mod h1:6aAX80dvJ3r5fjN9CzzPglRptoiPgIC9KFGGsUA+1Hw=
|
git.frostfs.info/TrueCloudLab/frostfs-observability v0.0.0-20231101111734-b3ad3335ff65/go.mod h1:6aAX80dvJ3r5fjN9CzzPglRptoiPgIC9KFGGsUA+1Hw=
|
||||||
git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20231101144515-6fbe1595cb3d h1:KVHsNsEoedQ1+f+eDq88AFKkLePGfnygt4bcUQrCgPw=
|
git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20231114081800-3787477133f3 h1:Qa35bB58plMb14LIsYzu2ibeYfsY2taFnbZytv9Ao3M=
|
||||||
git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20231101144515-6fbe1595cb3d/go.mod h1:t1akKcUH7iBrFHX8rSXScYMP17k2kYQXMbZooiL5Juw=
|
git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20231114081800-3787477133f3/go.mod h1:t1akKcUH7iBrFHX8rSXScYMP17k2kYQXMbZooiL5Juw=
|
||||||
git.frostfs.info/TrueCloudLab/hrw v1.2.1 h1:ccBRK21rFvY5R1WotI6LNoPlizk7qSvdfD8lNIRudVc=
|
git.frostfs.info/TrueCloudLab/hrw v1.2.1 h1:ccBRK21rFvY5R1WotI6LNoPlizk7qSvdfD8lNIRudVc=
|
||||||
git.frostfs.info/TrueCloudLab/hrw v1.2.1/go.mod h1:C1Ygde2n843yTZEQ0FP69jYiuaYV0kriLvP4zm8JuvM=
|
git.frostfs.info/TrueCloudLab/hrw v1.2.1/go.mod h1:C1Ygde2n843yTZEQ0FP69jYiuaYV0kriLvP4zm8JuvM=
|
||||||
git.frostfs.info/TrueCloudLab/policy-engine v0.0.0-20231115094736-5db67021e10f h1:Rq95TuEkqc3T1EN5ZU1Vgf6H33TR95hz97ca8jrUciQ=
|
git.frostfs.info/TrueCloudLab/policy-engine v0.0.0-20231115094736-5db67021e10f h1:Rq95TuEkqc3T1EN5ZU1Vgf6H33TR95hz97ca8jrUciQ=
|
||||||
|
|
44
pkg/network/cache/multi.go
vendored
44
pkg/network/cache/multi.go
vendored
|
@ -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) {
|
func (x *multiClient) createForAddress(ctx context.Context, addr network.Address) (clientcore.Client, error) {
|
||||||
var (
|
var c client.Client
|
||||||
c client.Client
|
|
||||||
prmInit client.PrmInit
|
|
||||||
prmDial client.PrmDial
|
|
||||||
)
|
|
||||||
|
|
||||||
prmInit.DisableFrostFSFailuresResolution()
|
|
||||||
prmDial.SetServerURI(addr.URIAddr())
|
|
||||||
|
|
||||||
|
prmInit := client.PrmInit{
|
||||||
|
DisableFrostFSErrorResolution: true,
|
||||||
|
}
|
||||||
if x.opts.Key != nil {
|
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 {
|
if x.opts.DialTimeout > 0 {
|
||||||
prmDial.SetTimeout(x.opts.DialTimeout)
|
prmDial.DialTimeout = x.opts.DialTimeout
|
||||||
}
|
}
|
||||||
|
|
||||||
if x.opts.StreamTimeout > 0 {
|
if x.opts.StreamTimeout > 0 {
|
||||||
prmDial.SetStreamTimeout(x.opts.StreamTimeout)
|
prmDial.StreamTimeout = x.opts.StreamTimeout
|
||||||
}
|
}
|
||||||
|
|
||||||
if x.opts.ResponseCallback != nil {
|
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)
|
c.Init(prmInit)
|
||||||
err := c.Dial(ctx, prmDial)
|
err := c.Dial(ctx, prmDial)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue