diff --git a/cmd/neofs-node/config/apiclient/config.go b/cmd/neofs-node/config/apiclient/config.go new file mode 100644 index 00000000..4961de7d --- /dev/null +++ b/cmd/neofs-node/config/apiclient/config.go @@ -0,0 +1,27 @@ +package apiclientconfig + +import ( + "time" + + "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config" +) + +const ( + subsection = "apiclient" + + // DialTimeoutDefault is a default dial timeout of NeoFS API client connection. + DialTimeoutDefault = 5 * time.Second +) + +// DialTimeout returns value of "dial_timeout" config parameter +// from "apiclient" section. +// +// Returns DialTimeoutDefault if value is not positive duration. +func DialTimeout(c *config.Config) time.Duration { + v := config.DurationSafe(c.Sub(subsection), "dial_timeout") + if v != 0 { + return v + } + + return DialTimeoutDefault +} diff --git a/cmd/neofs-node/config/apiclient/config_test.go b/cmd/neofs-node/config/apiclient/config_test.go new file mode 100644 index 00000000..85644cb1 --- /dev/null +++ b/cmd/neofs-node/config/apiclient/config_test.go @@ -0,0 +1,31 @@ +package apiclientconfig_test + +import ( + "testing" + "time" + + "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config" + apiclientconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/apiclient" + configtest "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/test" + "github.com/stretchr/testify/require" +) + +func TestApiclientSection(t *testing.T) { + t.Run("defaults", func(t *testing.T) { + empty := configtest.EmptyConfig() + + require.Equal(t, apiclientconfig.DialTimeoutDefault, apiclientconfig.DialTimeout(empty)) + }) + + const path = "../../../../config/example/node" + + var fileConfigTest = func(c *config.Config) { + require.Equal(t, 15*time.Second, apiclientconfig.DialTimeout(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 21e1fbbf..a0984af2 100644 --- a/config/example/node.env +++ b/config/example/node.env @@ -38,6 +38,9 @@ NEOFS_MORPH_NOTIFICATION_ENDPOINT=wss://rpc1.morph.fs.neo.org:40341/ws wss://rpc NEOFS_MAINCHAIN_DIAL_TIMEOUT=30s NEOFS_MAINCHAIN_RPC_ENDPOINT=https://rpc1.n3.nspcc.ru:30341 https://rpc2.n3.nspcc.ru:30341 +# API Client section +NEOFS_APICLIENT_DIAL_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 1ac54255..26bb4343 100644 --- a/config/example/node.json +++ b/config/example/node.json @@ -58,6 +58,9 @@ "https://rpc2.n3.nspcc.ru:30341" ] }, + "apiclient": { + "dial_timeout": "15s" + }, "storage": { "shard_num": 2, "shard": { diff --git a/config/example/node.yaml b/config/example/node.yaml index b96aaca0..ab4a6902 100644 --- a/config/example/node.yaml +++ b/config/example/node.yaml @@ -51,6 +51,9 @@ mainchain: - https://rpc1.n3.nspcc.ru:30341 - https://rpc2.n3.nspcc.ru:30341 +apiclient: + dial_timeout: 15s + storage: shard_num: 2 shard: