2023-05-19 08:17:19 +00:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
2023-12-11 10:06:03 +00:00
|
|
|
"strconv"
|
2023-05-19 08:17:19 +00:00
|
|
|
"time"
|
|
|
|
|
2023-05-31 09:25:32 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
|
2023-05-19 08:17:19 +00:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
)
|
|
|
|
|
|
|
|
type WriteCacheMetrics interface {
|
2024-04-27 12:49:07 +00:00
|
|
|
AddMethodDuration(shardID, path, storageType, method string, success bool, d time.Duration)
|
|
|
|
SetActualCount(shardID, path, storageType string, count uint64)
|
|
|
|
SetEstimateSize(shardID, path, storageType string, size uint64)
|
2024-04-27 12:34:29 +00:00
|
|
|
SetMode(shardID, mode string)
|
2024-04-27 12:49:07 +00:00
|
|
|
IncOperationCounter(shardID, path, storageType, operation string, success NullBool)
|
|
|
|
Close(shardID, path string)
|
2023-05-19 08:17:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type writeCacheMetrics struct {
|
2023-06-13 12:05:45 +00:00
|
|
|
methodDuration *prometheus.HistogramVec
|
|
|
|
operationCounter *prometheus.CounterVec
|
2023-05-19 08:17:19 +00:00
|
|
|
|
2023-05-31 09:25:32 +00:00
|
|
|
actualCount *prometheus.GaugeVec
|
2023-05-19 08:17:19 +00:00
|
|
|
|
2023-05-31 09:25:32 +00:00
|
|
|
estimatedSize *prometheus.GaugeVec
|
2023-05-19 08:17:19 +00:00
|
|
|
|
2023-06-14 08:00:44 +00:00
|
|
|
mode *shardIDModeValue
|
2023-05-19 08:17:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newWriteCacheMetrics() *writeCacheMetrics {
|
|
|
|
return &writeCacheMetrics{
|
2023-06-13 12:05:45 +00:00
|
|
|
methodDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{
|
|
|
|
Namespace: namespace,
|
2023-06-16 07:13:22 +00:00
|
|
|
Subsystem: writeCacheSubsystem,
|
2023-06-13 12:05:45 +00:00
|
|
|
Name: "request_duration_seconds",
|
|
|
|
Help: "Writecache request process duration",
|
2024-05-02 17:03:33 +00:00
|
|
|
}, []string{shardIDLabel, successLabel, storageLabel, methodLabel, pathLabel}),
|
2023-06-13 12:05:45 +00:00
|
|
|
operationCounter: metrics.NewCounterVec(prometheus.CounterOpts{
|
|
|
|
Namespace: namespace,
|
2023-06-16 07:13:22 +00:00
|
|
|
Subsystem: writeCacheSubsystem,
|
2023-06-14 07:16:19 +00:00
|
|
|
Name: "operations_total",
|
2023-06-13 12:05:45 +00:00
|
|
|
Help: "The number of writecache operations processed",
|
2024-04-27 12:49:07 +00:00
|
|
|
}, []string{shardIDLabel, storageLabel, successLabel, operationLabel, pathLabel}),
|
|
|
|
actualCount: newWCGaugeVec("actual_objects_total", "Actual objects count in writecache", []string{shardIDLabel, storageLabel, pathLabel}),
|
|
|
|
estimatedSize: newWCGaugeVec("estimated_size_bytes", "Estimated writecache size", []string{shardIDLabel, storageLabel, pathLabel}),
|
2023-06-16 07:13:22 +00:00
|
|
|
mode: newShardIDMode(writeCacheSubsystem, "mode_info", "Writecache mode value"),
|
2023-05-19 08:17:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-27 12:49:07 +00:00
|
|
|
func (m *writeCacheMetrics) AddMethodDuration(shardID, path, storageType, method string, success bool, d time.Duration) {
|
2023-06-13 12:05:45 +00:00
|
|
|
m.methodDuration.With(
|
|
|
|
prometheus.Labels{
|
2023-06-16 07:13:22 +00:00
|
|
|
shardIDLabel: shardID,
|
2023-12-11 10:06:03 +00:00
|
|
|
successLabel: strconv.FormatBool(success),
|
2023-06-16 07:13:22 +00:00
|
|
|
storageLabel: storageType,
|
|
|
|
methodLabel: method,
|
2024-04-27 12:49:07 +00:00
|
|
|
pathLabel: path,
|
2023-06-13 12:05:45 +00:00
|
|
|
},
|
|
|
|
).Observe(d.Seconds())
|
2023-05-19 08:17:19 +00:00
|
|
|
}
|
|
|
|
|
2024-04-27 12:49:07 +00:00
|
|
|
func (m *writeCacheMetrics) SetActualCount(shardID, path, storageType string, count uint64) {
|
2023-05-31 09:25:32 +00:00
|
|
|
m.actualCount.With(prometheus.Labels{
|
2023-06-16 07:13:22 +00:00
|
|
|
shardIDLabel: shardID,
|
|
|
|
storageLabel: storageType,
|
2024-04-27 12:49:07 +00:00
|
|
|
pathLabel: path,
|
2023-05-19 08:17:19 +00:00
|
|
|
}).Set(float64(count))
|
|
|
|
}
|
|
|
|
|
2024-04-27 12:49:07 +00:00
|
|
|
func (m *writeCacheMetrics) SetEstimateSize(shardID, path, storageType string, size uint64) {
|
2023-05-31 09:25:32 +00:00
|
|
|
m.estimatedSize.With(prometheus.Labels{
|
2023-06-16 07:13:22 +00:00
|
|
|
shardIDLabel: shardID,
|
|
|
|
storageLabel: storageType,
|
2024-04-27 12:49:07 +00:00
|
|
|
pathLabel: path,
|
2023-05-19 08:17:19 +00:00
|
|
|
}).Set(float64(size))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *writeCacheMetrics) SetMode(shardID string, mode string) {
|
2023-06-14 08:00:44 +00:00
|
|
|
m.mode.SetMode(shardID, mode)
|
2023-05-19 08:17:19 +00:00
|
|
|
}
|
|
|
|
|
2024-04-27 12:49:07 +00:00
|
|
|
func (m *writeCacheMetrics) IncOperationCounter(shardID, path, storageType, operation string, success NullBool) {
|
2023-06-13 12:05:45 +00:00
|
|
|
m.operationCounter.With(prometheus.Labels{
|
2023-06-16 07:13:22 +00:00
|
|
|
shardIDLabel: shardID,
|
|
|
|
storageLabel: storageType,
|
|
|
|
operationLabel: operation,
|
|
|
|
successLabel: success.String(),
|
2024-04-27 12:49:07 +00:00
|
|
|
pathLabel: path,
|
2023-05-19 08:17:19 +00:00
|
|
|
}).Inc()
|
|
|
|
}
|
|
|
|
|
2024-04-27 12:49:07 +00:00
|
|
|
func (m *writeCacheMetrics) Close(shardID, path string) {
|
2023-06-14 08:00:44 +00:00
|
|
|
m.mode.Delete(shardID)
|
2024-04-27 12:49:07 +00:00
|
|
|
m.methodDuration.DeletePartialMatch(prometheus.Labels{shardIDLabel: shardID, pathLabel: path})
|
|
|
|
m.operationCounter.DeletePartialMatch(prometheus.Labels{shardIDLabel: shardID, pathLabel: path})
|
|
|
|
m.actualCount.DeletePartialMatch(prometheus.Labels{shardIDLabel: shardID, pathLabel: path})
|
|
|
|
m.estimatedSize.DeletePartialMatch(prometheus.Labels{shardIDLabel: shardID, pathLabel: path})
|
2023-06-13 12:14:28 +00:00
|
|
|
}
|
|
|
|
|
2023-05-31 09:25:32 +00:00
|
|
|
func newWCGaugeVec(name, help string, labels []string) *prometheus.GaugeVec {
|
|
|
|
return metrics.NewGaugeVec(prometheus.GaugeOpts{
|
2023-05-19 08:17:19 +00:00
|
|
|
Namespace: namespace,
|
2023-06-16 07:13:22 +00:00
|
|
|
Subsystem: writeCacheSubsystem,
|
2023-05-19 08:17:19 +00:00
|
|
|
Name: name,
|
|
|
|
Help: help,
|
|
|
|
}, labels)
|
|
|
|
}
|