diff --git a/cmd/neofs-node/config/metrics/config.go b/cmd/neofs-node/config/metrics/config.go new file mode 100644 index 00000000..17510ed3 --- /dev/null +++ b/cmd/neofs-node/config/metrics/config.go @@ -0,0 +1,40 @@ +package metricsconfig + +import ( + "time" + + "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config" +) + +const ( + subsection = "metrics" + + ShutdownTimeoutDefault = 30 * time.Second + AddressDefault = "" +) + +// ShutdownTimeout returns value of "shutdown_timeout" config parameter +// from "metrics" 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 "metrics" 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/metrics/config_test.go b/cmd/neofs-node/config/metrics/config_test.go new file mode 100644 index 00000000..92056ee5 --- /dev/null +++ b/cmd/neofs-node/config/metrics/config_test.go @@ -0,0 +1,37 @@ +package metricsconfig_test + +import ( + "testing" + "time" + + "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config" + metricsconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/metrics" + configtest "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/test" + "github.com/stretchr/testify/require" +) + +func TestMetricsSection(t *testing.T) { + t.Run("defaults", func(t *testing.T) { + to := metricsconfig.ShutdownTimeout(configtest.EmptyConfig()) + addr := metricsconfig.Address(configtest.EmptyConfig()) + + require.Equal(t, metricsconfig.ShutdownTimeoutDefault, to) + require.Equal(t, metricsconfig.AddressDefault, addr) + }) + + const path = "../../../../config/example/node" + + var fileConfigTest = func(c *config.Config) { + to := metricsconfig.ShutdownTimeout(c) + addr := metricsconfig.Address(c) + + require.Equal(t, 15*time.Second, to) + require.Equal(t, "127.0.0.1:9090", 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 15e7fc33..d4c9c371 100644 --- a/config/example/node.env +++ b/config/example/node.env @@ -1,4 +1,7 @@ NEOFS_LOGGER_LEVEL=debug NEOFS_PROFILER_ADDRESS=127.0.0.1:6060 -NEOFS_PROFILER_SHUTDOWN_TIMEOUT=15s \ No newline at end of file +NEOFS_PROFILER_SHUTDOWN_TIMEOUT=15s + +NEOFS_METRICS_ADDRESS=127.0.0.1:9090 +NEOFS_METRICS_SHUTDOWN_TIMEOUT=15s \ No newline at end of file diff --git a/config/example/node.json b/config/example/node.json index 875c6c37..660037a1 100644 --- a/config/example/node.json +++ b/config/example/node.json @@ -5,5 +5,9 @@ "profiler": { "address": "127.0.0.1:6060", "shutdown_timeout": "15s" + }, + "metrics": { + "address": "127.0.0.1:9090", + "shutdown_timeout": "15s" } } diff --git a/config/example/node.yaml b/config/example/node.yaml index 36dbe164..15318a4a 100644 --- a/config/example/node.yaml +++ b/config/example/node.yaml @@ -3,3 +3,6 @@ logger: profiler: address: 127.0.0.1:6060 shutdown_timeout: 15s +metrics: + address: 127.0.0.1:9090 + shutdown_timeout: 15s