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

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-06-02 15:31:29 +03:00 committed by Alex Vanin
parent f40b84c99e
commit cd947bb580
5 changed files with 83 additions and 0 deletions

View file

@ -0,0 +1,41 @@
package objectconfig
import (
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
)
// PutConfig is a wrapper over "put" config section which provides access
// to object put pipeline configuration of object service.
type PutConfig struct {
cfg *config.Config
}
const (
subsection = "object"
putSubsection = "put"
// PutPoolSizeDefault is a default value of routine pool size to
// process object.Put requests in object service.
PutPoolSizeDefault = 10
)
// Put returns structure that provides access to "put" subsection of
// "object" section.
func Put(c *config.Config) PutConfig {
return PutConfig{
c.Sub(subsection).Sub(putSubsection),
}
}
// PoolSize returns value of "pool_size" config parameter.
//
// Returns PutPoolSizeDefault if value is not positive number.
func (g PutConfig) PoolSize() int {
v := config.Int(g.cfg, "pool_size")
if v > 0 {
return int(v)
}
return PutPoolSizeDefault
}

View file

@ -0,0 +1,30 @@
package objectconfig_test
import (
"testing"
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
objectconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/object"
configtest "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/test"
"github.com/stretchr/testify/require"
)
func TestObjectSection(t *testing.T) {
t.Run("defaults", func(t *testing.T) {
empty := configtest.EmptyConfig()
require.Equal(t, objectconfig.PutPoolSizeDefault, objectconfig.Put(empty).PoolSize())
})
const path = "../../../../config/example/node"
var fileConfigTest = func(c *config.Config) {
require.Equal(t, 100, objectconfig.Put(c).PoolSize())
}
configtest.ForEachFileType(path, fileConfigTest)
t.Run("ENV", func(t *testing.T) {
configtest.ForEnvFileType(path, fileConfigTest)
})
}

View file

@ -47,6 +47,9 @@ NEOFS_POLICER_HEAD_TIMEOUT=15s
# Replicator section
NEOFS_REPLICATOR_PUT_TIMEOUT=15s
# Object service section
NEOFS_OBJECT_PUT_POOL_SIZE=100
# Storage engine section
NEOFS_STORAGE_SHARD_NUM=2
## 0 shard

View file

@ -67,6 +67,11 @@
"replicator": {
"put_timeout": "15s"
},
"object": {
"put": {
"pool_size": 100
}
},
"storage": {
"shard_num": 2,
"shard": {

View file

@ -60,6 +60,10 @@ policer:
replicator:
put_timeout: 15s
object:
put:
pool_size: 100
storage:
shard_num: 2
shard: