From 26b305f82b830eebf6c727f013606b576299e45d Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Wed, 14 Jun 2023 12:12:47 +0300 Subject: [PATCH] [#424] morph: Fix cache metrics Use separate morph cache metrics for node and IR Signed-off-by: Dmitrii Stepanov --- cmd/frostfs-node/morph.go | 3 +-- pkg/metrics/innerring.go | 9 +++++---- pkg/metrics/morphcache.go | 8 ++++++-- pkg/morph/client/constructor.go | 1 + pkg/morph/metrics/metrics.go | 4 ++++ 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/cmd/frostfs-node/morph.go b/cmd/frostfs-node/morph.go index ae50b8a8a..63d1605ef 100644 --- a/cmd/frostfs-node/morph.go +++ b/cmd/frostfs-node/morph.go @@ -30,8 +30,6 @@ const ( ) func initMorphComponents(ctx context.Context, c *cfg) { - var err error - addresses := morphconfig.RPCEndpoint(c.appCfg) // Morph client stable-sorts endpoints by priority. Shuffle here to randomize @@ -50,6 +48,7 @@ func initMorphComponents(ctx context.Context, c *cfg) { c.internalErr <- errors.New("morph connection has been lost") }), client.WithSwitchInterval(morphconfig.SwitchInterval(c.appCfg)), + client.WithMorphCacheMetrics(metrics.NewNodeMorphCacheMetrics()), ) if err != nil { c.log.Info(logs.FrostFSNodeFailedToCreateNeoRPCClient, diff --git a/pkg/metrics/innerring.go b/pkg/metrics/innerring.go index b3cb3e285..0aee068c5 100644 --- a/pkg/metrics/innerring.go +++ b/pkg/metrics/innerring.go @@ -12,6 +12,7 @@ const ( innerRingSubsystem = "ir" innerRingLabelSuccess = "success" innerRingLabelType = "type" + innerRingNamespace = "frostfs_ir" ) // InnerRingServiceMetrics contains metrics collected by inner ring. @@ -26,19 +27,19 @@ type InnerRingServiceMetrics struct { func NewInnerRingMetrics() *InnerRingServiceMetrics { var ( epoch = metrics.NewGauge(prometheus.GaugeOpts{ - Namespace: namespace, + Namespace: innerRingNamespace, Subsystem: innerRingSubsystem, Name: "epoch", Help: "Current epoch as seen by inner-ring node.", }) health = metrics.NewGauge(prometheus.GaugeOpts{ - Namespace: namespace, + Namespace: innerRingNamespace, Subsystem: innerRingSubsystem, Name: "health", Help: "Current inner-ring node state.", }) eventDuration = metrics.NewHistogramVec(prometheus.HistogramOpts{ - Namespace: namespace, + Namespace: innerRingNamespace, Subsystem: innerRingSubsystem, Name: "event_duration_seconds", Help: "Duration of processing of inner-ring events", @@ -49,7 +50,7 @@ func NewInnerRingMetrics() *InnerRingServiceMetrics { epoch: epoch, health: health, eventDuration: eventDuration, - morphCacheMetrics: newMorphCacheMetrics(), + morphCacheMetrics: newMorphCacheMetrics(innerRingNamespace), } } diff --git a/pkg/metrics/morphcache.go b/pkg/metrics/morphcache.go index 9cf2c8a0c..3f215b5bf 100644 --- a/pkg/metrics/morphcache.go +++ b/pkg/metrics/morphcache.go @@ -24,10 +24,14 @@ type morphCacheMetrics struct { var _ MorphCacheMetrics = (*morphCacheMetrics)(nil) -func newMorphCacheMetrics() *morphCacheMetrics { +func NewNodeMorphCacheMetrics() MorphCacheMetrics { + return newMorphCacheMetrics(namespace) +} + +func newMorphCacheMetrics(ns string) *morphCacheMetrics { return &morphCacheMetrics{ methodDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{ - Namespace: namespace, + Namespace: ns, Subsystem: mcSubsystem, Name: "request_duration_seconds", Help: "Morph cache request process duration", diff --git a/pkg/morph/client/constructor.go b/pkg/morph/client/constructor.go index 6cc66c5cc..e7e1bbca9 100644 --- a/pkg/morph/client/constructor.go +++ b/pkg/morph/client/constructor.go @@ -68,6 +68,7 @@ func defaultConfig() *cfg { signer: &transaction.Signer{ Scopes: transaction.Global, }, + morphCacheMetrics: &morphmetrics.NoopMorphCacheMetrics{}, } } diff --git a/pkg/morph/metrics/metrics.go b/pkg/morph/metrics/metrics.go index 9e41a0b86..5d74b054d 100644 --- a/pkg/morph/metrics/metrics.go +++ b/pkg/morph/metrics/metrics.go @@ -15,3 +15,7 @@ func (NoopRegister) IncSwitchCount() { func (NoopRegister) SetLastBlock(uint32) {} func (NoopRegister) IncNotificationCount(string) {} func (NoopRegister) ObserveInvoke(string, string, string, bool, time.Duration) {} + +type NoopMorphCacheMetrics struct{} + +func (m *NoopMorphCacheMetrics) AddMethodDuration(string, bool, time.Duration) {}