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

Report current_offset metric for incomplete partitions #830

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion core/internal/evaluator/caching.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func evaluatePartitionStatus(partition *protocol.ConsumerPartition, minimumCompl
}

// Slice the offsets to remove all nil entries (they'll be at the start)
firstOffset := len(partition.Offsets) - 1
firstOffset := len(partition.Offsets) // defaults to the length, so if all offsets are nil we make an empty slice
Copy link
Author

@andpol andpol Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this change, a runtime error: invalid memory address or nil pointer dereference was happening.

for i, offset := range partition.Offsets {
if offset != nil {
firstOffset = i
Expand Down
4 changes: 3 additions & 1 deletion core/internal/httpserver/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ func (hc *Coordinator) handlePrometheusMetrics() http.HandlerFunc {

consumerPartitionLagGauge.With(labels).Set(float64(partition.CurrentLag))

if partition.Complete == 1.0 {
if partition.Complete > 0.0 {
consumerPartitionCurrentOffset.With(labels).Set(float64(partition.End.Offset))
}
if partition.Complete == 1.0 {
partitionStatusGauge.With(labels).Set(float64(partition.Status))
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/internal/httpserver/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func TestHttpServer_handlePrometheusMetrics(t *testing.T) {
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`)
assert.NotContains(t, promExp, `burrow_kafka_consumer_current_offset{cluster="testcluster",consumer_group="testgroup",partition="0",topic="incomplete"} 5335`)
assert.Contains(t, promExp, `burrow_kafka_consumer_current_offset{cluster="testcluster",consumer_group="testgroup",partition="0",topic="incomplete"} 5335`)
assert.Contains(t, promExp, `burrow_kafka_consumer_current_offset{cluster="testcluster",consumer_group="testgroup",partition="1",topic="incomplete"} 99888`)

assert.Contains(t, promExp, `burrow_kafka_topic_partition_offset{cluster="testcluster",partition="0",topic="testtopic"} 6556`)
Expand Down