forked from TrueCloudLab/frostfs-node
[#213] metrics: Refactor engine metrics
Resolve funlen linter for newEngineMetrics function. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>fix/118-unit_test
parent
b689027d57
commit
38ae71cc7d
|
@ -1,6 +1,8 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
@ -26,118 +28,49 @@ type (
|
|||
|
||||
const engineSubsystem = "engine"
|
||||
|
||||
// nolint: funlen
|
||||
func newEngineMetrics() engineMetrics {
|
||||
var (
|
||||
listContainersDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: engineSubsystem,
|
||||
Name: "list_containers_duration",
|
||||
Help: "Accumulated duration of engine list containers operations",
|
||||
})
|
||||
|
||||
estimateContainerSizeDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: engineSubsystem,
|
||||
Name: "estimate_container_size_duration",
|
||||
Help: "Accumulated duration of engine container size estimate operations",
|
||||
})
|
||||
|
||||
deleteDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: engineSubsystem,
|
||||
Name: "delete_duration",
|
||||
Help: "Accumulated duration of engine delete operations",
|
||||
})
|
||||
|
||||
existsDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: engineSubsystem,
|
||||
Name: "exists_duration",
|
||||
Help: "Accumulated duration of engine exists operations",
|
||||
})
|
||||
|
||||
getDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: engineSubsystem,
|
||||
Name: "get_duration",
|
||||
Help: "Accumulated duration of engine get operations",
|
||||
})
|
||||
|
||||
headDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: engineSubsystem,
|
||||
Name: "head_duration",
|
||||
Help: "Accumulated duration of engine head operations",
|
||||
})
|
||||
|
||||
inhumeDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: engineSubsystem,
|
||||
Name: "inhume_duration",
|
||||
Help: "Accumulated duration of engine inhume operations",
|
||||
})
|
||||
|
||||
putDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: engineSubsystem,
|
||||
Name: "put_duration",
|
||||
Help: "Accumulated duration of engine put operations",
|
||||
})
|
||||
|
||||
rangeDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: engineSubsystem,
|
||||
Name: "range_duration",
|
||||
Help: "Accumulated duration of engine range operations",
|
||||
})
|
||||
|
||||
searchDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: engineSubsystem,
|
||||
Name: "search_duration",
|
||||
Help: "Accumulated duration of engine search operations",
|
||||
})
|
||||
|
||||
listObjectsDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: engineSubsystem,
|
||||
Name: "list_objects_duration",
|
||||
Help: "Accumulated duration of engine list objects operations",
|
||||
})
|
||||
|
||||
containerSize = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: engineSubsystem,
|
||||
Name: "container_size",
|
||||
Help: "Accumulated size of all objects in a container",
|
||||
}, []string{containerIDLabelKey})
|
||||
|
||||
payloadSize = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: engineSubsystem,
|
||||
Name: "payload_size",
|
||||
Help: "Accumulated size of all objects in a shard",
|
||||
}, []string{shardIDLabelKey})
|
||||
)
|
||||
|
||||
return engineMetrics{
|
||||
listContainersDuration: listContainersDuration,
|
||||
estimateContainerSizeDuration: estimateContainerSizeDuration,
|
||||
deleteDuration: deleteDuration,
|
||||
existsDuration: existsDuration,
|
||||
getDuration: getDuration,
|
||||
headDuration: headDuration,
|
||||
inhumeDuration: inhumeDuration,
|
||||
putDuration: putDuration,
|
||||
rangeDuration: rangeDuration,
|
||||
searchDuration: searchDuration,
|
||||
listObjectsDuration: listObjectsDuration,
|
||||
containerSize: *containerSize,
|
||||
payloadSize: *payloadSize,
|
||||
listContainersDuration: newEngineMethodDurationCounter("list_containers_"),
|
||||
estimateContainerSizeDuration: newEngineCounter("estimate_container_size_duration", "Accumulated duration of engine container size estimate operations"),
|
||||
deleteDuration: newEngineMethodDurationCounter("delete"),
|
||||
existsDuration: newEngineMethodDurationCounter("exists"),
|
||||
getDuration: newEngineMethodDurationCounter("get"),
|
||||
headDuration: newEngineMethodDurationCounter("head"),
|
||||
inhumeDuration: newEngineMethodDurationCounter("inhume"),
|
||||
putDuration: newEngineMethodDurationCounter("put"),
|
||||
rangeDuration: newEngineMethodDurationCounter("range"),
|
||||
searchDuration: newEngineMethodDurationCounter("search"),
|
||||
listObjectsDuration: newEngineMethodDurationCounter("list_objects"),
|
||||
containerSize: *newEngineGaugeVector("container_size", "Accumulated size of all objects in a container", []string{containerIDLabelKey}),
|
||||
payloadSize: *newEngineGaugeVector("payload_size", "Accumulated size of all objects in a shard", []string{shardIDLabelKey}),
|
||||
}
|
||||
}
|
||||
|
||||
func newEngineCounter(name, help string) prometheus.Counter {
|
||||
return prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: engineSubsystem,
|
||||
Name: name,
|
||||
Help: help,
|
||||
})
|
||||
}
|
||||
|
||||
func newEngineMethodDurationCounter(method string) prometheus.Counter {
|
||||
return newEngineCounter(
|
||||
fmt.Sprintf("%s_duration", method),
|
||||
fmt.Sprintf("Accumulated duration of engine %s operations", strings.ReplaceAll(method, "_", " ")),
|
||||
)
|
||||
}
|
||||
|
||||
func newEngineGaugeVector(name, help string, labels []string) *prometheus.GaugeVec {
|
||||
return prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: engineSubsystem,
|
||||
Name: name,
|
||||
Help: help,
|
||||
}, labels)
|
||||
}
|
||||
|
||||
func (m engineMetrics) register() {
|
||||
prometheus.MustRegister(m.listContainersDuration)
|
||||
prometheus.MustRegister(m.estimateContainerSizeDuration)
|
||||
|
|
Loading…
Reference in New Issue