/
updates_latency.go
57 lines (49 loc) · 1.37 KB
/
updates_latency.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package metrics
import (
"sync"
"time"
"github.com/SAP/stewardci-core/pkg/metrics"
"github.com/prometheus/client_golang/prometheus"
)
var (
// UpdatesLatency is a metric that observes the duration of updates
// partitioned by a "type".
UpdatesLatency UpdatesLatencyMetric = &updatesLatency{}
)
// UpdatesLatencyMetric is the interface of UpdatesLatency
type UpdatesLatencyMetric interface {
Observe(typ string, duration time.Duration)
}
func init() {
UpdatesLatency.(*updatesLatency).init()
}
type updatesLatency struct {
initOnlyOnce sync.Once
metric *prometheus.HistogramVec
}
func (m *updatesLatency) init() {
m.initOnlyOnce.Do(func() {
m.metric = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
// TODO use metric name prefixes consistently
// TODO use better name
//Subsystem: subsystem,
//Name: "updates_latency_seconds",
Name: "steward_pipelinerun_update_seconds",
Help: "Deprecated! Use REST client metrics and retries metrics instead." +
"\n\nA histogram vector of the duration of update operations.",
Buckets: prometheus.ExponentialBuckets(0.001, 1.3, 30),
},
[]string{
"type",
},
)
metrics.Registerer().MustRegister(m.metric)
})
}
func (m *updatesLatency) Observe(typ string, duration time.Duration) {
labels := prometheus.Labels{
"type": typ,
}
m.metric.With(labels).Observe(duration.Seconds())
}