chore(push-gateway): ai02 module updates - config, hub, ws, kafka, health, docs

This commit is contained in:
SpecialX
2026-07-10 17:36:53 +08:00
parent dc0a6feec4
commit 3fac472a57
16 changed files with 2017 additions and 289 deletions

View File

@@ -120,6 +120,39 @@ func (c *Consumer) Close() error {
return c.reader.Close()
}
// HealthCheck verifies that the Kafka broker is reachable. Used by /readyz as
// a soft-failure probe: a failing check marks the consumer as degraded but
// does not return 503 (per ARB-015 §17.4 / ISSUE-058).
//
// The check issues a metadata request for the consumer topic; on success the
// broker is considered reachable. This is cheaper than a Lag() call which
// requires partition assignment to have completed.
func (c *Consumer) HealthCheck(ctx context.Context) error {
conn, err := kafka.DialContext(ctx, "tcp", c.reader.Config().Brokers[0])
if err != nil {
return fmt.Errorf("kafka: dial broker: %w", err)
}
defer conn.Close()
partitions, err := conn.ReadPartitions(c.topic)
if err != nil {
return fmt.Errorf("kafka: read partitions: %w", err)
}
if len(partitions) == 0 {
return fmt.Errorf("kafka: topic %q has no partitions", c.topic)
}
return nil
}
// Topic returns the configured topic name. Exposed for diagnostics.
func (c *Consumer) Topic() string {
return c.topic
}
// GroupID returns the configured consumer group name.
func (c *Consumer) GroupID() string {
return c.groupID
}
// processMessage handles a single Kafka message with retry and idempotency.
func (c *Consumer) processMessage(ctx context.Context, msg kafka.Message) {
var event NotificationRequested