feat(go): expose kafka consumer lag metrics

This commit is contained in:
lingniu
2026-07-02 19:23:01 +08:00
parent 41ff0bcef4
commit 1f4a23ff69
9 changed files with 63 additions and 3 deletions

View File

@@ -46,6 +46,24 @@ func TestRegistryRendersGaugesWithLabels(t *testing.T) {
}
}
func TestRegistryRecordsKafkaLagGauge(t *testing.T) {
registry := NewRegistry()
registry.SetKafkaLag("vehicle_history_kafka_lag", "vehicle.raw.go.jt808.v1", 3, 101, 130)
registry.SetKafkaLag("vehicle_history_kafka_lag", "vehicle.raw.go.gb32960.v1", 0, 9, 9)
text := registry.Render()
for _, want := range []string{
`# TYPE vehicle_history_kafka_lag gauge`,
`vehicle_history_kafka_lag{partition="0",topic="vehicle.raw.go.gb32960.v1"} 0`,
`vehicle_history_kafka_lag{partition="3",topic="vehicle.raw.go.jt808.v1"} 28`,
} {
if !strings.Contains(text, want) {
t.Fatalf("metrics missing %s:\n%s", want, text)
}
}
}
func TestHandlerServesPrometheusText(t *testing.T) {
registry := NewRegistry()
registry.IncCounter("vehicle_kafka_commits_total", Labels{"service": "history"})