[#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

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