fix(blooms): improves mempool metrics (#13283)

pull/13285/head
Owen Diehl 11 months ago committed by GitHub
parent c1fada9af0
commit d36e1d580a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 17
      pkg/util/mempool/metrics.go
  2. 6
      pkg/util/mempool/pool.go

@ -8,13 +8,19 @@ import (
)
type metrics struct {
availableBuffersPerSlab *prometheus.CounterVec
availableBuffersPerSlab *prometheus.GaugeVec
errorsCounter *prometheus.CounterVec
accesses *prometheus.CounterVec
}
const (
opTypeGet = "get"
opTypePut = "put"
)
func newMetrics(r prometheus.Registerer, name string) *metrics {
return &metrics{
availableBuffersPerSlab: promauto.With(r).NewCounterVec(prometheus.CounterOpts{
availableBuffersPerSlab: promauto.With(r).NewGaugeVec(prometheus.GaugeOpts{
Namespace: constants.Loki,
Subsystem: "mempool",
Name: "available_buffers_per_slab",
@ -28,5 +34,12 @@ func newMetrics(r prometheus.Registerer, name string) *metrics {
Help: "The total amount of errors returned from the pool.",
ConstLabels: prometheus.Labels{"pool": name},
}, []string{"slab", "reason"}),
accesses: promauto.With(r).NewCounterVec(prometheus.CounterOpts{
Namespace: constants.Loki,
Subsystem: "mempool",
Name: "accesses_total",
Help: "The total amount of accesses to the pool.",
ConstLabels: prometheus.Labels{"pool": name},
}, []string{"slab", "op"}),
}
}

@ -27,7 +27,7 @@ type slab struct {
func newSlab(bufferSize, bufferCount int, m *metrics) *slab {
name := humanize.Bytes(uint64(bufferSize))
m.availableBuffersPerSlab.WithLabelValues(name).Add(0) // initialize metric with value 0
m.availableBuffersPerSlab.WithLabelValues(name).Set(0) // initialize metric with value 0
return &slab{
size: bufferSize,
@ -44,10 +44,11 @@ func (s *slab) init() {
ptr := unsafe.Pointer(unsafe.SliceData(buf))
s.buffer <- ptr
}
s.metrics.availableBuffersPerSlab.WithLabelValues(s.name).Add(float64(s.count))
s.metrics.availableBuffersPerSlab.WithLabelValues(s.name).Set(float64(s.count))
}
func (s *slab) get(size int) ([]byte, error) {
s.metrics.accesses.WithLabelValues(s.name, opTypeGet).Inc()
s.mtx.Lock()
if s.buffer == nil {
s.init()
@ -77,6 +78,7 @@ func (s *slab) get(size int) ([]byte, error) {
}
func (s *slab) put(buf []byte) {
s.metrics.accesses.WithLabelValues(s.name, opTypePut).Inc()
if s.buffer == nil {
panic("slab is not initialized")
}

Loading…
Cancel
Save