From 5e229dc2481c3a745ec702f6c74353e648ce649d Mon Sep 17 00:00:00 2001 From: Ekaterina Lebedeva Date: Wed, 4 Oct 2023 19:20:59 +0300 Subject: [PATCH] [#701] metrics: add metric to evaluate policer performance Add processed objects counter in policerMetrics, add policer field to NodeMetrics Signed-off-by: Ekaterina Lebedeva --- pkg/metrics/consts.go | 1 + pkg/metrics/node.go | 6 ++++++ pkg/metrics/policer.go | 29 +++++++++++++++++++++++++++++ pkg/services/policer/metrics.go | 5 +++++ pkg/services/policer/option.go | 2 ++ pkg/services/policer/process.go | 1 + 6 files changed, 44 insertions(+) create mode 100644 pkg/metrics/policer.go create mode 100644 pkg/services/policer/metrics.go diff --git a/pkg/metrics/consts.go b/pkg/metrics/consts.go index 550eec42..f7a8fd77 100644 --- a/pkg/metrics/consts.go +++ b/pkg/metrics/consts.go @@ -20,6 +20,7 @@ const ( treeServiceSubsystem = "treeservice" writeCacheSubsystem = "writecache" grpcServerSubsystem = "grpc_server" + policerSubsystem = "policer" successLabel = "success" shardIDLabel = "shard_id" diff --git a/pkg/metrics/node.go b/pkg/metrics/node.go index ad6864b8..052defa4 100644 --- a/pkg/metrics/node.go +++ b/pkg/metrics/node.go @@ -18,6 +18,7 @@ type NodeMetrics struct { metabase *metabaseMetrics pilorama *piloramaMetrics grpc *grpcServerMetrics + policer *policerMetrics } func NewNodeMetrics() *NodeMetrics { @@ -39,6 +40,7 @@ func NewNodeMetrics() *NodeMetrics { metabase: newMetabaseMetrics(), pilorama: newPiloramaMetrics(), grpc: newGrpcServerMetrics(), + policer: newPolicerMetrics(), } } @@ -90,3 +92,7 @@ func (m *NodeMetrics) PiloramaMetrics() PiloramaMetrics { func (m *NodeMetrics) GrpcServerMetrics() GrpcServerMetrics { return m.grpc } + +func (m *NodeMetrics) PolicerMetrics() PolicerMetrics { + return m.policer +} diff --git a/pkg/metrics/policer.go b/pkg/metrics/policer.go new file mode 100644 index 00000000..e4bdc944 --- /dev/null +++ b/pkg/metrics/policer.go @@ -0,0 +1,29 @@ +package metrics + +import ( + "git.frostfs.info/TrueCloudLab/frostfs-observability/metrics" + "github.com/prometheus/client_golang/prometheus" +) + +type PolicerMetrics interface { + IncProcessedObjects() +} + +type policerMetrics struct { + processedObjectsCounter prometheus.Counter +} + +func newPolicerMetrics() *policerMetrics { + return &policerMetrics{ + processedObjectsCounter: metrics.NewCounter(prometheus.CounterOpts{ + Namespace: namespace, + Subsystem: policerSubsystem, + Name: "processed_objects_total", + Help: "Total number of objects processed by policer", + }), + } +} + +func (m *policerMetrics) IncProcessedObjects() { + m.processedObjectsCounter.Inc() +} diff --git a/pkg/services/policer/metrics.go b/pkg/services/policer/metrics.go new file mode 100644 index 00000000..0b83f298 --- /dev/null +++ b/pkg/services/policer/metrics.go @@ -0,0 +1,5 @@ +package policer + +type MetricsRegister interface { + IncProcessedObjects() +} diff --git a/pkg/services/policer/option.go b/pkg/services/policer/option.go index 5058b026..3a2fdc50 100644 --- a/pkg/services/policer/option.go +++ b/pkg/services/policer/option.go @@ -69,6 +69,8 @@ type cfg struct { batchSize, cacheSize uint32 rebalanceFreq, evictDuration, sleepDuration time.Duration + + metrics MetricsRegister } func defaultCfg() *cfg { diff --git a/pkg/services/policer/process.go b/pkg/services/policer/process.go index 2e8fe929..873a1efb 100644 --- a/pkg/services/policer/process.go +++ b/pkg/services/policer/process.go @@ -60,6 +60,7 @@ func (p *Policer) shardPolicyWorker(ctx context.Context) { } p.cache.Add(addr.Address, time.Now()) p.objsInWork.remove(addr.Address) + p.metrics.IncProcessedObjects() } }) if err != nil {