From 02831d427b01ae0152e4238721c003c987e979e5 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Wed, 5 Apr 2023 12:43:32 +0300 Subject: [PATCH] [#213] metrics: Refactor object metrics Resolve funlen linter for newObjectServiceMetrics function. Signed-off-by: Dmitrii Stepanov --- pkg/metrics/object.go | 162 ++++++++++++------------------------------ 1 file changed, 47 insertions(+), 115 deletions(-) diff --git a/pkg/metrics/object.go b/pkg/metrics/object.go index ffa5d481d..fae86cb4a 100644 --- a/pkg/metrics/object.go +++ b/pkg/metrics/object.go @@ -2,6 +2,7 @@ package metrics import ( "fmt" + "strings" "time" "github.com/prometheus/client_golang/prometheus" @@ -46,7 +47,7 @@ const ( containerIDLabelKey = "cid" ) -func newMethodCallCounter(name string) methodCount { +func newObjectMethodCallCounter(name string) methodCount { return methodCount{ success: prometheus.NewCounter(prometheus.CounterOpts{ Namespace: namespace, @@ -75,125 +76,56 @@ func (m methodCount) Inc(success bool) { } } -// nolint: funlen func newObjectServiceMetrics() objectServiceMetrics { - var ( // Request counter metrics. - getCounter = newMethodCallCounter("get") - putCounter = newMethodCallCounter("put") - headCounter = newMethodCallCounter("head") - searchCounter = newMethodCallCounter("search") - deleteCounter = newMethodCallCounter("delete") - rangeCounter = newMethodCallCounter("range") - rangeHashCounter = newMethodCallCounter("range_hash") - ) - - var ( // Request duration metrics. - getDuration = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Subsystem: objectSubsystem, - Name: "get_req_duration", - Help: "Accumulated get request process duration", - }) - - putDuration = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Subsystem: objectSubsystem, - Name: "put_req_duration", - Help: "Accumulated put request process duration", - }) - - headDuration = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Subsystem: objectSubsystem, - Name: "head_req_duration", - Help: "Accumulated head request process duration", - }) - - searchDuration = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Subsystem: objectSubsystem, - Name: "search_req_duration", - Help: "Accumulated search request process duration", - }) - - deleteDuration = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Subsystem: objectSubsystem, - Name: "delete_req_duration", - Help: "Accumulated delete request process duration", - }) - - rangeDuration = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Subsystem: objectSubsystem, - Name: "range_req_duration", - Help: "Accumulated range request process duration", - }) - - rangeHashDuration = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Subsystem: objectSubsystem, - Name: "range_hash_req_duration", - Help: "Accumulated range hash request process duration", - }) - ) - - var ( // Object payload metrics. - putPayload = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Subsystem: objectSubsystem, - Name: "put_payload", - Help: "Accumulated payload size at object put method", - }) - - getPayload = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Subsystem: objectSubsystem, - Name: "get_payload", - Help: "Accumulated payload size at object get method", - }) - - shardsMetrics = prometheus.NewGaugeVec(prometheus.GaugeOpts{ - Namespace: namespace, - Subsystem: objectSubsystem, - Name: "counter", - Help: "Objects counters per shards", - }, - []string{shardIDLabelKey, counterTypeLabelKey}, - ) - - shardsReadonly = prometheus.NewGaugeVec(prometheus.GaugeOpts{ - Namespace: namespace, - Subsystem: objectSubsystem, - Name: "readonly", - Help: "Shard state", - }, - []string{shardIDLabelKey}, - ) - ) - return objectServiceMetrics{ - getCounter: getCounter, - putCounter: putCounter, - headCounter: headCounter, - searchCounter: searchCounter, - deleteCounter: deleteCounter, - rangeCounter: rangeCounter, - rangeHashCounter: rangeHashCounter, - getDuration: getDuration, - putDuration: putDuration, - headDuration: headDuration, - searchDuration: searchDuration, - deleteDuration: deleteDuration, - rangeDuration: rangeDuration, - rangeHashDuration: rangeHashDuration, - putPayload: putPayload, - getPayload: getPayload, - shardMetrics: shardsMetrics, - shardsReadonly: shardsReadonly, + getCounter: newObjectMethodCallCounter("get"), + putCounter: newObjectMethodCallCounter("put"), + headCounter: newObjectMethodCallCounter("head"), + searchCounter: newObjectMethodCallCounter("search"), + deleteCounter: newObjectMethodCallCounter("delete"), + rangeCounter: newObjectMethodCallCounter("range"), + rangeHashCounter: newObjectMethodCallCounter("range_hash"), + getDuration: newObjectMethodDurationCounter("get"), + putDuration: newObjectMethodDurationCounter("put"), + headDuration: newObjectMethodDurationCounter("head"), + searchDuration: newObjectMethodDurationCounter("search"), + deleteDuration: newObjectMethodDurationCounter("delete"), + rangeDuration: newObjectMethodDurationCounter("range"), + rangeHashDuration: newObjectMethodDurationCounter("range_hash"), + putPayload: newObjectMethodPayloadCounter("put"), + getPayload: newObjectMethodPayloadCounter("get"), + shardMetrics: newObjectGaugeVector("counter", "Objects counters per shards", []string{shardIDLabelKey, counterTypeLabelKey}), + shardsReadonly: newObjectGaugeVector("readonly", "Shard state", []string{shardIDLabelKey}), } } +func newObjectMethodPayloadCounter(method string) prometheus.Counter { + return prometheus.NewCounter(prometheus.CounterOpts{ + Namespace: namespace, + Subsystem: objectSubsystem, + Name: fmt.Sprintf("%s_payload", method), + Help: fmt.Sprintf("Accumulated payload size at object %s method", strings.ReplaceAll(method, "_", " ")), + }) +} + +func newObjectMethodDurationCounter(method string) prometheus.Counter { + return prometheus.NewCounter(prometheus.CounterOpts{ + Namespace: namespace, + Subsystem: objectSubsystem, + Name: fmt.Sprintf("%s_req_duration", method), + Help: fmt.Sprintf("Accumulated %s request process duration", strings.ReplaceAll(method, "_", " ")), + }) +} + +func newObjectGaugeVector(name, help string, labels []string) *prometheus.GaugeVec { + return prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Namespace: namespace, + Subsystem: objectSubsystem, + Name: name, + Help: help, + }, labels) +} + func (m objectServiceMetrics) register() { m.getCounter.mustRegister() m.putCounter.mustRegister()