2023-05-24 07:01:50 +00:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
2023-06-13 11:19:33 +00:00
|
|
|
"strconv"
|
2023-05-24 07:01:50 +00:00
|
|
|
"time"
|
|
|
|
|
2023-05-31 09:25:32 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
|
2023-05-24 07:01:50 +00:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
)
|
|
|
|
|
2023-05-26 09:15:50 +00:00
|
|
|
type TreeMetricsRegister interface {
|
|
|
|
AddReplicateTaskDuration(time.Duration, bool)
|
|
|
|
AddReplicateWaitDuration(time.Duration, bool)
|
|
|
|
AddSyncDuration(time.Duration, bool)
|
|
|
|
}
|
|
|
|
|
2023-05-24 07:01:50 +00:00
|
|
|
type treeServiceMetrics struct {
|
2023-05-31 09:25:32 +00:00
|
|
|
replicateTaskDuration *prometheus.HistogramVec
|
|
|
|
replicateWaitDuration *prometheus.HistogramVec
|
|
|
|
syncOpDuration *prometheus.HistogramVec
|
2023-05-24 07:01:50 +00:00
|
|
|
}
|
|
|
|
|
2023-05-26 09:15:50 +00:00
|
|
|
var _ TreeMetricsRegister = (*treeServiceMetrics)(nil)
|
|
|
|
|
2023-05-24 07:01:50 +00:00
|
|
|
func newTreeServiceMetrics() *treeServiceMetrics {
|
|
|
|
return &treeServiceMetrics{
|
2023-05-31 09:25:32 +00:00
|
|
|
replicateTaskDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{
|
2023-05-24 07:01:50 +00:00
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: treeServiceSubsystem,
|
|
|
|
Name: "replicate_task_duration_seconds",
|
|
|
|
Help: "Duration of individual replication tasks executed as part of replication loops",
|
2023-06-16 07:13:22 +00:00
|
|
|
}, []string{successLabel}),
|
2023-05-31 09:25:32 +00:00
|
|
|
replicateWaitDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{
|
2023-05-24 07:01:50 +00:00
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: treeServiceSubsystem,
|
|
|
|
Name: "replicate_wait_duration_seconds",
|
|
|
|
Help: "Duration of overall waiting time for replication loops",
|
2023-06-16 07:13:22 +00:00
|
|
|
}, []string{successLabel}),
|
2023-05-31 09:25:32 +00:00
|
|
|
syncOpDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{
|
2023-05-24 07:01:50 +00:00
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: treeServiceSubsystem,
|
|
|
|
Name: "sync_duration_seconds",
|
|
|
|
Help: "Duration of synchronization operations",
|
2023-06-16 07:13:22 +00:00
|
|
|
}, []string{successLabel}),
|
2023-05-24 07:01:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *treeServiceMetrics) AddReplicateTaskDuration(d time.Duration, success bool) {
|
2023-05-31 09:25:32 +00:00
|
|
|
m.replicateTaskDuration.With(prometheus.Labels{
|
2023-06-16 07:13:22 +00:00
|
|
|
successLabel: strconv.FormatBool(success),
|
2023-05-24 07:01:50 +00:00
|
|
|
}).Observe(d.Seconds())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *treeServiceMetrics) AddReplicateWaitDuration(d time.Duration, success bool) {
|
2023-05-31 09:25:32 +00:00
|
|
|
m.replicateWaitDuration.With(prometheus.Labels{
|
2023-06-16 07:13:22 +00:00
|
|
|
successLabel: strconv.FormatBool(success),
|
2023-05-24 07:01:50 +00:00
|
|
|
}).Observe(d.Seconds())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *treeServiceMetrics) AddSyncDuration(d time.Duration, success bool) {
|
2023-05-31 09:25:32 +00:00
|
|
|
m.syncOpDuration.With(prometheus.Labels{
|
2023-06-16 07:13:22 +00:00
|
|
|
successLabel: strconv.FormatBool(success),
|
2023-05-24 07:01:50 +00:00
|
|
|
}).Observe(d.Seconds())
|
|
|
|
}
|