forked from TrueCloudLab/frostfs-node
[#493] cmd/node: Add policer section to config
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
27b4781e95
commit
8c96494da0
5 changed files with 67 additions and 0 deletions
27
cmd/neofs-node/config/policer/config.go
Normal file
27
cmd/neofs-node/config/policer/config.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
package policerconfig
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
|
||||
)
|
||||
|
||||
const (
|
||||
subsection = "policer"
|
||||
|
||||
// HeadTimeoutDefault is a default object.Head request timeout in policer.
|
||||
HeadTimeoutDefault = 5 * time.Second
|
||||
)
|
||||
|
||||
// HeadTimeout returns value of "head_timeout" config parameter
|
||||
// from "policer" section.
|
||||
//
|
||||
// Returns HeadTimeoutDefault if value is not positive duration.
|
||||
func HeadTimeout(c *config.Config) time.Duration {
|
||||
v := config.DurationSafe(c.Sub(subsection), "head_timeout")
|
||||
if v > 0 {
|
||||
return v
|
||||
}
|
||||
|
||||
return HeadTimeoutDefault
|
||||
}
|
31
cmd/neofs-node/config/policer/config_test.go
Normal file
31
cmd/neofs-node/config/policer/config_test.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package policerconfig_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
|
||||
policerconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/policer"
|
||||
configtest "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/test"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestPolicerSection(t *testing.T) {
|
||||
t.Run("defaults", func(t *testing.T) {
|
||||
empty := configtest.EmptyConfig()
|
||||
|
||||
require.Equal(t, policerconfig.HeadTimeoutDefault, policerconfig.HeadTimeout(empty))
|
||||
})
|
||||
|
||||
const path = "../../../../config/example/node"
|
||||
|
||||
var fileConfigTest = func(c *config.Config) {
|
||||
require.Equal(t, 15*time.Second, policerconfig.HeadTimeout(c))
|
||||
}
|
||||
|
||||
configtest.ForEachFileType(path, fileConfigTest)
|
||||
|
||||
t.Run("ENV", func(t *testing.T) {
|
||||
configtest.ForEnvFileType(path, fileConfigTest)
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue