2023-05-29 14:32:13 +00:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2023-05-31 09:25:32 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
|
2023-05-29 14:32:13 +00:00
|
|
|
"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 {
|
|
|
|
AddRunDuration(shardID string, d time.Duration, success bool)
|
|
|
|
AddDeletedCount(shardID string, deleted, failed uint64)
|
|
|
|
AddExpiredObjectCollectionDuration(shardID string, d time.Duration, success bool, objectType string)
|
|
|
|
AddInhumedObjectCount(shardID string, count uint64, objectType string)
|
|
|
|
}
|
|
|
|
|
|
|
|
type gcMetrics struct {
|
2023-05-31 09:25:32 +00:00
|
|
|
runDuration *prometheus.CounterVec
|
|
|
|
deletedCounter *prometheus.CounterVec
|
|
|
|
expCollectDuration *prometheus.CounterVec
|
|
|
|
inhumedCounter *prometheus.CounterVec
|
2023-05-29 14:32:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newGCMetrics() *gcMetrics {
|
|
|
|
return &gcMetrics{
|
2023-05-31 09:25:32 +00:00
|
|
|
runDuration: metrics.NewCounterVec(prometheus.CounterOpts{
|
2023-05-29 14:32:13 +00:00
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: gcSubsystem,
|
|
|
|
Name: "delete_duration_seconds",
|
|
|
|
Help: "The total time of GC runs to delete objects from disk",
|
|
|
|
}, []string{gcShardID, gcSuccess}),
|
2023-05-31 09:25:32 +00:00
|
|
|
deletedCounter: metrics.NewCounterVec(prometheus.CounterOpts{
|
2023-05-29 14:32:13 +00:00
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: gcSubsystem,
|
|
|
|
Name: "deleted_objects_count",
|
|
|
|
Help: "Total count of objects GC deleted or failed to delete from disk",
|
|
|
|
}, []string{gcShardID, gcStatus}),
|
2023-05-31 09:25:32 +00:00
|
|
|
expCollectDuration: metrics.NewCounterVec(prometheus.CounterOpts{
|
2023-05-29 14:32:13 +00:00
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: gcSubsystem,
|
|
|
|
Name: "marking_duration_seconds",
|
|
|
|
Help: "The total time of GC runs to mark expired objects as removed",
|
|
|
|
}, []string{gcShardID, gcSuccess, gcObjectType}),
|
2023-05-31 09:25:32 +00:00
|
|
|
inhumedCounter: metrics.NewCounterVec(prometheus.CounterOpts{
|
2023-05-29 14:32:13 +00:00
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: gcSubsystem,
|
|
|
|
Name: "marked_for_removal_objects_count",
|
|
|
|
Help: "Total count of expired objects GC marked to remove",
|
|
|
|
}, []string{gcShardID, gcObjectType}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *gcMetrics) AddRunDuration(shardID string, d time.Duration, success bool) {
|
2023-05-31 09:25:32 +00:00
|
|
|
m.runDuration.With(prometheus.Labels{
|
2023-05-29 14:32:13 +00:00
|
|
|
gcShardID: shardID,
|
|
|
|
gcSuccess: fmt.Sprintf("%v", success),
|
|
|
|
}).Add(d.Seconds())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *gcMetrics) AddDeletedCount(shardID string, deleted, failed uint64) {
|
2023-05-31 09:25:32 +00:00
|
|
|
m.deletedCounter.With(
|
2023-05-29 14:32:13 +00:00
|
|
|
prometheus.Labels{
|
|
|
|
gcShardID: shardID,
|
|
|
|
gcStatus: gcDeleted,
|
|
|
|
}).Add(float64(deleted))
|
2023-05-31 09:25:32 +00:00
|
|
|
m.deletedCounter.With(
|
2023-05-29 14:32:13 +00:00
|
|
|
prometheus.Labels{
|
|
|
|
gcShardID: shardID,
|
|
|
|
gcStatus: gcFailed,
|
|
|
|
}).Add(float64(failed))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *gcMetrics) AddExpiredObjectCollectionDuration(shardID string, d time.Duration, success bool, objectType string) {
|
2023-05-31 09:25:32 +00:00
|
|
|
m.expCollectDuration.With(prometheus.Labels{
|
2023-05-29 14:32:13 +00:00
|
|
|
gcShardID: shardID,
|
|
|
|
gcSuccess: fmt.Sprintf("%v", success),
|
|
|
|
gcObjectType: objectType,
|
|
|
|
}).Add(d.Seconds())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *gcMetrics) AddInhumedObjectCount(shardID string, count uint64, objectType string) {
|
2023-05-31 09:25:32 +00:00
|
|
|
m.inhumedCounter.With(
|
2023-05-29 14:32:13 +00:00
|
|
|
prometheus.Labels{
|
|
|
|
gcShardID: shardID,
|
|
|
|
gcObjectType: objectType,
|
|
|
|
}).Add(float64(count))
|
|
|
|
}
|