From 8c96494da0adfaf82f4faca197bb4b22f53bb1b5 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 2 Jun 2021 15:23:41 +0300 Subject: [PATCH] [#493] cmd/node: Add policer section to config Signed-off-by: Alex Vanin --- cmd/neofs-node/config/policer/config.go | 27 +++++++++++++++++ cmd/neofs-node/config/policer/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/policer/config.go create mode 100644 cmd/neofs-node/config/policer/config_test.go diff --git a/cmd/neofs-node/config/policer/config.go b/cmd/neofs-node/config/policer/config.go new file mode 100644 index 000000000..14fea7eab --- /dev/null +++ b/cmd/neofs-node/config/policer/config.go @@ -0,0 +1,27 @@ +package policerconfig + +import ( + "time" + + "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config" +) + +const ( + subsection = "policer" + + // HeadTimeoutDefault is a default object.Head request timeout in policer. + HeadTimeoutDefault = 5 * time.Second +) + +// HeadTimeout returns value of "head_timeout" config parameter +// from "policer" section. +// +// Returns HeadTimeoutDefault if value is not positive duration. +func HeadTimeout(c *config.Config) time.Duration { + v := config.DurationSafe(c.Sub(subsection), "head_timeout") + if v > 0 { + return v + } + + return HeadTimeoutDefault +} diff --git a/cmd/neofs-node/config/policer/config_test.go b/cmd/neofs-node/config/policer/config_test.go new file mode 100644 index 000000000..03a2f3a86 --- /dev/null +++ b/cmd/neofs-node/config/policer/config_test.go @@ -0,0 +1,31 @@ +package policerconfig_test + +import ( + "testing" + "time" + + "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config" + policerconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/policer" + configtest "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/test" + "github.com/stretchr/testify/require" +) + +func TestPolicerSection(t *testing.T) { + t.Run("defaults", func(t *testing.T) { + empty := configtest.EmptyConfig() + + require.Equal(t, policerconfig.HeadTimeoutDefault, policerconfig.HeadTimeout(empty)) + }) + + const path = "../../../../config/example/node" + + var fileConfigTest = func(c *config.Config) { + require.Equal(t, 15*time.Second, policerconfig.HeadTimeout(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 a0984af24..f71d4f200 100644 --- a/config/example/node.env +++ b/config/example/node.env @@ -41,6 +41,9 @@ NEOFS_MAINCHAIN_RPC_ENDPOINT=https://rpc1.n3.nspcc.ru:30341 https://rpc2.n3.nspc # API Client section NEOFS_APICLIENT_DIAL_TIMEOUT=15s +# Policer section +NEOFS_POLICER_HEAD_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 26bb43439..fe6387184 100644 --- a/config/example/node.json +++ b/config/example/node.json @@ -61,6 +61,9 @@ "apiclient": { "dial_timeout": "15s" }, + "policer": { + "head_timeout": "15s" + }, "storage": { "shard_num": 2, "shard": { diff --git a/config/example/node.yaml b/config/example/node.yaml index ab4a6902d..26250d17b 100644 --- a/config/example/node.yaml +++ b/config/example/node.yaml @@ -54,6 +54,9 @@ mainchain: apiclient: dial_timeout: 15s +policer: + head_timeout: 15s + storage: shard_num: 2 shard: