test: cover daemon telemetry publication
This commit is contained in:
@@ -245,15 +245,7 @@ func publishServerTelemetry(ctx context.Context, persistence *store.Store, healt
|
||||
ticker := time.NewTicker(10 * time.Second)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
sampleContext, cancel := context.WithTimeout(ctx, time.Second)
|
||||
telemetry, err := persistence.Telemetry(sampleContext)
|
||||
cancel()
|
||||
if err != nil {
|
||||
health.Inc("telemetry_read_failure")
|
||||
} else {
|
||||
health.SetGauge("queue_depth", float64(telemetry.QueuedCommands))
|
||||
health.SetGauge("server_charged_bytes", float64(telemetry.ChargedBytes))
|
||||
}
|
||||
publishServerTelemetrySample(ctx, persistence.Telemetry, health)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
@@ -261,3 +253,18 @@ func publishServerTelemetry(ctx context.Context, persistence *store.Store, healt
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// publishServerTelemetrySample performs one intentionally bounded, best-effort
|
||||
// telemetry read. A failed metrics read must never affect server readiness or
|
||||
// durable command processing.
|
||||
func publishServerTelemetrySample(ctx context.Context, read func(context.Context) (store.Telemetry, error), health *observability.Health) {
|
||||
sampleContext, cancel := context.WithTimeout(ctx, time.Second)
|
||||
telemetry, err := read(sampleContext)
|
||||
cancel()
|
||||
if err != nil {
|
||||
health.Inc("telemetry_read_failure")
|
||||
return
|
||||
}
|
||||
health.SetGauge("queue_depth", float64(telemetry.QueuedCommands))
|
||||
health.SetGauge("server_charged_bytes", float64(telemetry.ChargedBytes))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user