[#493] cmd/node: Add replicator section to config

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-06-02 15:26:51 +03:00 committed by Alex Vanin
parent 8c96494da0
commit f40b84c99e
5 changed files with 67 additions and 0 deletions

View file

@ -0,0 +1,27 @@
package replicatorconfig
import (
"time"
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
)
const (
subsection = "replicator"
// PutTimeoutDefault is a default timeout of object put request in replicator.
PutTimeoutDefault = 5 * time.Second
)
// PutTimeout returns value of "put_timeout" config parameter
// from "replicator" section.
//
// Returns PutTimeoutDefault if value is not positive duration.
func PutTimeout(c *config.Config) time.Duration {
v := config.DurationSafe(c.Sub(subsection), "put_timeout")
if v > 0 {
return v
}
return PutTimeoutDefault
}

View file

@ -0,0 +1,31 @@
package replicatorconfig_test
import (
"testing"
"time"
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
replicatorconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/replicator"
configtest "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/test"
"github.com/stretchr/testify/require"
)
func TestReplicatorSection(t *testing.T) {
t.Run("defaults", func(t *testing.T) {
empty := configtest.EmptyConfig()
require.Equal(t, replicatorconfig.PutTimeoutDefault, replicatorconfig.PutTimeout(empty))
})
const path = "../../../../config/example/node"
var fileConfigTest = func(c *config.Config) {
require.Equal(t, 15*time.Second, replicatorconfig.PutTimeout(c))
}
configtest.ForEachFileType(path, fileConfigTest)
t.Run("ENV", func(t *testing.T) {
configtest.ForEnvFileType(path, fileConfigTest)
})
}

View file

@ -44,6 +44,9 @@ NEOFS_APICLIENT_DIAL_TIMEOUT=15s
# Policer section # Policer section
NEOFS_POLICER_HEAD_TIMEOUT=15s NEOFS_POLICER_HEAD_TIMEOUT=15s
# Replicator section
NEOFS_REPLICATOR_PUT_TIMEOUT=15s
# Storage engine section # Storage engine section
NEOFS_STORAGE_SHARD_NUM=2 NEOFS_STORAGE_SHARD_NUM=2
## 0 shard ## 0 shard

View file

@ -64,6 +64,9 @@
"policer": { "policer": {
"head_timeout": "15s" "head_timeout": "15s"
}, },
"replicator": {
"put_timeout": "15s"
},
"storage": { "storage": {
"shard_num": 2, "shard_num": 2,
"shard": { "shard": {

View file

@ -57,6 +57,9 @@ apiclient:
policer: policer:
head_timeout: 15s head_timeout: 15s
replicator:
put_timeout: 15s
storage: storage:
shard_num: 2 shard_num: 2
shard: shard: