[#373] metrics: Move labels to consts

To unify label naming all lable keys and other consts are moved to
one file.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-06-16 10:13:22 +03:00
parent b5d9f4a285
commit 03aa210145
13 changed files with 119 additions and 160 deletions

View file

@ -1,20 +1,45 @@
package metrics package metrics
const ( const (
namespace = "frostfs_node"
innerRingNamespace = "frostfs_ir"
fstreeSubSystem = "fstree" fstreeSubSystem = "fstree"
blobstoreSubSystem = "blobstore" blobstoreSubSystem = "blobstore"
blobovnizaTreeSubSystem = "blobovniza_tree" blobovnizaTreeSubSystem = "blobovniza_tree"
metabaseSubSystem = "metabase" metabaseSubSystem = "metabase"
piloramaSubSystem = "pilorama" piloramaSubSystem = "pilorama"
engineSubsystem = "engine"
gcSubsystem = "garbage_collector"
innerRingSubsystem = "ir"
morphSubsystem = "morph"
morphCacheSubsystem = "morphcache"
objectSubsystem = "object"
replicatorSubsystem = "replicator"
stateSubsystem = "state"
treeServiceSubsystem = "treeservice"
writeCacheSubsystem = "writecache"
successLabel = "success" successLabel = "success"
shardIDLabel = "shardID" shardIDLabel = "shard_id"
modeLabel = "mode" modeLabel = "mode"
pathLabel = "path" pathLabel = "path"
methodLabel = "method" methodLabel = "method"
withStorageIDLabel = "withStorageID" withStorageIDLabel = "with_storage_id"
statusLabel = "status"
objectTypeLabel = "object_type"
typeLabel = "type"
notificationTypeLabel = "notification_type"
invokeTypeLabel = "invoke_type"
contractLabel = "contract"
containerIDLabelKey = "cid"
storageLabel = "storage"
operationLabel = "operation"
readWriteMode = "READ_WRITE" readWriteMode = "READ_WRITE"
readOnlyMode = "READ_ONLY" readOnlyMode = "READ_ONLY"
closedMode = "CLOSED" closedMode = "CLOSED"
failedToDeleteStatus = "failed_to_delete"
deletedStatus = "deleted"
) )

View file

@ -35,23 +35,18 @@ type engineMetrics struct {
writeCache *writeCacheMetrics writeCache *writeCacheMetrics
} }
const (
engineSubsystem = "engine"
engineMethod = "method"
)
func newEngineMetrics() *engineMetrics { func newEngineMetrics() *engineMetrics {
return &engineMetrics{ return &engineMetrics{
containerSize: newEngineGaugeVector("container_size_bytes", "Accumulated size of all objects in a container", []string{containerIDLabelKey}), containerSize: newEngineGaugeVector("container_size_bytes", "Accumulated size of all objects in a container", []string{containerIDLabelKey}),
payloadSize: newEngineGaugeVector("payload_size_bytes", "Accumulated size of all objects in a shard", []string{shardIDLabelKey}), payloadSize: newEngineGaugeVector("payload_size_bytes", "Accumulated size of all objects in a shard", []string{shardIDLabel}),
errorCounter: newEngineGaugeVector("errors_total", "Shard's error counter", []string{shardIDLabelKey}), errorCounter: newEngineGaugeVector("errors_total", "Shard's error counter", []string{shardIDLabel}),
methodDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{ methodDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{
Namespace: namespace, Namespace: namespace,
Subsystem: engineSubsystem, Subsystem: engineSubsystem,
Name: "request_duration_seconds", Name: "request_duration_seconds",
Help: "Duration of Engine requests", Help: "Duration of Engine requests",
}, []string{engineMethod}), }, []string{methodLabel}),
objectCounter: newEngineGaugeVector("objects_total", "Objects counters per shards", []string{shardIDLabelKey, counterTypeLabelKey}), objectCounter: newEngineGaugeVector("objects_total", "Objects counters per shards", []string{shardIDLabel, typeLabel}),
gc: newGCMetrics(), gc: newGCMetrics(),
writeCache: newWriteCacheMetrics(), writeCache: newWriteCacheMetrics(),
mode: newShardIDMode(engineSubsystem, "mode_info", "Shard mode"), mode: newShardIDMode(engineSubsystem, "mode_info", "Shard mode"),
@ -69,7 +64,7 @@ func newEngineGaugeVector(name, help string, labels []string) *prometheus.GaugeV
func (m *engineMetrics) AddMethodDuration(method string, d time.Duration) { func (m *engineMetrics) AddMethodDuration(method string, d time.Duration) {
m.methodDuration.With(prometheus.Labels{ m.methodDuration.With(prometheus.Labels{
engineMethod: method, methodLabel: method,
}).Observe(d.Seconds()) }).Observe(d.Seconds())
} }
@ -78,29 +73,29 @@ func (m *engineMetrics) AddToContainerSize(cnrID string, size int64) {
} }
func (m *engineMetrics) AddToPayloadCounter(shardID string, size int64) { func (m *engineMetrics) AddToPayloadCounter(shardID string, size int64) {
m.payloadSize.With(prometheus.Labels{shardIDLabelKey: shardID}).Add(float64(size)) m.payloadSize.With(prometheus.Labels{shardIDLabel: shardID}).Add(float64(size))
} }
func (m *engineMetrics) IncErrorCounter(shardID string) { func (m *engineMetrics) IncErrorCounter(shardID string) {
m.errorCounter.With(prometheus.Labels{shardIDLabelKey: shardID}).Inc() m.errorCounter.With(prometheus.Labels{shardIDLabel: shardID}).Inc()
} }
func (m *engineMetrics) ClearErrorCounter(shardID string) { func (m *engineMetrics) ClearErrorCounter(shardID string) {
m.errorCounter.With(prometheus.Labels{shardIDLabelKey: shardID}).Set(0) m.errorCounter.With(prometheus.Labels{shardIDLabel: shardID}).Set(0)
} }
func (m *engineMetrics) DeleteShardMetrics(shardID string) { func (m *engineMetrics) DeleteShardMetrics(shardID string) {
m.errorCounter.Delete(prometheus.Labels{shardIDLabelKey: shardID}) m.errorCounter.Delete(prometheus.Labels{shardIDLabel: shardID})
m.payloadSize.Delete(prometheus.Labels{shardIDLabelKey: shardID}) m.payloadSize.Delete(prometheus.Labels{shardIDLabel: shardID})
m.objectCounter.DeletePartialMatch(prometheus.Labels{shardIDLabelKey: shardID}) m.objectCounter.DeletePartialMatch(prometheus.Labels{shardIDLabel: shardID})
m.mode.Delete(shardID) m.mode.Delete(shardID)
} }
func (m *engineMetrics) AddToObjectCounter(shardID, objectType string, delta int) { func (m *engineMetrics) AddToObjectCounter(shardID, objectType string, delta int) {
m.objectCounter.With( m.objectCounter.With(
prometheus.Labels{ prometheus.Labels{
shardIDLabelKey: shardID, shardIDLabel: shardID,
counterTypeLabelKey: objectType, typeLabel: objectType,
}, },
).Add(float64(delta)) ).Add(float64(delta))
} }
@ -108,8 +103,8 @@ func (m *engineMetrics) AddToObjectCounter(shardID, objectType string, delta int
func (m *engineMetrics) SetObjectCounter(shardID, objectType string, v uint64) { func (m *engineMetrics) SetObjectCounter(shardID, objectType string, v uint64) {
m.objectCounter.With( m.objectCounter.With(
prometheus.Labels{ prometheus.Labels{
shardIDLabelKey: shardID, shardIDLabel: shardID,
counterTypeLabelKey: objectType, typeLabel: objectType,
}, },
).Set(float64(v)) ).Set(float64(v))
} }

View file

@ -8,16 +8,6 @@ import (
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
) )
const (
gcSubsystem = "garbage_collector"
gcShardID = "shard_id"
gcSuccess = "success"
gcStatus = "status"
gcDeleted = "deleted"
gcFailed = "failed_to_delete"
gcObjectType = "object_type"
)
type GCMetrics interface { type GCMetrics interface {
AddRunDuration(shardID string, d time.Duration, success bool) AddRunDuration(shardID string, d time.Duration, success bool)
AddDeletedCount(shardID string, deleted, failed uint64) AddDeletedCount(shardID string, deleted, failed uint64)
@ -39,60 +29,60 @@ func newGCMetrics() *gcMetrics {
Subsystem: gcSubsystem, Subsystem: gcSubsystem,
Name: "delete_duration_seconds", Name: "delete_duration_seconds",
Help: "The total time of GC runs to delete objects from disk", Help: "The total time of GC runs to delete objects from disk",
}, []string{gcShardID, gcSuccess}), }, []string{shardIDLabel, successLabel}),
deletedCounter: metrics.NewCounterVec(prometheus.CounterOpts{ deletedCounter: metrics.NewCounterVec(prometheus.CounterOpts{
Namespace: namespace, Namespace: namespace,
Subsystem: gcSubsystem, Subsystem: gcSubsystem,
Name: "deleted_objects_total", Name: "deleted_objects_total",
Help: "Total count of objects GC deleted or failed to delete from disk", Help: "Total count of objects GC deleted or failed to delete from disk",
}, []string{gcShardID, gcStatus}), }, []string{shardIDLabel, statusLabel}),
expCollectDuration: metrics.NewCounterVec(prometheus.CounterOpts{ expCollectDuration: metrics.NewCounterVec(prometheus.CounterOpts{
Namespace: namespace, Namespace: namespace,
Subsystem: gcSubsystem, Subsystem: gcSubsystem,
Name: "marking_duration_seconds", Name: "marking_duration_seconds",
Help: "The total time of GC runs to mark expired objects as removed", Help: "The total time of GC runs to mark expired objects as removed",
}, []string{gcShardID, gcSuccess, gcObjectType}), }, []string{shardIDLabel, successLabel, objectTypeLabel}),
inhumedCounter: metrics.NewCounterVec(prometheus.CounterOpts{ inhumedCounter: metrics.NewCounterVec(prometheus.CounterOpts{
Namespace: namespace, Namespace: namespace,
Subsystem: gcSubsystem, Subsystem: gcSubsystem,
Name: "marked_for_removal_objects_total", Name: "marked_for_removal_objects_total",
Help: "Total count of expired objects GC marked to remove", Help: "Total count of expired objects GC marked to remove",
}, []string{gcShardID, gcObjectType}), }, []string{shardIDLabel, objectTypeLabel}),
} }
} }
func (m *gcMetrics) AddRunDuration(shardID string, d time.Duration, success bool) { func (m *gcMetrics) AddRunDuration(shardID string, d time.Duration, success bool) {
m.runDuration.With(prometheus.Labels{ m.runDuration.With(prometheus.Labels{
gcShardID: shardID, shardIDLabel: shardID,
gcSuccess: strconv.FormatBool(success), successLabel: strconv.FormatBool(success),
}).Add(d.Seconds()) }).Add(d.Seconds())
} }
func (m *gcMetrics) AddDeletedCount(shardID string, deleted, failed uint64) { func (m *gcMetrics) AddDeletedCount(shardID string, deleted, failed uint64) {
m.deletedCounter.With( m.deletedCounter.With(
prometheus.Labels{ prometheus.Labels{
gcShardID: shardID, shardIDLabel: shardID,
gcStatus: gcDeleted, statusLabel: deletedStatus,
}).Add(float64(deleted)) }).Add(float64(deleted))
m.deletedCounter.With( m.deletedCounter.With(
prometheus.Labels{ prometheus.Labels{
gcShardID: shardID, shardIDLabel: shardID,
gcStatus: gcFailed, statusLabel: failedToDeleteStatus,
}).Add(float64(failed)) }).Add(float64(failed))
} }
func (m *gcMetrics) AddExpiredObjectCollectionDuration(shardID string, d time.Duration, success bool, objectType string) { func (m *gcMetrics) AddExpiredObjectCollectionDuration(shardID string, d time.Duration, success bool, objectType string) {
m.expCollectDuration.With(prometheus.Labels{ m.expCollectDuration.With(prometheus.Labels{
gcShardID: shardID, shardIDLabel: shardID,
gcSuccess: strconv.FormatBool(success), successLabel: strconv.FormatBool(success),
gcObjectType: objectType, objectTypeLabel: objectType,
}).Add(d.Seconds()) }).Add(d.Seconds())
} }
func (m *gcMetrics) AddInhumedObjectCount(shardID string, count uint64, objectType string) { func (m *gcMetrics) AddInhumedObjectCount(shardID string, count uint64, objectType string) {
m.inhumedCounter.With( m.inhumedCounter.With(
prometheus.Labels{ prometheus.Labels{
gcShardID: shardID, shardIDLabel: shardID,
gcObjectType: objectType, objectTypeLabel: objectType,
}).Add(float64(count)) }).Add(float64(count))
} }

View file

@ -8,13 +8,6 @@ import (
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
) )
const (
innerRingSubsystem = "ir"
innerRingLabelSuccess = "success"
innerRingLabelType = "type"
innerRingNamespace = "frostfs_ir"
)
// InnerRingServiceMetrics contains metrics collected by inner ring. // InnerRingServiceMetrics contains metrics collected by inner ring.
type InnerRingServiceMetrics struct { type InnerRingServiceMetrics struct {
epoch prometheus.Gauge epoch prometheus.Gauge
@ -43,7 +36,7 @@ func NewInnerRingMetrics() *InnerRingServiceMetrics {
Subsystem: innerRingSubsystem, Subsystem: innerRingSubsystem,
Name: "event_duration_seconds", Name: "event_duration_seconds",
Help: "Duration of processing of inner-ring events", Help: "Duration of processing of inner-ring events",
}, []string{innerRingLabelType, innerRingLabelSuccess}) }, []string{typeLabel, successLabel})
) )
return &InnerRingServiceMetrics{ return &InnerRingServiceMetrics{
@ -66,8 +59,8 @@ func (m *InnerRingServiceMetrics) SetHealth(s int32) {
func (m *InnerRingServiceMetrics) AddEvent(d time.Duration, typ string, success bool) { func (m *InnerRingServiceMetrics) AddEvent(d time.Duration, typ string, success bool) {
m.eventDuration.With(prometheus.Labels{ m.eventDuration.With(prometheus.Labels{
innerRingLabelType: typ, typeLabel: typ,
innerRingLabelSuccess: strconv.FormatBool(success), successLabel: strconv.FormatBool(success),
}).Observe(d.Seconds()) }).Observe(d.Seconds())
} }

View file

@ -17,24 +17,24 @@ func newShardIDMode(subsystem, name, help string) *shardIDModeValue {
Subsystem: subsystem, Subsystem: subsystem,
Name: name, Name: name,
Help: help, Help: help,
}, []string{wcShardID, wcMode}), }, []string{shardIDLabel, modeLabel}),
} }
} }
func (m *shardIDModeValue) SetMode(shardID string, mode string) { func (m *shardIDModeValue) SetMode(shardID string, mode string) {
m.modeValue.DeletePartialMatch(prometheus.Labels{ m.modeValue.DeletePartialMatch(prometheus.Labels{
wcShardID: shardID, shardIDLabel: shardID,
}) })
m.modeValue.With(prometheus.Labels{ m.modeValue.With(prometheus.Labels{
wcShardID: shardID, shardIDLabel: shardID,
wcMode: mode, modeLabel: mode,
}).Set(1) }).Set(1)
} }
func (m *shardIDModeValue) Delete(shardID string) { func (m *shardIDModeValue) Delete(shardID string) {
m.modeValue.DeletePartialMatch(prometheus.Labels{ m.modeValue.DeletePartialMatch(prometheus.Labels{
wcShardID: shardID, shardIDLabel: shardID,
}) })
} }

View file

@ -9,15 +9,6 @@ import (
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
) )
const (
morphSubsystem = "morph"
morphNotificationTypeLabel = "notification_type"
morphInvokeTypeLabel = "invoke_type"
morphContractLabel = "contract"
morphMethodLabel = "method"
morphSuccessLabel = "success"
)
type morphClientMetrics struct { type morphClientMetrics struct {
switchCount prometheus.Counter switchCount prometheus.Counter
lastBlock prometheus.Gauge lastBlock prometheus.Gauge
@ -44,13 +35,13 @@ func NewMorphClientMetrics() morphmetrics.Register {
Subsystem: morphSubsystem, Subsystem: morphSubsystem,
Name: "notifications_total", Name: "notifications_total",
Help: "Number of notifications received by notification type", Help: "Number of notifications received by notification type",
}, []string{morphNotificationTypeLabel}), }, []string{notificationTypeLabel}),
invokeDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{ invokeDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{
Namespace: namespace, Namespace: namespace,
Subsystem: morphSubsystem, Subsystem: morphSubsystem,
Name: "invoke_duration_seconds", Name: "invoke_duration_seconds",
Help: "Cummulative duration of contract invocations", Help: "Cummulative duration of contract invocations",
}, []string{morphInvokeTypeLabel, morphContractLabel, morphMethodLabel, morphSuccessLabel}), }, []string{invokeTypeLabel, contractLabel, methodLabel, successLabel}),
} }
} }
@ -65,7 +56,7 @@ func (m *morphClientMetrics) SetLastBlock(index uint32) {
func (m *morphClientMetrics) IncNotificationCount(typ string) { func (m *morphClientMetrics) IncNotificationCount(typ string) {
m.notificationCount.With( m.notificationCount.With(
prometheus.Labels{ prometheus.Labels{
morphNotificationTypeLabel: typ, notificationTypeLabel: typ,
}, },
).Inc() ).Inc()
} }
@ -73,10 +64,10 @@ func (m *morphClientMetrics) IncNotificationCount(typ string) {
func (m *morphClientMetrics) ObserveInvoke(typ string, contract string, method string, success bool, d time.Duration) { func (m *morphClientMetrics) ObserveInvoke(typ string, contract string, method string, success bool, d time.Duration) {
m.invokeDuration.With( m.invokeDuration.With(
prometheus.Labels{ prometheus.Labels{
morphInvokeTypeLabel: typ, invokeTypeLabel: typ,
morphContractLabel: contract, contractLabel: contract,
morphMethodLabel: method, methodLabel: method,
morphSuccessLabel: strconv.FormatBool(success), successLabel: strconv.FormatBool(success),
}, },
).Observe(d.Seconds()) ).Observe(d.Seconds())
} }

View file

@ -8,12 +8,6 @@ import (
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
) )
const (
mcSubsystem = "morphcache"
mcSuccess = "success"
mcMethod = "method"
)
type MorphCacheMetrics interface { type MorphCacheMetrics interface {
AddMethodDuration(method string, success bool, d time.Duration) AddMethodDuration(method string, success bool, d time.Duration)
} }
@ -32,18 +26,18 @@ func newMorphCacheMetrics(ns string) *morphCacheMetrics {
return &morphCacheMetrics{ return &morphCacheMetrics{
methodDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{ methodDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{
Namespace: ns, Namespace: ns,
Subsystem: mcSubsystem, Subsystem: morphCacheSubsystem,
Name: "request_duration_seconds", Name: "request_duration_seconds",
Help: "Morph cache request process duration", Help: "Morph cache request process duration",
}, []string{mcSuccess, mcMethod}), }, []string{successLabel, methodLabel}),
} }
} }
func (m *morphCacheMetrics) AddMethodDuration(method string, success bool, d time.Duration) { func (m *morphCacheMetrics) AddMethodDuration(method string, success bool, d time.Duration) {
m.methodDuration.With( m.methodDuration.With(
prometheus.Labels{ prometheus.Labels{
mcSuccess: strconv.FormatBool(success), successLabel: strconv.FormatBool(success),
mcMethod: method, methodLabel: method,
}, },
).Observe(d.Seconds()) ).Observe(d.Seconds())
} }

View file

@ -5,8 +5,6 @@ import (
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
) )
const namespace = "frostfs_node"
type NodeMetrics struct { type NodeMetrics struct {
engine *engineMetrics engine *engineMetrics
state *stateMetrics state *stateMetrics

View file

@ -8,8 +8,6 @@ import (
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
) )
const objectSubsystem = "object"
type ObjectServiceMetrics interface { type ObjectServiceMetrics interface {
AddRequestDuration(method string, d time.Duration, success bool) AddRequestDuration(method string, d time.Duration, success bool)
AddPayloadSize(method string, size int) AddPayloadSize(method string, size int)
@ -20,14 +18,6 @@ type objectServiceMetrics struct {
payloadCounter *prometheus.CounterVec payloadCounter *prometheus.CounterVec
} }
const (
shardIDLabelKey = "shard"
counterTypeLabelKey = "type"
containerIDLabelKey = "cid"
methodLabelKey = "method"
successLabelKey = "success"
)
func newObjectServiceMetrics() *objectServiceMetrics { func newObjectServiceMetrics() *objectServiceMetrics {
return &objectServiceMetrics{ return &objectServiceMetrics{
methodDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{ methodDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{
@ -35,25 +25,25 @@ func newObjectServiceMetrics() *objectServiceMetrics {
Subsystem: objectSubsystem, Subsystem: objectSubsystem,
Name: "request_duration_seconds", Name: "request_duration_seconds",
Help: "Object Service request process duration", Help: "Object Service request process duration",
}, []string{methodLabelKey, successLabelKey}), }, []string{methodLabel, successLabel}),
payloadCounter: metrics.NewCounterVec(prometheus.CounterOpts{ payloadCounter: metrics.NewCounterVec(prometheus.CounterOpts{
Namespace: namespace, Namespace: namespace,
Subsystem: objectSubsystem, Subsystem: objectSubsystem,
Name: "request_payload_bytes", Name: "request_payload_bytes",
Help: "Object Service request payload", Help: "Object Service request payload",
}, []string{methodLabelKey}), }, []string{methodLabel}),
} }
} }
func (m *objectServiceMetrics) AddRequestDuration(method string, d time.Duration, success bool) { func (m *objectServiceMetrics) AddRequestDuration(method string, d time.Duration, success bool) {
m.methodDuration.With(prometheus.Labels{ m.methodDuration.With(prometheus.Labels{
methodLabelKey: method, methodLabel: method,
successLabelKey: strconv.FormatBool(success), successLabel: strconv.FormatBool(success),
}).Observe(d.Seconds()) }).Observe(d.Seconds())
} }
func (m *objectServiceMetrics) AddPayloadSize(method string, size int) { func (m *objectServiceMetrics) AddPayloadSize(method string, size int) {
m.payloadCounter.With(prometheus.Labels{ m.payloadCounter.With(prometheus.Labels{
methodLabelKey: method, methodLabel: method,
}).Add(float64(size)) }).Add(float64(size))
} }

View file

@ -5,8 +5,6 @@ import (
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
) )
const replicatorSubsystem = "replicator"
//TODO //TODO
type ReplicatorMetrics interface { type ReplicatorMetrics interface {

View file

@ -5,8 +5,6 @@ import (
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
) )
const stateSubsystem = "state"
type StateMetrics interface { type StateMetrics interface {
SetHealth(s int32) SetHealth(s int32)
} }

View file

@ -8,8 +8,6 @@ import (
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
) )
const treeServiceLabelSuccess = "success"
type TreeMetricsRegister interface { type TreeMetricsRegister interface {
AddReplicateTaskDuration(time.Duration, bool) AddReplicateTaskDuration(time.Duration, bool)
AddReplicateWaitDuration(time.Duration, bool) AddReplicateWaitDuration(time.Duration, bool)
@ -25,43 +23,42 @@ type treeServiceMetrics struct {
var _ TreeMetricsRegister = (*treeServiceMetrics)(nil) var _ TreeMetricsRegister = (*treeServiceMetrics)(nil)
func newTreeServiceMetrics() *treeServiceMetrics { func newTreeServiceMetrics() *treeServiceMetrics {
const treeServiceSubsystem = "treeservice"
return &treeServiceMetrics{ return &treeServiceMetrics{
replicateTaskDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{ replicateTaskDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{
Namespace: namespace, Namespace: namespace,
Subsystem: treeServiceSubsystem, Subsystem: treeServiceSubsystem,
Name: "replicate_task_duration_seconds", Name: "replicate_task_duration_seconds",
Help: "Duration of individual replication tasks executed as part of replication loops", Help: "Duration of individual replication tasks executed as part of replication loops",
}, []string{treeServiceLabelSuccess}), }, []string{successLabel}),
replicateWaitDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{ replicateWaitDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{
Namespace: namespace, Namespace: namespace,
Subsystem: treeServiceSubsystem, Subsystem: treeServiceSubsystem,
Name: "replicate_wait_duration_seconds", Name: "replicate_wait_duration_seconds",
Help: "Duration of overall waiting time for replication loops", Help: "Duration of overall waiting time for replication loops",
}, []string{treeServiceLabelSuccess}), }, []string{successLabel}),
syncOpDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{ syncOpDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{
Namespace: namespace, Namespace: namespace,
Subsystem: treeServiceSubsystem, Subsystem: treeServiceSubsystem,
Name: "sync_duration_seconds", Name: "sync_duration_seconds",
Help: "Duration of synchronization operations", Help: "Duration of synchronization operations",
}, []string{treeServiceLabelSuccess}), }, []string{successLabel}),
} }
} }
func (m *treeServiceMetrics) AddReplicateTaskDuration(d time.Duration, success bool) { func (m *treeServiceMetrics) AddReplicateTaskDuration(d time.Duration, success bool) {
m.replicateTaskDuration.With(prometheus.Labels{ m.replicateTaskDuration.With(prometheus.Labels{
treeServiceLabelSuccess: strconv.FormatBool(success), successLabel: strconv.FormatBool(success),
}).Observe(d.Seconds()) }).Observe(d.Seconds())
} }
func (m *treeServiceMetrics) AddReplicateWaitDuration(d time.Duration, success bool) { func (m *treeServiceMetrics) AddReplicateWaitDuration(d time.Duration, success bool) {
m.replicateWaitDuration.With(prometheus.Labels{ m.replicateWaitDuration.With(prometheus.Labels{
treeServiceLabelSuccess: strconv.FormatBool(success), successLabel: strconv.FormatBool(success),
}).Observe(d.Seconds()) }).Observe(d.Seconds())
} }
func (m *treeServiceMetrics) AddSyncDuration(d time.Duration, success bool) { func (m *treeServiceMetrics) AddSyncDuration(d time.Duration, success bool) {
m.syncOpDuration.With(prometheus.Labels{ m.syncOpDuration.With(prometheus.Labels{
treeServiceLabelSuccess: strconv.FormatBool(success), successLabel: strconv.FormatBool(success),
}).Observe(d.Seconds()) }).Observe(d.Seconds())
} }

View file

@ -8,16 +8,6 @@ import (
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
) )
const (
wcSubsystem = "writecache"
wcShardID = "shard_id"
wcSuccess = "success"
wcStorage = "storage"
wcMode = "mode"
wcMethod = "method"
wcOperation = "operation"
)
type WriteCacheMetrics interface { type WriteCacheMetrics interface {
AddMethodDuration(shardID string, method string, success bool, d time.Duration, storageType string) AddMethodDuration(shardID string, method string, success bool, d time.Duration, storageType string)
@ -48,58 +38,58 @@ func newWriteCacheMetrics() *writeCacheMetrics {
return &writeCacheMetrics{ return &writeCacheMetrics{
methodDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{ methodDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{
Namespace: namespace, Namespace: namespace,
Subsystem: wcSubsystem, Subsystem: writeCacheSubsystem,
Name: "request_duration_seconds", Name: "request_duration_seconds",
Help: "Writecache request process duration", Help: "Writecache request process duration",
}, []string{wcShardID, wcSuccess, wcStorage, wcMethod}), }, []string{shardIDLabel, successLabel, storageLabel, methodLabel}),
operationCounter: metrics.NewCounterVec(prometheus.CounterOpts{ operationCounter: metrics.NewCounterVec(prometheus.CounterOpts{
Namespace: namespace, Namespace: namespace,
Subsystem: wcSubsystem, Subsystem: writeCacheSubsystem,
Name: "operations_total", Name: "operations_total",
Help: "The number of writecache operations processed", Help: "The number of writecache operations processed",
}, []string{wcShardID, wcStorage, wcSuccess, wcOperation}), }, []string{shardIDLabel, storageLabel, successLabel, operationLabel}),
actualCount: newWCGaugeVec("actual_objects_total", "Actual objects count in writecache", []string{wcShardID, wcStorage}), actualCount: newWCGaugeVec("actual_objects_total", "Actual objects count in writecache", []string{shardIDLabel, storageLabel}),
estimatedSize: newWCGaugeVec("estimated_size_bytes", "Estimated writecache size", []string{wcShardID, wcStorage}), estimatedSize: newWCGaugeVec("estimated_size_bytes", "Estimated writecache size", []string{shardIDLabel, storageLabel}),
mode: newShardIDMode(wcSubsystem, "mode_info", "Writecache mode value"), mode: newShardIDMode(writeCacheSubsystem, "mode_info", "Writecache mode value"),
} }
} }
func (m *writeCacheMetrics) AddMethodDuration(shardID string, method string, success bool, d time.Duration, storageType string) { func (m *writeCacheMetrics) AddMethodDuration(shardID string, method string, success bool, d time.Duration, storageType string) {
m.methodDuration.With( m.methodDuration.With(
prometheus.Labels{ prometheus.Labels{
wcShardID: shardID, shardIDLabel: shardID,
wcSuccess: fmt.Sprintf("%v", success), successLabel: fmt.Sprintf("%v", success),
wcStorage: storageType, storageLabel: storageType,
wcMethod: method, methodLabel: method,
}, },
).Observe(d.Seconds()) ).Observe(d.Seconds())
} }
func (m *writeCacheMetrics) IncActualCount(shardID string, storageType string) { func (m *writeCacheMetrics) IncActualCount(shardID string, storageType string) {
m.actualCount.With(prometheus.Labels{ m.actualCount.With(prometheus.Labels{
wcShardID: shardID, shardIDLabel: shardID,
wcStorage: storageType, storageLabel: storageType,
}).Inc() }).Inc()
} }
func (m *writeCacheMetrics) DecActualCount(shardID string, storageType string) { func (m *writeCacheMetrics) DecActualCount(shardID string, storageType string) {
m.actualCount.With(prometheus.Labels{ m.actualCount.With(prometheus.Labels{
wcShardID: shardID, shardIDLabel: shardID,
wcStorage: storageType, storageLabel: storageType,
}).Dec() }).Dec()
} }
func (m *writeCacheMetrics) SetActualCount(shardID string, count uint64, storageType string) { func (m *writeCacheMetrics) SetActualCount(shardID string, count uint64, storageType string) {
m.actualCount.With(prometheus.Labels{ m.actualCount.With(prometheus.Labels{
wcShardID: shardID, shardIDLabel: shardID,
wcStorage: storageType, storageLabel: storageType,
}).Set(float64(count)) }).Set(float64(count))
} }
func (m *writeCacheMetrics) SetEstimateSize(shardID string, size uint64, storageType string) { func (m *writeCacheMetrics) SetEstimateSize(shardID string, size uint64, storageType string) {
m.estimatedSize.With(prometheus.Labels{ m.estimatedSize.With(prometheus.Labels{
wcShardID: shardID, shardIDLabel: shardID,
wcStorage: storageType, storageLabel: storageType,
}).Set(float64(size)) }).Set(float64(size))
} }
@ -109,25 +99,25 @@ func (m *writeCacheMetrics) SetMode(shardID string, mode string) {
func (m *writeCacheMetrics) IncOperationCounter(shardID string, operation string, success NullBool, storageType string) { func (m *writeCacheMetrics) IncOperationCounter(shardID string, operation string, success NullBool, storageType string) {
m.operationCounter.With(prometheus.Labels{ m.operationCounter.With(prometheus.Labels{
wcShardID: shardID, shardIDLabel: shardID,
wcStorage: storageType, storageLabel: storageType,
wcOperation: operation, operationLabel: operation,
wcSuccess: success.String(), successLabel: success.String(),
}).Inc() }).Inc()
} }
func (m *writeCacheMetrics) Close(shardID string) { func (m *writeCacheMetrics) Close(shardID string) {
m.mode.Delete(shardID) m.mode.Delete(shardID)
m.methodDuration.DeletePartialMatch(prometheus.Labels{wcShardID: shardID}) m.methodDuration.DeletePartialMatch(prometheus.Labels{shardIDLabel: shardID})
m.operationCounter.DeletePartialMatch(prometheus.Labels{wcShardID: shardID}) m.operationCounter.DeletePartialMatch(prometheus.Labels{shardIDLabel: shardID})
m.actualCount.DeletePartialMatch(prometheus.Labels{wcShardID: shardID}) m.actualCount.DeletePartialMatch(prometheus.Labels{shardIDLabel: shardID})
m.estimatedSize.DeletePartialMatch(prometheus.Labels{wcShardID: shardID}) m.estimatedSize.DeletePartialMatch(prometheus.Labels{shardIDLabel: shardID})
} }
func newWCGaugeVec(name, help string, labels []string) *prometheus.GaugeVec { func newWCGaugeVec(name, help string, labels []string) *prometheus.GaugeVec {
return metrics.NewGaugeVec(prometheus.GaugeOpts{ return metrics.NewGaugeVec(prometheus.GaugeOpts{
Namespace: namespace, Namespace: namespace,
Subsystem: wcSubsystem, Subsystem: writeCacheSubsystem,
Name: name, Name: name,
Help: help, Help: help,
}, labels) }, labels)