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

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
remotes/fyrchik/fix-grpc-timeout-backup
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)
AddListObjectsDuration(d time.Duration)
SetObjectCounter(shardID string, v uint64)
AddToObjectCounter(shardID string, delta int)
}

View File

@ -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)
}

View File

@ -120,6 +120,8 @@ func (s *Shard) Init() error {
}
}
s.updateObjectCounter()
s.gc = &gc{
gcCfg: s.gcCfg,
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.
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()

View File

@ -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))
}