[#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 <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-10-12 20:55:35 +03:00 committed by Pavel Karpy
parent 8714fc42b5
commit 31c623636d
5 changed files with 21 additions and 5 deletions

View file

@ -42,6 +42,7 @@ Changelog for NeoFS Node
- `control drop-objects` can remove split objects (#1830) - `control drop-objects` can remove split objects (#1830)
- Node's status in `neofs-cli netmap nodeinfo` command (#1833) - Node's status in `neofs-cli netmap nodeinfo` command (#1833)
- Child check in object assembly process of `ObjectService.Get` handler (#1878) - Child check in object assembly process of `ObjectService.Get` handler (#1878)
- Shard ID in the object counter metrics (#1863)
### Removed ### Removed
- Remove WIF and NEP2 support in `neofs-cli`'s --wallet flag (#1128) - Remove WIF and NEP2 support in `neofs-cli`'s --wallet flag (#1128)

View file

@ -23,19 +23,25 @@ type metricsWithID struct {
mw MetricRegister 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) 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) 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) 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) 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 { if e.metrics != nil {
opts = append(opts, shard.WithMetricsWriter( opts = append(opts, shard.WithMetricsWriter(
metricsWithID{ &metricsWithID{
id: id.String(), id: id.String(),
mw: e.metrics, mw: e.metrics,
}, },

View file

@ -43,6 +43,10 @@ func (s *Shard) UpdateID() (err error) {
} }
if len(id) != 0 { if len(id) != 0 {
s.info.ID = NewIDFromBytes(id) 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()))} s.log = &logger.Logger{Logger: s.log.With(zap.String("shard_id", s.info.ID.String()))}

View file

@ -19,6 +19,8 @@ type metricsStore struct {
s map[string]uint64 s map[string]uint64
} }
func (m metricsStore) SetShardID(_ string) {}
func (m metricsStore) SetObjectCounter(objectType string, v uint64) { func (m metricsStore) SetObjectCounter(objectType string, v uint64) {
m.s[objectType] = v m.s[objectType] = v
} }

View file

@ -59,6 +59,9 @@ type MetricsWriter interface {
// DecObjectCounter must decrement shard's object counter taking into account // DecObjectCounter must decrement shard's object counter taking into account
// object type. // object type.
DecObjectCounter(objectType string) DecObjectCounter(objectType string)
// SetShardID must set (update) the shard identifier that will be used in
// metrics.
SetShardID(id string)
} }
type cfg struct { type cfg struct {