From f40b84c99e789600df464f44483cc6a9a9920e61 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 2 Jun 2021 15:26:51 +0300 Subject: [PATCH] [#493] cmd/node: Add replicator section to config Signed-off-by: Alex Vanin --- cmd/neofs-node/config/replicator/config.go | 27 ++++++++++++++++ .../config/replicator/config_test.go | 31 +++++++++++++++++++ config/example/node.env | 3 ++ config/example/node.json | 3 ++ config/example/node.yaml | 3 ++ 5 files changed, 67 insertions(+) create mode 100644 cmd/neofs-node/config/replicator/config.go create mode 100644 cmd/neofs-node/config/replicator/config_test.go diff --git a/cmd/neofs-node/config/replicator/config.go b/cmd/neofs-node/config/replicator/config.go new file mode 100644 index 00000000..3cf10a4b --- /dev/null +++ b/cmd/neofs-node/config/replicator/config.go @@ -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 +} diff --git a/cmd/neofs-node/config/replicator/config_test.go b/cmd/neofs-node/config/replicator/config_test.go new file mode 100644 index 00000000..419f39cd --- /dev/null +++ b/cmd/neofs-node/config/replicator/config_test.go @@ -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) + }) +} diff --git a/config/example/node.env b/config/example/node.env index f71d4f20..6ba00aef 100644 --- a/config/example/node.env +++ b/config/example/node.env @@ -44,6 +44,9 @@ NEOFS_APICLIENT_DIAL_TIMEOUT=15s # Policer section NEOFS_POLICER_HEAD_TIMEOUT=15s +# Replicator section +NEOFS_REPLICATOR_PUT_TIMEOUT=15s + # Storage engine section NEOFS_STORAGE_SHARD_NUM=2 ## 0 shard diff --git a/config/example/node.json b/config/example/node.json index fe638718..e5489ac4 100644 --- a/config/example/node.json +++ b/config/example/node.json @@ -64,6 +64,9 @@ "policer": { "head_timeout": "15s" }, + "replicator": { + "put_timeout": "15s" + }, "storage": { "shard_num": 2, "shard": { diff --git a/config/example/node.yaml b/config/example/node.yaml index 26250d17..e3d8db53 100644 --- a/config/example/node.yaml +++ b/config/example/node.yaml @@ -57,6 +57,9 @@ apiclient: policer: head_timeout: 15s +replicator: + put_timeout: 15s + storage: shard_num: 2 shard: