Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: move partition_id into label to make PromQL easier #14714

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Loading