From e96eb3e00bdccd7dbe8ea97e1cd078190338413d Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 28 Dec 2021 13:39:42 +0300 Subject: [PATCH] [#1054] neofs-node: add epoch metric Signed-off-by: Evgenii Stratonikov --- cmd/neofs-node/config.go | 1 + cmd/neofs-node/netmap.go | 6 ++++++ pkg/metrics/metrics.go | 17 +++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index 532599198..b4b5cc422 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -316,6 +316,7 @@ func initCfg(path string) *cfg { if metricsconfig.Address(c.appCfg) != "" { c.metricsCollector = metrics.NewStorageMetrics() + netState.metrics = c.metricsCollector } c.onShutdown(c.clientCache.CloseAll) // clean up connections diff --git a/cmd/neofs-node/netmap.go b/cmd/neofs-node/netmap.go index 453b484dd..948e63f0e 100644 --- a/cmd/neofs-node/netmap.go +++ b/cmd/neofs-node/netmap.go @@ -10,6 +10,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/v2/refs" nodeconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/node" "github.com/nspcc-dev/neofs-node/pkg/core/netmap" + "github.com/nspcc-dev/neofs-node/pkg/metrics" "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper" "github.com/nspcc-dev/neofs-node/pkg/morph/event" netmapEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap" @@ -30,6 +31,8 @@ type networkState struct { controlNetStatus atomic.Value // control.NetmapStatus nodeInfo atomic.Value // *netmapSDK.NodeInfo + + metrics *metrics.StorageMetrics } func newNetworkState() *networkState { @@ -44,6 +47,9 @@ func (s *networkState) CurrentEpoch() uint64 { func (s *networkState) setCurrentEpoch(v uint64) { s.epoch.Store(v) + if s.metrics != nil { + s.metrics.SetEpoch(v) + } } func (s *networkState) setNodeInfo(ni *netmapSDK.NodeInfo) { diff --git a/pkg/metrics/metrics.go b/pkg/metrics/metrics.go index 01e246dc9..e21fce099 100644 --- a/pkg/metrics/metrics.go +++ b/pkg/metrics/metrics.go @@ -1,10 +1,13 @@ package metrics +import "github.com/prometheus/client_golang/prometheus" + const namespace = "neofs_node" type StorageMetrics struct { objectServiceMetrics engineMetrics + epoch prometheus.Gauge } func NewStorageMetrics() *StorageMetrics { @@ -14,8 +17,22 @@ func NewStorageMetrics() *StorageMetrics { engine := newEngineMetrics() engine.register() + epoch := prometheus.NewGauge(prometheus.GaugeOpts{ + Namespace: namespace, + Subsystem: innerRingSubsystem, + Name: "epoch", + Help: "Current epoch as seen by inner-ring node.", + }) + prometheus.MustRegister(epoch) + return &StorageMetrics{ objectServiceMetrics: objectService, engineMetrics: engine, + epoch: epoch, } } + +// SetEpoch updates epoch metric. +func (m *StorageMetrics) SetEpoch(epoch uint64) { + m.epoch.Set(float64(epoch)) +}