From 9c7b3ce79930588b3d6ba7cb7ebe881488ff024b Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Fri, 19 Aug 2022 20:24:05 +0300 Subject: [PATCH] [#1658] node: Read metrics from meta on startup Signed-off-by: Pavel Karpy --- pkg/local_object_storage/engine/metrics.go | 1 + pkg/local_object_storage/engine/shards.go | 4 ++++ pkg/local_object_storage/shard/control.go | 2 ++ pkg/local_object_storage/shard/shard.go | 17 +++++++++++++++++ pkg/metrics/object.go | 4 ++++ 5 files changed, 28 insertions(+) diff --git a/pkg/local_object_storage/engine/metrics.go b/pkg/local_object_storage/engine/metrics.go index 254a7d6d..98aacb77 100644 --- a/pkg/local_object_storage/engine/metrics.go +++ b/pkg/local_object_storage/engine/metrics.go @@ -17,6 +17,7 @@ type MetricRegister interface { AddSearchDuration(d time.Duration) AddListObjectsDuration(d time.Duration) + SetObjectCounter(shardID string, v uint64) AddToObjectCounter(shardID string, delta int) } diff --git a/pkg/local_object_storage/engine/shards.go b/pkg/local_object_storage/engine/shards.go index db72fd8b..d0a7fe0c 100644 --- a/pkg/local_object_storage/engine/shards.go +++ b/pkg/local_object_storage/engine/shards.go @@ -22,6 +22,10 @@ type metricsWithID struct { mw MetricRegister } +func (m metricsWithID) SetObjectCounter(v uint64) { + m.mw.SetObjectCounter(m.id, v) +} + func (m metricsWithID) AddToObjectCounter(delta int) { m.mw.AddToObjectCounter(m.id, delta) } diff --git a/pkg/local_object_storage/shard/control.go b/pkg/local_object_storage/shard/control.go index 7ca5f8a3..76e582dc 100644 --- a/pkg/local_object_storage/shard/control.go +++ b/pkg/local_object_storage/shard/control.go @@ -120,6 +120,8 @@ func (s *Shard) Init() error { } } + s.updateObjectCounter() + s.gc = &gc{ gcCfg: s.gcCfg, remover: s.removeGarbage, diff --git a/pkg/local_object_storage/shard/shard.go b/pkg/local_object_storage/shard/shard.go index bd54fc94..0785637c 100644 --- a/pkg/local_object_storage/shard/shard.go +++ b/pkg/local_object_storage/shard/shard.go @@ -47,6 +47,8 @@ type DeletedLockCallback func(context.Context, []oid.Address) // MetricsWriter is an interface that must store shard's metrics. type MetricsWriter interface { + // SetObjectCounter must set object counter. + SetObjectCounter(v uint64) // AddToObjectCounter must update object counter. Negative // parameter must decrease the counter. AddToObjectCounter(delta int) @@ -293,6 +295,21 @@ func (s *Shard) fillInfo() { } } +func (s *Shard) updateObjectCounter() { + if s.cfg.metricsWriter != nil && !s.GetMode().NoMetabase() { + c, err := s.metaBase.ObjectCounter() + if err != nil { + s.log.Warn("meta: object counter read", + zap.Error(err), + ) + + return + } + + s.cfg.metricsWriter.SetObjectCounter(c) + } +} + func (s *Shard) incObjectCounter() { if s.cfg.metricsWriter != nil { s.cfg.metricsWriter.IncObjectCounter() diff --git a/pkg/metrics/object.go b/pkg/metrics/object.go index e5c0292c..5c4d2396 100644 --- a/pkg/metrics/object.go +++ b/pkg/metrics/object.go @@ -274,3 +274,7 @@ func (m objectServiceMetrics) AddGetPayload(ln int) { func (m objectServiceMetrics) AddToObjectCounter(shardID string, delta int) { m.shardMetrics.With(prometheus.Labels{shardIDLabelKey: shardID}).Add(float64(delta)) } + +func (m objectServiceMetrics) SetObjectCounter(shardID string, v uint64) { + m.shardMetrics.With(prometheus.Labels{shardIDLabelKey: shardID}).Set(float64(v)) +}