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

@@ -58,7 +58,7 @@ func TestProcessHistoryMessageRecordsMetrics(t *testing.T) {
registry,
&contextCheckingHistoryAppender{},
&contextCheckingHistoryCommitter{},
kafka.Message{Topic: "vehicle.raw.gb32960.v1", Value: payload},
kafka.Message{Topic: "vehicle.raw.gb32960.v1", Partition: 1, Offset: 20, HighWaterMark: 23, Value: payload},
)
text := registry.Render()
@@ -66,6 +66,7 @@ func TestProcessHistoryMessageRecordsMetrics(t *testing.T) {
`vehicle_history_kafka_messages_total{status="received",topic="vehicle.raw.gb32960.v1"} 1`,
`vehicle_history_writes_total{status="ok",topic="vehicle.raw.gb32960.v1"} 1`,
`vehicle_history_kafka_commits_total{status="ok",topic="vehicle.raw.gb32960.v1"} 1`,
`vehicle_history_kafka_lag{partition="1",topic="vehicle.raw.gb32960.v1"} 2`,
} {
if !strings.Contains(text, want) {
t.Fatalf("metrics missing %s:\n%s", want, text)