From cd947bb580b3ceb2fa9fcc2e68a606c1c8d3a942 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 2 Jun 2021 15:31:29 +0300 Subject: [PATCH] [#493] cmd/node: Add object service section to config Signed-off-by: Alex Vanin --- cmd/neofs-node/config/object/config.go | 41 +++++++++++++++++++++ cmd/neofs-node/config/object/config_test.go | 30 +++++++++++++++ config/example/node.env | 3 ++ config/example/node.json | 5 +++ config/example/node.yaml | 4 ++ 5 files changed, 83 insertions(+) create mode 100644 cmd/neofs-node/config/object/config.go create mode 100644 cmd/neofs-node/config/object/config_test.go diff --git a/cmd/neofs-node/config/object/config.go b/cmd/neofs-node/config/object/config.go new file mode 100644 index 000000000..79f3df75b --- /dev/null +++ b/cmd/neofs-node/config/object/config.go @@ -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 +} diff --git a/cmd/neofs-node/config/object/config_test.go b/cmd/neofs-node/config/object/config_test.go new file mode 100644 index 000000000..a2d6b619d --- /dev/null +++ b/cmd/neofs-node/config/object/config_test.go @@ -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) + }) +} diff --git a/config/example/node.env b/config/example/node.env index 6ba00aefd..4d56ad365 100644 --- a/config/example/node.env +++ b/config/example/node.env @@ -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 diff --git a/config/example/node.json b/config/example/node.json index e5489ac46..612544611 100644 --- a/config/example/node.json +++ b/config/example/node.json @@ -67,6 +67,11 @@ "replicator": { "put_timeout": "15s" }, + "object": { + "put": { + "pool_size": 100 + } + }, "storage": { "shard_num": 2, "shard": { diff --git a/config/example/node.yaml b/config/example/node.yaml index e3d8db53b..ba0028e03 100644 --- a/config/example/node.yaml +++ b/config/example/node.yaml @@ -60,6 +60,10 @@ policer: replicator: put_timeout: 15s +object: + put: + pool_size: 100 + storage: shard_num: 2 shard: