Skip to content

Commit

Permalink
fix: move partition_id into label to make PromQL easier (#14714)
Browse files Browse the repository at this point in the history
  • Loading branch information
grobinson-grafana authored Nov 1, 2024
1 parent 3280376 commit e6cf423
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions pkg/kafka/partition/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package partition

import (
"math"
"strconv"
"time"

"github.com/prometheus/client_golang/prometheus"
Expand All @@ -12,7 +13,7 @@ import (
)

type readerMetrics struct {
partition prometheus.Gauge
partition *prometheus.GaugeVec
phase *prometheus.GaugeVec
receiveDelay *prometheus.HistogramVec
recordsPerFetch prometheus.Histogram
Expand All @@ -26,10 +27,10 @@ type readerMetrics struct {
// newReaderMetrics initializes and returns a new set of metrics for the PartitionReader.
func newReaderMetrics(r prometheus.Registerer) readerMetrics {
return readerMetrics{
partition: promauto.With(r).NewGauge(prometheus.GaugeOpts{
Name: "loki_ingest_storage_reader_partition_id",
partition: promauto.With(r).NewGaugeVec(prometheus.GaugeOpts{
Name: "loki_ingest_storage_reader_partition",
Help: "The partition ID assigned to this reader.",
}),
}, []string{"id"}),
phase: promauto.With(r).NewGaugeVec(prometheus.GaugeOpts{
Name: "loki_ingest_storage_reader_phase",
Help: "The current phase of the consumer.",
Expand Down Expand Up @@ -66,13 +67,13 @@ func newReaderMetrics(r prometheus.Registerer) readerMetrics {
}

func (m *readerMetrics) reportStarting(partitionID int32) {
m.partition.Set(float64(partitionID))
m.partition.WithLabelValues(strconv.Itoa(int(partitionID))).Set(1)
m.phase.WithLabelValues(phaseStarting).Set(1)
m.phase.WithLabelValues(phaseRunning).Set(0)
}

func (m *readerMetrics) reportRunning(partitionID int32) {
m.partition.Set(float64(partitionID))
m.partition.WithLabelValues(strconv.Itoa(int(partitionID))).Set(1)
m.phase.WithLabelValues(phaseStarting).Set(0)
m.phase.WithLabelValues(phaseRunning).Set(1)
}

0 comments on commit e6cf423

Please sign in to comment.