feat(go): expose fast writer batch pending metrics

This commit is contained in:
lingniu
2026-07-03 19:20:09 +08:00
parent 3b694671fa
commit c43b87d648
6 changed files with 93 additions and 4 deletions

View File

@@ -262,6 +262,8 @@ func processFastBatch(ctx context.Context, registry *metrics.Registry, appender
if len(envelopes) == 0 {
return nil
}
setFastBatchPending(registry, len(messages), len(envelopes))
defer setFastBatchPending(registry, 0, 0)
subject := fastBatchSubject(validMessages)
started := time.Now()
err := appender.AppendAllBatch(ctx, envelopes)
@@ -367,6 +369,14 @@ func addFastMetric(registry *metrics.Registry, subject string, status string) {
registry.IncCounter("vehicle_fast_writer_messages_total", metrics.Labels{"subject": subject, "status": status})
}
func setFastBatchPending(registry *metrics.Registry, messages int, envelopes int) {
if registry == nil {
return
}
registry.SetGauge("vehicle_fast_writer_batch_pending_messages", nil, float64(messages))
registry.SetGauge("vehicle_fast_writer_batch_pending_envelopes", nil, float64(envelopes))
}
func recordFastWriterStageDuration(registry *metrics.Registry, subject string, stage string, status string, elapsed time.Duration) {
if registry == nil {
return