From 994f48f8bba365c22ca15dbba83275f87957c6a7 Mon Sep 17 00:00:00 2001 From: Anton Nikiforov Date: Wed, 4 Oct 2023 10:03:37 +0300 Subject: [PATCH] [#680] metrics: Export log and morph with script Signed-off-by: Anton Nikiforov --- cmd/frostfs-node/morph.go | 5 ++--- pkg/metrics/morph.go | 3 +-- pkg/metrics/morphcache.go | 4 ---- pkg/metrics/node.go | 13 +++++++++++++ pkg/util/logger/logger.go | 2 +- pkg/util/logger/metrics.go | 8 ++++---- scripts/export-metrics/main.go | 3 +++ 7 files changed, 24 insertions(+), 14 deletions(-) diff --git a/cmd/frostfs-node/morph.go b/cmd/frostfs-node/morph.go index 63d1605e..5c3db0d2 100644 --- a/cmd/frostfs-node/morph.go +++ b/cmd/frostfs-node/morph.go @@ -9,7 +9,6 @@ import ( morphconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/morph" "git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/netmap" - "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/metrics" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client" nmClient "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/netmap" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event" @@ -42,13 +41,13 @@ func initMorphComponents(ctx context.Context, c *cfg) { c.key, client.WithDialTimeout(morphconfig.DialTimeout(c.appCfg)), client.WithLogger(c.log), - client.WithMetrics(metrics.NewMorphClientMetrics()), + client.WithMetrics(c.metricsCollector.MorphClientMetrics()), client.WithEndpoints(addresses...), client.WithConnLostCallback(func() { c.internalErr <- errors.New("morph connection has been lost") }), client.WithSwitchInterval(morphconfig.SwitchInterval(c.appCfg)), - client.WithMorphCacheMetrics(metrics.NewNodeMorphCacheMetrics()), + client.WithMorphCacheMetrics(c.metricsCollector.MorphCacheMetrics()), ) if err != nil { c.log.Info(logs.FrostFSNodeFailedToCreateNeoRPCClient, diff --git a/pkg/metrics/morph.go b/pkg/metrics/morph.go index 5215c674..02d7517b 100644 --- a/pkg/metrics/morph.go +++ b/pkg/metrics/morph.go @@ -4,7 +4,6 @@ import ( "strconv" "time" - morphmetrics "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/metrics" "git.frostfs.info/TrueCloudLab/frostfs-observability/metrics" "github.com/prometheus/client_golang/prometheus" ) @@ -16,7 +15,7 @@ type morphClientMetrics struct { invokeDuration *prometheus.HistogramVec } -func NewMorphClientMetrics() morphmetrics.Register { +func newMorphClientMetrics() *morphClientMetrics { return &morphClientMetrics{ switchCount: metrics.NewCounter(prometheus.CounterOpts{ Namespace: namespace, diff --git a/pkg/metrics/morphcache.go b/pkg/metrics/morphcache.go index a4dbbccf..388cb11e 100644 --- a/pkg/metrics/morphcache.go +++ b/pkg/metrics/morphcache.go @@ -18,10 +18,6 @@ type morphCacheMetrics struct { var _ MorphCacheMetrics = (*morphCacheMetrics)(nil) -func NewNodeMorphCacheMetrics() MorphCacheMetrics { - return newMorphCacheMetrics(namespace) -} - func newMorphCacheMetrics(ns string) *morphCacheMetrics { return &morphCacheMetrics{ methodDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{ diff --git a/pkg/metrics/node.go b/pkg/metrics/node.go index 052defa4..614300aa 100644 --- a/pkg/metrics/node.go +++ b/pkg/metrics/node.go @@ -1,6 +1,7 @@ package metrics import ( + morphmetrics "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/metrics" "git.frostfs.info/TrueCloudLab/frostfs-observability/metrics" "github.com/prometheus/client_golang/prometheus" ) @@ -19,6 +20,8 @@ type NodeMetrics struct { pilorama *piloramaMetrics grpc *grpcServerMetrics policer *policerMetrics + morphClient *morphClientMetrics + morphCache *morphCacheMetrics } func NewNodeMetrics() *NodeMetrics { @@ -41,6 +44,8 @@ func NewNodeMetrics() *NodeMetrics { pilorama: newPiloramaMetrics(), grpc: newGrpcServerMetrics(), policer: newPolicerMetrics(), + morphClient: newMorphClientMetrics(), + morphCache: newMorphCacheMetrics(namespace), } } @@ -96,3 +101,11 @@ func (m *NodeMetrics) GrpcServerMetrics() GrpcServerMetrics { func (m *NodeMetrics) PolicerMetrics() PolicerMetrics { return m.policer } + +func (m *NodeMetrics) MorphClientMetrics() morphmetrics.Register { + return m.morphClient +} + +func (m *NodeMetrics) MorphCacheMetrics() MorphCacheMetrics { + return m.morphCache +} diff --git a/pkg/util/logger/logger.go b/pkg/util/logger/logger.go index fcac0932..cd429776 100644 --- a/pkg/util/logger/logger.go +++ b/pkg/util/logger/logger.go @@ -82,7 +82,7 @@ func NewLogger(prm *Prm) (*Logger, error) { lvl := zap.NewAtomicLevelAt(prm.level) - m := newLogMetrics(prm.MetricsNamespace) + m := NewLogMetrics(prm.MetricsNamespace) c := zap.NewProductionConfig() c.Level = lvl diff --git a/pkg/util/logger/metrics.go b/pkg/util/logger/metrics.go index 70858347..1fa0669a 100644 --- a/pkg/util/logger/metrics.go +++ b/pkg/util/logger/metrics.go @@ -14,12 +14,12 @@ const ( logDroppedLabel = "dropped" ) -type logMetrics struct { +type LogMetrics struct { logCount *prometheus.CounterVec } -func newLogMetrics(namespace string) *logMetrics { - return &logMetrics{ +func NewLogMetrics(namespace string) *LogMetrics { + return &LogMetrics{ logCount: metrics.NewCounterVec(prometheus.CounterOpts{ Namespace: namespace, Subsystem: logSubsystem, @@ -29,7 +29,7 @@ func newLogMetrics(namespace string) *logMetrics { } } -func (m *logMetrics) Inc(level zapcore.Level, dropped bool) { +func (m *LogMetrics) Inc(level zapcore.Level, dropped bool) { m.logCount.With(prometheus.Labels{ logLevelLabel: level.String(), logDroppedLabel: strconv.FormatBool(dropped), diff --git a/scripts/export-metrics/main.go b/scripts/export-metrics/main.go index f29eca37..45b15526 100644 --- a/scripts/export-metrics/main.go +++ b/scripts/export-metrics/main.go @@ -7,6 +7,7 @@ import ( "os" local_metrics "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/metrics" + "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger" "git.frostfs.info/TrueCloudLab/frostfs-observability/metrics" ) @@ -27,9 +28,11 @@ func main() { switch { case *node != "": _ = local_metrics.NewNodeMetrics() + _ = logger.NewLogMetrics("frostfs_node") filename = *node case *ir != "": _ = local_metrics.NewInnerRingMetrics() + _ = logger.NewLogMetrics("frostfs_ir") filename = *ir default: