refactor(go): make raw topics the realtime source

This commit is contained in:
lingniu
2026-07-03 08:25:14 +08:00
parent c2d058bf75
commit 4c34c1221b
14 changed files with 151 additions and 44 deletions

View File

@@ -190,7 +190,8 @@ func consumeKafka(ctx context.Context, logger interface {
}
func kafkaTopicsFromEnv() []string {
return splitCSV(env("KAFKA_TOPICS", topics.Unified))
defaultTopics := strings.Join([]string{topics.RawGB32960, topics.RawJT808, topics.RawYutongMQTT}, ",")
return splitCSV(env("KAFKA_TOPICS", defaultTopics))
}
const kafkaMessageOperationTimeout = 30 * time.Second

View File

@@ -66,15 +66,15 @@ func TestProcessRealtimeMessageRecordsMetrics(t *testing.T) {
registry,
&contextCheckingRealtimeUpdater{},
&contextCheckingMessageCommitter{},
kafka.Message{Topic: "vehicle.event.go.unified.v1", Partition: 2, Offset: 10, HighWaterMark: 16, Value: payload},
kafka.Message{Topic: "vehicle.raw.go.jt808.v1", Partition: 2, Offset: 10, HighWaterMark: 16, Value: payload},
)
text := registry.Render()
for _, want := range []string{
`vehicle_realtime_kafka_messages_total{status="received",topic="vehicle.event.go.unified.v1"} 1`,
`vehicle_realtime_updates_total{status="ok",topic="vehicle.event.go.unified.v1"} 1`,
`vehicle_realtime_kafka_commits_total{status="ok",topic="vehicle.event.go.unified.v1"} 1`,
`vehicle_realtime_kafka_lag{partition="2",topic="vehicle.event.go.unified.v1"} 5`,
`vehicle_realtime_kafka_messages_total{status="received",topic="vehicle.raw.go.jt808.v1"} 1`,
`vehicle_realtime_updates_total{status="ok",topic="vehicle.raw.go.jt808.v1"} 1`,
`vehicle_realtime_kafka_commits_total{status="ok",topic="vehicle.raw.go.jt808.v1"} 1`,
`vehicle_realtime_kafka_lag{partition="2",topic="vehicle.raw.go.jt808.v1"} 5`,
} {
if !strings.Contains(text, want) {
t.Fatalf("metrics missing %s:\n%s", want, text)
@@ -96,9 +96,9 @@ func TestCompositeRealtimeUpdaterUpdatesBothStores(t *testing.T) {
}
}
func TestKafkaTopicsFromEnvDefaultsToGoUnifiedTopic(t *testing.T) {
func TestKafkaTopicsFromEnvDefaultsToGoRawTopics(t *testing.T) {
got := strings.Join(kafkaTopicsFromEnv(), ",")
want := "vehicle.event.go.unified.v1"
want := "vehicle.raw.go.gb32960.v1,vehicle.raw.go.jt808.v1,vehicle.raw.go.yutong-mqtt.v1"
if got != want {
t.Fatalf("topics = %q, want %q", got, want)
}