diff --git a/cmd/neofs-node/config/profiler/config.go b/cmd/neofs-node/config/profiler/config.go new file mode 100644 index 00000000..12d574bb --- /dev/null +++ b/cmd/neofs-node/config/profiler/config.go @@ -0,0 +1,40 @@ +package profilerconfig + +import ( + "time" + + "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config" +) + +const ( + subsection = "profiler" + + ShutdownTimeoutDefault = 30 * time.Second + AddressDefault = "" +) + +// ShutdownTimeout returns value of "shutdown_timeout" config parameter +// from "profiler" section. +// +// Returns ShutdownTimeoutDefault if value is not set. +func ShutdownTimeout(c *config.Config) time.Duration { + v := config.DurationSafe(c.Sub(subsection), "shutdown_timeout") + if v != 0 { + return v + } + + return ShutdownTimeoutDefault +} + +// Address returns value of "address" config parameter +// from "profiler" section. +// +// Returns AddressDefault if value is not set. +func Address(c *config.Config) string { + v := config.StringSafe(c.Sub(subsection), "address") + if v != "" { + return v + } + + return AddressDefault +} diff --git a/cmd/neofs-node/config/profiler/config_test.go b/cmd/neofs-node/config/profiler/config_test.go new file mode 100644 index 00000000..18eb9fae --- /dev/null +++ b/cmd/neofs-node/config/profiler/config_test.go @@ -0,0 +1,37 @@ +package profilerconfig_test + +import ( + "testing" + "time" + + "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config" + profilerconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/profiler" + configtest "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/test" + "github.com/stretchr/testify/require" +) + +func TestProfilerSection(t *testing.T) { + t.Run("defaults", func(t *testing.T) { + to := profilerconfig.ShutdownTimeout(configtest.EmptyConfig()) + addr := profilerconfig.Address(configtest.EmptyConfig()) + + require.Equal(t, profilerconfig.ShutdownTimeoutDefault, to) + require.Equal(t, profilerconfig.AddressDefault, addr) + }) + + const path = "../../../../config/example/node" + + var fileConfigTest = func(c *config.Config) { + to := profilerconfig.ShutdownTimeout(c) + addr := profilerconfig.Address(c) + + require.Equal(t, 15*time.Second, to) + require.Equal(t, "127.0.0.1:6060", addr) + } + + 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 f23bc7d9..15e7fc33 100644 --- a/config/example/node.env +++ b/config/example/node.env @@ -1 +1,4 @@ -NEOFS_LOGGER_LEVEL=debug \ No newline at end of file +NEOFS_LOGGER_LEVEL=debug + +NEOFS_PROFILER_ADDRESS=127.0.0.1:6060 +NEOFS_PROFILER_SHUTDOWN_TIMEOUT=15s \ No newline at end of file diff --git a/config/example/node.json b/config/example/node.json index 17d9ee6b..875c6c37 100644 --- a/config/example/node.json +++ b/config/example/node.json @@ -1,5 +1,9 @@ { "logger": { "level": "debug" + }, + "profiler": { + "address": "127.0.0.1:6060", + "shutdown_timeout": "15s" } } diff --git a/config/example/node.yaml b/config/example/node.yaml index 6f04a94f..36dbe164 100644 --- a/config/example/node.yaml +++ b/config/example/node.yaml @@ -1,2 +1,5 @@ logger: level: debug +profiler: + address: 127.0.0.1:6060 + shutdown_timeout: 15s