-
Notifications
You must be signed in to change notification settings - Fork 88
/
metrics.go
38 lines (34 loc) · 1.04 KB
/
metrics.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
package internal
import (
"github.com/grafana/alloy/internal/util"
"github.com/prometheus/client_golang/prometheus"
)
type MarkerMetrics struct {
lastMarkedSegment *prometheus.GaugeVec
}
func NewMarkerMetrics(reg prometheus.Registerer) *MarkerMetrics {
m := &MarkerMetrics{
lastMarkedSegment: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "loki_write",
Subsystem: "wal_marker",
Name: "last_marked_segment",
Help: "Last marked WAL segment.",
},
[]string{"id"},
),
}
if reg != nil {
m.lastMarkedSegment = util.MustRegisterOrGet(reg, m.lastMarkedSegment).(*prometheus.GaugeVec)
}
return m
}
// WithCurriedId returns a curried version of MarkerMetrics, with the id label pre-filled. This is a helper that avoids
// having to move the id around where it's unnecessary, and won't change inside the consumer of the metrics.
func (m *MarkerMetrics) WithCurriedId(id string) *MarkerMetrics {
return &MarkerMetrics{
lastMarkedSegment: m.lastMarkedSegment.MustCurryWith(map[string]string{
"id": id,
}),
}
}