diff --git a/cmd/neofs-node/config/replicator/config.go b/cmd/neofs-node/config/replicator/config.go new file mode 100644 index 0000000000..3cf10a4b1a --- /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 0000000000..419f39cd95 --- /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 f71d4f200d..6ba00aefdf 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 fe63871842..e5489ac46e 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 26250d17bc..e3d8db53b1 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: