[#371] ir: Add morph cache metrics
All checks were successful
ci/woodpecker/push/pre-commit Pipeline was successful

Signed-off-by: Airat Arifullin a.arifullin@yadro.com
This commit is contained in:
Airat Arifullin 2023-05-26 12:15:50 +03:00 committed by Evgenii Stratonikov
parent 4f83ab0fb4
commit 90e9247b69
11 changed files with 154 additions and 27 deletions

View file

@ -7,6 +7,7 @@ import (
"time"
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/metrics"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
lru "github.com/hashicorp/golang-lru/v2"
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
@ -42,6 +43,8 @@ type cfg struct {
inactiveModeCb Callback
switchInterval time.Duration
morphCacheMetrics metrics.MorphCacheMetrics
}
const (
@ -104,7 +107,7 @@ func New(ctx context.Context, key *keys.PrivateKey, opts ...Option) (*Client, er
}
cli := &Client{
cache: newClientCache(),
cache: newClientCache(cfg.morphCacheMetrics),
logger: cfg.logger,
acc: acc,
accAddr: accAddr,
@ -195,10 +198,11 @@ func newActor(ws *rpcclient.WSClient, acc *wallet.Account, cfg cfg) (*actor.Acto
}})
}
func newClientCache() cache {
func newClientCache(morphCacheMetrics metrics.MorphCacheMetrics) cache {
c, _ := lru.New[util.Uint256, uint32](100) // returns error only if size is negative
return cache{
txHeights: c,
metrics: morphCacheMetrics,
}
}
@ -282,3 +286,9 @@ func WithSwitchInterval(i time.Duration) Option {
c.switchInterval = i
}
}
func WithMorphCacheMetrics(morphCacheMetrics metrics.MorphCacheMetrics) Option {
return func(c *cfg) {
c.morphCacheMetrics = morphCacheMetrics
}
}