forked from TrueCloudLab/frostfs-node
[#493] cmd/node: Add metrics section to config
Signed-off-by: Alex Vanin <alexey@nspcc.ru>support/v0.27
parent
da8310f0e3
commit
3fbf5e05b2
|
@ -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
|
||||
}
|
|
@ -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)
|
||||
})
|
||||
}
|
|
@ -2,3 +2,6 @@ NEOFS_LOGGER_LEVEL=debug
|
|||
|
||||
NEOFS_PROFILER_ADDRESS=127.0.0.1:6060
|
||||
NEOFS_PROFILER_SHUTDOWN_TIMEOUT=15s
|
||||
|
||||
NEOFS_METRICS_ADDRESS=127.0.0.1:9090
|
||||
NEOFS_METRICS_SHUTDOWN_TIMEOUT=15s
|
|
@ -5,5 +5,9 @@
|
|||
"profiler": {
|
||||
"address": "127.0.0.1:6060",
|
||||
"shutdown_timeout": "15s"
|
||||
},
|
||||
"metrics": {
|
||||
"address": "127.0.0.1:9090",
|
||||
"shutdown_timeout": "15s"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue