Skip to content

Commit

Permalink
chore: separate usage of partition owner gauge (#15079)
Browse files Browse the repository at this point in the history
  • Loading branch information
grobinson-grafana authored Nov 22, 2024
1 parent 3aad529 commit d2e1992
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions pkg/kafka/partition/reader_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ func (s *ReaderService) starting(ctx context.Context) error {
"partition", s.reader.Partition(),
"consumer_group", s.reader.ConsumerGroup(),
)
s.metrics.reportStarting(s.reader.Partition())
s.metrics.reportOwnerOfPartition(s.reader.Partition())
s.metrics.reportStarting()

// Fetch the last committed offset to determine where to start reading
lastCommittedOffset, err := s.reader.FetchLastCommittedOffset(ctx)
Expand Down Expand Up @@ -196,7 +197,7 @@ func (s *ReaderService) running(ctx context.Context) error {
"partition", s.reader.Partition(),
"consumer_group", s.reader.ConsumerGroup(),
)
s.metrics.reportRunning(s.reader.Partition())
s.metrics.reportRunning()

consumer, err := s.consumerFactory(s.committer)
if err != nil {
Expand Down Expand Up @@ -396,14 +397,16 @@ func (s *ReaderService) startFetchLoop(ctx context.Context) chan []Record {
return records
}

func (s *serviceMetrics) reportStarting(partition int32) {
s.partition.WithLabelValues(strconv.Itoa(int(partition))).Set(1)
func (s *serviceMetrics) reportOwnerOfPartition(id int32) {
s.partition.WithLabelValues(strconv.Itoa(int(id))).Set(1)
}

func (s *serviceMetrics) reportStarting() {
s.phase.WithLabelValues(phaseStarting).Set(1)
s.phase.WithLabelValues(phaseRunning).Set(0)
}

func (s *serviceMetrics) reportRunning(partition int32) {
s.partition.WithLabelValues(strconv.Itoa(int(partition))).Set(1)
func (s *serviceMetrics) reportRunning() {
s.phase.WithLabelValues(phaseStarting).Set(0)
s.phase.WithLabelValues(phaseRunning).Set(1)
}
Expand Down

0 comments on commit d2e1992

Please sign in to comment.