From e1137aa09fdb634ac1c1a0c2740fd331ee4808b3 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 27 Dec 2021 15:24:05 +0300 Subject: [PATCH] [#1054] innerring: add epoch metric Signed-off-by: Evgenii Stratonikov --- pkg/innerring/innerring.go | 9 +++++++++ pkg/innerring/state.go | 3 +++ pkg/metrics/innerring.go | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 pkg/metrics/innerring.go diff --git a/pkg/innerring/innerring.go b/pkg/innerring/innerring.go index 350a3f3c6..79035c9a7 100644 --- a/pkg/innerring/innerring.go +++ b/pkg/innerring/innerring.go @@ -28,6 +28,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/innerring/processors/settlement" auditSettlement "github.com/nspcc-dev/neofs-node/pkg/innerring/processors/settlement/audit" timerEvent "github.com/nspcc-dev/neofs-node/pkg/innerring/timers" + "github.com/nspcc-dev/neofs-node/pkg/metrics" "github.com/nspcc-dev/neofs-node/pkg/morph/client" auditWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/audit/wrapper" balanceWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/balance/wrapper" @@ -80,6 +81,9 @@ type ( netmapClient *nmWrapper.Wrapper persistate *state.PersistentStorage + // metrics + metrics *metrics.InnerRingServiceMetrics + // notary configuration feeConfig *config.FeeConfig mainNotaryConfig *notaryConfig @@ -909,6 +913,11 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error queueSize: cfg.GetUint32("workers.subnet"), }) + if cfg.GetString("metrics.address") != "" { + m := metrics.NewInnerRingMetrics() + server.metrics = &m + } + return server, nil } diff --git a/pkg/innerring/state.go b/pkg/innerring/state.go index c4cfb1d45..0d225f103 100644 --- a/pkg/innerring/state.go +++ b/pkg/innerring/state.go @@ -30,6 +30,9 @@ func (s *Server) EpochCounter() uint64 { // epoch counter. func (s *Server) SetEpochCounter(val uint64) { s.epochCounter.Store(val) + if s.metrics != nil { + s.metrics.SetEpoch(val) + } } // EpochDuration is a getter for a global epoch duration. diff --git a/pkg/metrics/innerring.go b/pkg/metrics/innerring.go new file mode 100644 index 000000000..487edc192 --- /dev/null +++ b/pkg/metrics/innerring.go @@ -0,0 +1,33 @@ +package metrics + +import "github.com/prometheus/client_golang/prometheus" + +const innerRingSubsystem = "object" + +// InnerRingServiceMetrics contains metrics collected by inner ring. +type InnerRingServiceMetrics struct { + epoch prometheus.Gauge +} + +// NewInnerRingMetrics returns new instance of metrics collectors for inner ring. +func NewInnerRingMetrics() InnerRingServiceMetrics { + var ( + epoch = prometheus.NewGauge(prometheus.GaugeOpts{ + Namespace: namespace, + Subsystem: innerRingSubsystem, + Name: "epoch", + Help: "Current epoch as seen by inner-ring node.", + }) + ) + + prometheus.MustRegister(epoch) + + return InnerRingServiceMetrics{ + epoch: epoch, + } +} + +// SetEpoch updates epoch metrics. +func (m InnerRingServiceMetrics) SetEpoch(epoch uint64) { + m.epoch.Set(float64(epoch)) +}