[#1658] node: Read metrics from meta on startup

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-08-19 20:24:05 +03:00 committed by fyrchik
parent 745f72fff0
commit 9c7b3ce799
5 changed files with 28 additions and 0 deletions

View file

@ -17,6 +17,7 @@ type MetricRegister interface {
AddSearchDuration(d time.Duration) AddSearchDuration(d time.Duration)
AddListObjectsDuration(d time.Duration) AddListObjectsDuration(d time.Duration)
SetObjectCounter(shardID string, v uint64)
AddToObjectCounter(shardID string, delta int) AddToObjectCounter(shardID string, delta int)
} }

View file

@ -22,6 +22,10 @@ type metricsWithID struct {
mw MetricRegister mw MetricRegister
} }
func (m metricsWithID) SetObjectCounter(v uint64) {
m.mw.SetObjectCounter(m.id, v)
}
func (m metricsWithID) AddToObjectCounter(delta int) { func (m metricsWithID) AddToObjectCounter(delta int) {
m.mw.AddToObjectCounter(m.id, delta) m.mw.AddToObjectCounter(m.id, delta)
} }

View file

@ -120,6 +120,8 @@ func (s *Shard) Init() error {
} }
} }
s.updateObjectCounter()
s.gc = &gc{ s.gc = &gc{
gcCfg: s.gcCfg, gcCfg: s.gcCfg,
remover: s.removeGarbage, remover: s.removeGarbage,

View file

@ -47,6 +47,8 @@ type DeletedLockCallback func(context.Context, []oid.Address)
// MetricsWriter is an interface that must store shard's metrics. // MetricsWriter is an interface that must store shard's metrics.
type MetricsWriter interface { type MetricsWriter interface {
// SetObjectCounter must set object counter.
SetObjectCounter(v uint64)
// AddToObjectCounter must update object counter. Negative // AddToObjectCounter must update object counter. Negative
// parameter must decrease the counter. // parameter must decrease the counter.
AddToObjectCounter(delta int) 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() { func (s *Shard) incObjectCounter() {
if s.cfg.metricsWriter != nil { if s.cfg.metricsWriter != nil {
s.cfg.metricsWriter.IncObjectCounter() s.cfg.metricsWriter.IncObjectCounter()

View file

@ -274,3 +274,7 @@ func (m objectServiceMetrics) AddGetPayload(ln int) {
func (m objectServiceMetrics) AddToObjectCounter(shardID string, delta int) { func (m objectServiceMetrics) AddToObjectCounter(shardID string, delta int) {
m.shardMetrics.With(prometheus.Labels{shardIDLabelKey: shardID}).Add(float64(delta)) 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))
}