From 31c623636d5431466504caccb89cf21d3d634e21 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Wed, 12 Oct 2022 20:55:35 +0300 Subject: [PATCH] [#1863] node: Fix shard id in the object counter metrics If shard ID is stored in metabase (it is not the first time boot), read it, set it, use it (not a generated one) in the metrics writer. Signed-off-by: Pavel Karpy --- CHANGELOG.md | 1 + pkg/local_object_storage/engine/shards.go | 16 +++++++++++----- pkg/local_object_storage/shard/id.go | 4 ++++ pkg/local_object_storage/shard/metrics_test.go | 2 ++ pkg/local_object_storage/shard/shard.go | 3 +++ 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3e609bdc..f25218bd9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ Changelog for NeoFS Node - `control drop-objects` can remove split objects (#1830) - Node's status in `neofs-cli netmap nodeinfo` command (#1833) - Child check in object assembly process of `ObjectService.Get` handler (#1878) +- Shard ID in the object counter metrics (#1863) ### Removed - Remove WIF and NEP2 support in `neofs-cli`'s --wallet flag (#1128) diff --git a/pkg/local_object_storage/engine/shards.go b/pkg/local_object_storage/engine/shards.go index c54f2cc8e..77946f973 100644 --- a/pkg/local_object_storage/engine/shards.go +++ b/pkg/local_object_storage/engine/shards.go @@ -23,19 +23,25 @@ type metricsWithID struct { mw MetricRegister } -func (m metricsWithID) SetObjectCounter(objectType string, v uint64) { +func (m *metricsWithID) SetShardID(id string) { + // concurrent settings are not expected => + // no mutex protection + m.id = id +} + +func (m *metricsWithID) SetObjectCounter(objectType string, v uint64) { m.mw.SetObjectCounter(m.id, objectType, v) } -func (m metricsWithID) AddToObjectCounter(objectType string, delta int) { +func (m *metricsWithID) AddToObjectCounter(objectType string, delta int) { m.mw.AddToObjectCounter(m.id, objectType, delta) } -func (m metricsWithID) IncObjectCounter(objectType string) { +func (m *metricsWithID) IncObjectCounter(objectType string) { m.mw.AddToObjectCounter(m.id, objectType, +1) } -func (m metricsWithID) DecObjectCounter(objectType string) { +func (m *metricsWithID) DecObjectCounter(objectType string) { m.mw.AddToObjectCounter(m.id, objectType, -1) } @@ -67,7 +73,7 @@ func (e *StorageEngine) createShard(opts []shard.Option) (*shard.Shard, error) { if e.metrics != nil { opts = append(opts, shard.WithMetricsWriter( - metricsWithID{ + &metricsWithID{ id: id.String(), mw: e.metrics, }, diff --git a/pkg/local_object_storage/shard/id.go b/pkg/local_object_storage/shard/id.go index 592112815..c12d56e96 100644 --- a/pkg/local_object_storage/shard/id.go +++ b/pkg/local_object_storage/shard/id.go @@ -43,6 +43,10 @@ func (s *Shard) UpdateID() (err error) { } if len(id) != 0 { s.info.ID = NewIDFromBytes(id) + + if s.cfg.metricsWriter != nil { + s.cfg.metricsWriter.SetShardID(s.info.ID.String()) + } } s.log = &logger.Logger{Logger: s.log.With(zap.String("shard_id", s.info.ID.String()))} diff --git a/pkg/local_object_storage/shard/metrics_test.go b/pkg/local_object_storage/shard/metrics_test.go index c6eec3456..ea46896ed 100644 --- a/pkg/local_object_storage/shard/metrics_test.go +++ b/pkg/local_object_storage/shard/metrics_test.go @@ -19,6 +19,8 @@ type metricsStore struct { s map[string]uint64 } +func (m metricsStore) SetShardID(_ string) {} + func (m metricsStore) SetObjectCounter(objectType string, v uint64) { m.s[objectType] = v } diff --git a/pkg/local_object_storage/shard/shard.go b/pkg/local_object_storage/shard/shard.go index cbad4db9e..033b7bbaf 100644 --- a/pkg/local_object_storage/shard/shard.go +++ b/pkg/local_object_storage/shard/shard.go @@ -59,6 +59,9 @@ type MetricsWriter interface { // DecObjectCounter must decrement shard's object counter taking into account // object type. DecObjectCounter(objectType string) + // SetShardID must set (update) the shard identifier that will be used in + // metrics. + SetShardID(id string) } type cfg struct {