Skip to content
Open
Show file tree
Hide file tree
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
21 changes: 21 additions & 0 deletions core/internal/httpserver/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ var (
[]string{"cluster", "consumer_group", "topic", "partition"},
)

consumerTopicLagGauge = promauto.NewGaugeVec(
prometheus.GaugeOpts{
Name: "burrow_kafka_consumer_topic_lag",
Help: "Number of messages the consumer group is behind by for a topic as reported by Burrow",
},
[]string{"cluster", "consumer_group", "topic"},
)

topicPartitionOffsetGauge = promauto.NewGaugeVec(
prometheus.GaugeOpts{
Name: "burrow_kafka_topic_partition_offset",
Expand Down Expand Up @@ -127,6 +135,8 @@ func (hc *Coordinator) handlePrometheusMetrics() http.HandlerFunc {
consumerTotalLagGauge.With(labels).Set(float64(consumerStatus.TotalLag))
consumerStatusGauge.With(labels).Set(float64(consumerStatus.Status))

topicLags := make(map[string]uint64)

for _, partition := range consumerStatus.Partitions {
labels := map[string]string{
"cluster": cluster,
Expand All @@ -136,12 +146,23 @@ func (hc *Coordinator) handlePrometheusMetrics() http.HandlerFunc {
}

consumerPartitionLagGauge.With(labels).Set(float64(partition.CurrentLag))
topicLags[partition.Topic] += partition.CurrentLag

if partition.Complete == 1.0 {
consumerPartitionCurrentOffset.With(labels).Set(float64(partition.End.Offset))
partitionStatusGauge.With(labels).Set(float64(partition.Status))
}
}

for topic, lag := range topicLags {
labels := map[string]string{
"cluster": cluster,
"consumer_group": consumer,
"topic": topic,
}

consumerTopicLagGauge.With(labels).Set(float64(lag))
}
}

// Topics
Expand Down
4 changes: 4 additions & 0 deletions core/internal/httpserver/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ func TestHttpServer_handlePrometheusMetrics(t *testing.T) {
assert.Contains(t, promExp, `burrow_kafka_consumer_partition_lag{cluster="testcluster",consumer_group="testgroup",partition="0",topic="incomplete"} 0`)
assert.Contains(t, promExp, `burrow_kafka_consumer_partition_lag{cluster="testcluster",consumer_group="testgroup",partition="1",topic="incomplete"} 10`)

assert.Contains(t, promExp, `burrow_kafka_consumer_topic_lag{cluster="testcluster",consumer_group="testgroup",topic="testtopic"} 110`)
assert.Contains(t, promExp, `burrow_kafka_consumer_topic_lag{cluster="testcluster",consumer_group="testgroup",topic="testtopic1"} 50`)
assert.Contains(t, promExp, `burrow_kafka_consumer_topic_lag{cluster="testcluster",consumer_group="testgroup",topic="incomplete"} 10`)

assert.Contains(t, promExp, `burrow_kafka_consumer_current_offset{cluster="testcluster",consumer_group="testgroup",partition="0",topic="testtopic"} 22663`)
assert.Contains(t, promExp, `burrow_kafka_consumer_current_offset{cluster="testcluster",consumer_group="testgroup",partition="1",topic="testtopic"} 2488`)
assert.Contains(t, promExp, `burrow_kafka_consumer_current_offset{cluster="testcluster",consumer_group="testgroup",partition="0",topic="testtopic1"} 99888`)
Expand Down