From ca46dc5ec1818d19a2fb9f8f19280bb1cb2007d9 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Thu, 12 Oct 2023 18:08:11 +0300 Subject: [PATCH] [#XX] Don't reload rpc_endpoint for resolvers Signed-off-by: Denis Kirillov --- cmd/http-gw/app.go | 14 ++++++++------ docs/gate-configuration.md | 21 ++++++++++----------- resolver/resolver.go | 11 ++++++++--- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/cmd/http-gw/app.go b/cmd/http-gw/app.go index 1660586..8b8c057 100644 --- a/cmd/http-gw/app.go +++ b/cmd/http-gw/app.go @@ -178,20 +178,22 @@ func (a *app) initAppSettings() { func (a *app) initResolver() { var err error - a.resolver, err = resolver.NewContainerResolver(a.getResolverConfig()) + a.resolver, err = resolver.NewContainerResolver(a.getResolverOrder(), a.getResolverConfig()) if err != nil { a.log.Fatal(logs.FailedToCreateResolver, zap.Error(err)) } } -func (a *app) getResolverConfig() ([]string, *resolver.Config) { - resolveCfg := &resolver.Config{ +func (a *app) getResolverConfig() *resolver.Config { + return &resolver.Config{ FrostFS: resolver.NewFrostFSResolver(a.pool), RPCAddress: a.cfg.GetString(cfgRPCEndpoint), } +} +func (a *app) getResolverOrder() []string { order := a.cfg.GetStringSlice(cfgResolveOrder) - if resolveCfg.RPCAddress == "" { + if a.cfg.GetString(cfgRPCEndpoint) == "" { order = remove(order, resolver.NNSResolver) a.log.Warn(logs.ResolverNNSWontBeUsedSinceRPCEndpointIsntProvided) } @@ -200,7 +202,7 @@ func (a *app) getResolverConfig() ([]string, *resolver.Config) { a.log.Info(logs.ContainerResolverWillBeDisabledBecauseOfResolversResolverOrderIsEmpty) } - return order, resolveCfg + return order } func (a *app) initMetrics() { @@ -445,7 +447,7 @@ func (a *app) configReload(ctx context.Context) { a.logLevel.SetLevel(lvl) } - if err := a.resolver.UpdateResolvers(a.getResolverConfig()); err != nil { + if err := a.resolver.UpdateResolvers(a.getResolverOrder()); err != nil { a.log.Warn(logs.FailedToUpdateResolvers, zap.Error(err)) } diff --git a/docs/gate-configuration.md b/docs/gate-configuration.md index a75ffe7..e86a761 100644 --- a/docs/gate-configuration.md +++ b/docs/gate-configuration.md @@ -72,15 +72,15 @@ rebalance_timer: 30s pool_error_threshold: 100 ``` -| Parameter | Type | SIGHUP reload | Default value | Description | -|------------------------|------------|-------------------------------------------|---------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `rpc_endpoint` | `string` | depends on context (see related sections) | | The address of the RPC host to which the gateway connects to resolve bucket names and interact with frostfs contracts (required to use the `nns` resolver and `frostfsid` contract). | -| `resolve_order` | `[]string` | yes | `[nns, dns]` | Order of bucket name resolvers to use. Available resolvers: `dns`, `nns`. For this resolvers `rpc_endpoint` supports SIGHUP reload. | -| `connect_timeout` | `duration` | | `10s` | Timeout to connect to a node. | -| `stream_timeout` | `duration` | | `10s` | Timeout for individual operations in streaming RPC. | -| `request_timeout` | `duration` | | `15s` | Timeout to check node health during rebalance. | -| `rebalance_timer` | `duration` | | `60s` | Interval to check node health. | -| `pool_error_threshold` | `uint32` | | `100` | The number of errors on connection after which node is considered as unhealthy. | +| Parameter | Type | SIGHUP reload | Default value | Description | +|------------------------|------------|---------------|---------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `rpc_endpoint` | `string` | no | | The address of the RPC host to which the gateway connects to resolve bucket names and interact with frostfs contracts (required to use the `nns` resolver and `frostfsid` contract). | +| `resolve_order` | `[]string` | yes | `[nns, dns]` | Order of bucket name resolvers to use. Available resolvers: `dns`, `nns`. | +| `connect_timeout` | `duration` | no | `10s` | Timeout to connect to a node. | +| `stream_timeout` | `duration` | no | `10s` | Timeout for individual operations in streaming RPC. | +| `request_timeout` | `duration` | no | `15s` | Timeout to check node health during rebalance. | +| `rebalance_timer` | `duration` | no | `60s` | Interval to check node health. | +| `pool_error_threshold` | `uint32` | no | `100` | The number of errors on connection after which node is considered as unhealthy. | # `wallet` section @@ -273,8 +273,7 @@ runtime: # `frostfsid` section -FrostfsID contract configuration. To enable this functionality the `rpc_endpoint` param must be also set (In this -context `rpc_endpoint` does not support SIGHUP reload). +FrostfsID contract configuration. To enable this functionality the `rpc_endpoint` param must be also set. ```yaml frostfsid: diff --git a/resolver/resolver.go b/resolver/resolver.go index e6707e2..5e39125 100644 --- a/resolver/resolver.go +++ b/resolver/resolver.go @@ -34,6 +34,9 @@ type Config struct { } type ContainerResolver struct { + rpcAddress string + frostfs FrostFS + mu sync.RWMutex resolvers []*Resolver } @@ -58,7 +61,9 @@ func NewContainerResolver(resolverNames []string, cfg *Config) (*ContainerResolv } return &ContainerResolver{ - resolvers: resolvers, + rpcAddress: cfg.RPCAddress, + frostfs: cfg.FrostFS, + resolvers: resolvers, }, nil } @@ -101,7 +106,7 @@ func (r *ContainerResolver) Resolve(ctx context.Context, cnrName string) (*cid.I return nil, ErrNoResolvers } -func (r *ContainerResolver) UpdateResolvers(resolverNames []string, cfg *Config) error { +func (r *ContainerResolver) UpdateResolvers(resolverNames []string) error { r.mu.Lock() defer r.mu.Unlock() @@ -109,7 +114,7 @@ func (r *ContainerResolver) UpdateResolvers(resolverNames []string, cfg *Config) return nil } - resolvers, err := createResolvers(resolverNames, cfg) + resolvers, err := createResolvers(resolverNames, &Config{FrostFS: r.frostfs, RPCAddress: r.rpcAddress}) if err != nil { return err }