From 64fa67e4d86a72d3b92ddce5ec37864db56878d8 Mon Sep 17 00:00:00 2001 From: Jan Svabenik Date: Sun, 5 Apr 2026 17:08:01 +0200 Subject: [PATCH] Expose queue health in runtime stats --- cmd/fmrtx/main.go | 1 + cmd/fmrtx/main_test.go | 36 +++++++++++++++++++++++++ docs/pro-runtime-hardening-workboard.md | 3 ++- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 cmd/fmrtx/main_test.go diff --git a/cmd/fmrtx/main.go b/cmd/fmrtx/main.go index 9e7a5fa..573070b 100644 --- a/cmd/fmrtx/main.go +++ b/cmd/fmrtx/main.go @@ -254,6 +254,7 @@ func (b *txBridge) TXStats() map[string]any { "maxGenerateMs": s.MaxGenerateMs, "maxUpsampleMs": s.MaxUpsampleMs, "maxWriteMs": s.MaxWriteMs, + "queue": s.Queue, } } func (b *txBridge) UpdateConfig(lp ctrlpkg.LivePatch) error { diff --git a/cmd/fmrtx/main_test.go b/cmd/fmrtx/main_test.go new file mode 100644 index 0000000..b2bd2dd --- /dev/null +++ b/cmd/fmrtx/main_test.go @@ -0,0 +1,36 @@ +package main + +import ( + "testing" + + apppkg "github.com/jan/fm-rds-tx/internal/app" + cfgpkg "github.com/jan/fm-rds-tx/internal/config" + "github.com/jan/fm-rds-tx/internal/output" + "github.com/jan/fm-rds-tx/internal/platform" +) + +func TestTxBridgeExportsQueueStats(t *testing.T) { + cfg := cfgpkg.Default() + driver := platform.NewSimulatedDriver(nil) + engine := apppkg.NewEngine(cfg, driver) + bridge := &txBridge{engine: engine} + stats := bridge.TXStats() + + raw, ok := stats["queue"] + if !ok { + t.Fatalf("expected queue stats in tx stats") + } + + queue, ok := raw.(output.QueueStats) + if !ok { + t.Fatalf("queue stats type mismatch: %T", raw) + } + + if queue.Capacity != cfg.Runtime.FrameQueueCapacity { + t.Fatalf("unexpected queue capacity: want %d got %d", cfg.Runtime.FrameQueueCapacity, queue.Capacity) + } + + if queue.Health != output.QueueHealthCritical { + t.Fatalf("queue health should be critical with empty queue, got %s", queue.Health) + } +} diff --git a/docs/pro-runtime-hardening-workboard.md b/docs/pro-runtime-hardening-workboard.md index 202f7a8..f1eb60e 100644 --- a/docs/pro-runtime-hardening-workboard.md +++ b/docs/pro-runtime-hardening-workboard.md @@ -247,13 +247,14 @@ Generator/Upsampler und Hardwarewriter werden als getrennte Stufen mit kleinem, | Datum | Entscheidung | Notiz | |---|---|---| | 2026-04-05 | FrameQueue mit Engine-Integration | Queue lebt nach dem Upsampler auf DeviceFrame-Ebene, Kapazität via `runtime.frameQueueCapacity`, `EngineStats` zeigt `QueueStats`, Tests decken Timeouts und Counters ab. | -| 2026-04-05 | Queue-Health-Indikator | `QueueStats.Health` gibt `critical`/`low`/`normal` zurück und ist über `EngineStats.Queue` im Runtime-Endpunkt sichtbar. | +| 2026-04-05 | Queue-Health-Indikator | `QueueStats.Health` gibt `critical`/`low`/`normal` zurück und `txBridge` leitet `EngineStats.Queue` ins `/runtime`-JSON. | ## WS-01 Verifikation | Datum | Fokus | Ergebnis | |---|---|---| | 2026-04-05 | FrameQueue + Engine integration | ✅ `go test ./...` (im `internal`-Modul incl. `frame_queue_test.go`) | | 2026-04-05 | Queue-Health-Indikator | go test ./... deckt `TestFrameQueueHealthIndicator` und `queue.health` ab. | +| 2026-04-05 | Runtime API queue health | ✅ `/runtime` liefert jetzt `engine.queue.health` dank `txBridge.TXStats`. | ---