[#493] cmd/node: Add profiler section to config

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-06-01 14:12:25 +03:00 committed by Alex Vanin
parent 922d29ff88
commit 561c809fa5
5 changed files with 88 additions and 1 deletions

View file

@ -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
}

View file

@ -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)
})
}

View file

@ -1 +1,4 @@
NEOFS_LOGGER_LEVEL=debug NEOFS_LOGGER_LEVEL=debug
NEOFS_PROFILER_ADDRESS=127.0.0.1:6060
NEOFS_PROFILER_SHUTDOWN_TIMEOUT=15s

View file

@ -1,5 +1,9 @@
{ {
"logger": { "logger": {
"level": "debug" "level": "debug"
},
"profiler": {
"address": "127.0.0.1:6060",
"shutdown_timeout": "15s"
} }
} }

View file

@ -1,2 +1,5 @@
logger: logger:
level: debug level: debug
profiler:
address: 127.0.0.1:6060
shutdown_timeout: 15s