Skip to content

Commit d36e1d5

Browse files
authored
fix(blooms): improves mempool metrics (#13283)
1 parent c1fada9 commit d36e1d5

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

‎pkg/util/mempool/metrics.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@ import (
88
)
99

1010
type metrics struct {
11-
availableBuffersPerSlab *prometheus.CounterVec
11+
availableBuffersPerSlab *prometheus.GaugeVec
1212
errorsCounter *prometheus.CounterVec
13+
accesses *prometheus.CounterVec
1314
}
1415

16+
const (
17+
opTypeGet = "get"
18+
opTypePut = "put"
19+
)
20+
1521
func newMetrics(r prometheus.Registerer, name string) *metrics {
1622
return &metrics{
17-
availableBuffersPerSlab: promauto.With(r).NewCounterVec(prometheus.CounterOpts{
23+
availableBuffersPerSlab: promauto.With(r).NewGaugeVec(prometheus.GaugeOpts{
1824
Namespace: constants.Loki,
1925
Subsystem: "mempool",
2026
Name: "available_buffers_per_slab",
@@ -28,5 +34,12 @@ func newMetrics(r prometheus.Registerer, name string) *metrics {
2834
Help: "The total amount of errors returned from the pool.",
2935
ConstLabels: prometheus.Labels{"pool": name},
3036
}, []string{"slab", "reason"}),
37+
accesses: promauto.With(r).NewCounterVec(prometheus.CounterOpts{
38+
Namespace: constants.Loki,
39+
Subsystem: "mempool",
40+
Name: "accesses_total",
41+
Help: "The total amount of accesses to the pool.",
42+
ConstLabels: prometheus.Labels{"pool": name},
43+
}, []string{"slab", "op"}),
3144
}
3245
}

‎pkg/util/mempool/pool.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type slab struct {
2727

2828
func newSlab(bufferSize, bufferCount int, m *metrics) *slab {
2929
name := humanize.Bytes(uint64(bufferSize))
30-
m.availableBuffersPerSlab.WithLabelValues(name).Add(0) // initialize metric with value 0
30+
m.availableBuffersPerSlab.WithLabelValues(name).Set(0) // initialize metric with value 0
3131

3232
return &slab{
3333
size: bufferSize,
@@ -44,10 +44,11 @@ func (s *slab) init() {
4444
ptr := unsafe.Pointer(unsafe.SliceData(buf))
4545
s.buffer <- ptr
4646
}
47-
s.metrics.availableBuffersPerSlab.WithLabelValues(s.name).Add(float64(s.count))
47+
s.metrics.availableBuffersPerSlab.WithLabelValues(s.name).Set(float64(s.count))
4848
}
4949

5050
func (s *slab) get(size int) ([]byte, error) {
51+
s.metrics.accesses.WithLabelValues(s.name, opTypeGet).Inc()
5152
s.mtx.Lock()
5253
if s.buffer == nil {
5354
s.init()
@@ -77,6 +78,7 @@ func (s *slab) get(size int) ([]byte, error) {
7778
}
7879

7980
func (s *slab) put(buf []byte) {
81+
s.metrics.accesses.WithLabelValues(s.name, opTypePut).Inc()
8082
if s.buffer == nil {
8183
panic("slab is not initialized")
8284
}

0 commit comments

Comments
 (0)