2023-05-29 14:32:13 +00:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
2023-06-13 11:19:33 +00:00
|
|
|
"strconv"
|
2023-05-29 14:32:13 +00:00
|
|
|
"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"
|
|
|
|
)
|
|
|
|
|
|
|
|
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",
|
2023-06-16 07:13:22 +00:00
|
|
|
}, []string{shardIDLabel, successLabel}),
|
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,
|
2023-06-14 07:16:19 +00:00
|
|
|
Name: "deleted_objects_total",
|
2023-05-29 14:32:13 +00:00
|
|
|
Help: "Total count of objects GC deleted or failed to delete from disk",
|
2023-06-16 07:13:22 +00:00
|
|
|
}, []string{shardIDLabel, statusLabel}),
|
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",
|
2023-06-16 07:13:22 +00:00
|
|
|
}, []string{shardIDLabel, successLabel, objectTypeLabel}),
|
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,
|
2023-06-14 07:16:19 +00:00
|
|
|
Name: "marked_for_removal_objects_total",
|
2023-05-29 14:32:13 +00:00
|
|
|
Help: "Total count of expired objects GC marked to remove",
|
2023-06-16 07:13:22 +00:00
|
|
|
}, []string{shardIDLabel, objectTypeLabel}),
|
2023-05-29 14:32:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-06-16 07:13:22 +00:00
|
|
|
shardIDLabel: shardID,
|
|
|
|
successLabel: strconv.FormatBool(success),
|
2023-05-29 14:32:13 +00:00
|
|
|
}).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{
|
2023-06-16 07:13:22 +00:00
|
|
|
shardIDLabel: shardID,
|
|
|
|
statusLabel: deletedStatus,
|
2023-05-29 14:32:13 +00:00
|
|
|
}).Add(float64(deleted))
|
2023-05-31 09:25:32 +00:00
|
|
|
m.deletedCounter.With(
|
2023-05-29 14:32:13 +00:00
|
|
|
prometheus.Labels{
|
2023-06-16 07:13:22 +00:00
|
|
|
shardIDLabel: shardID,
|
|
|
|
statusLabel: failedToDeleteStatus,
|
2023-05-29 14:32:13 +00:00
|
|
|
}).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-06-16 07:13:22 +00:00
|
|
|
shardIDLabel: shardID,
|
|
|
|
successLabel: strconv.FormatBool(success),
|
|
|
|
objectTypeLabel: objectType,
|
2023-05-29 14:32:13 +00:00
|
|
|
}).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{
|
2023-06-16 07:13:22 +00:00
|
|
|
shardIDLabel: shardID,
|
|
|
|
objectTypeLabel: objectType,
|
2023-05-29 14:32:13 +00:00
|
|
|
}).Add(float64(count))
|
|
|
|
}
|