[#1658] node: Support object counter metrics

Increment shard's object counter on successful `Put` calls and decrement on
`Delete`.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-08-19 19:49:09 +03:00 committed by fyrchik
parent 067ab44e0b
commit 745f72fff0
7 changed files with 87 additions and 15 deletions

View file

@ -17,6 +17,23 @@ var errShardNotFound = errors.New("shard not found")
type hashedShard shardWrapper
type metricsWithID struct {
id string
mw MetricRegister
}
func (m metricsWithID) AddToObjectCounter(delta int) {
m.mw.AddToObjectCounter(m.id, delta)
}
func (m metricsWithID) IncObjectCounter() {
m.mw.AddToObjectCounter(m.id, +1)
}
func (m metricsWithID) DecObjectCounter() {
m.mw.AddToObjectCounter(m.id, -1)
}
// AddShard adds a new shard to the storage engine.
//
// Returns any error encountered that did not allow adding a shard.
@ -35,6 +52,15 @@ func (e *StorageEngine) AddShard(opts ...shard.Option) (*shard.ID, error) {
return nil, fmt.Errorf("could not generate shard ID: %w", err)
}
if e.metrics != nil {
opts = append(opts, shard.WithMetricsWriter(
metricsWithID{
id: id.String(),
mw: e.metrics,
},
))
}
sh := shard.New(append(opts,
shard.WithID(id),
shard.WithExpiredTombstonesCallback(e.processExpiredTombstones),