# TASK: Add Telemetry Debug Section to Controller Debug Page **Scope:** Controller only — add a "Telemetria teszt" section to the existing Debug page ## Overview The App Telemetry feature (metrics collection, log scanning, hub reporting, hub dashboard) is fully implemented and deployed. The remaining task is to add a debug section that lets the operator run telemetry collection on-demand and see the results — useful for verifying container→stack mapping, checking metrics DB values, and testing log scanner pattern matching without waiting for the 15-minute report cycle. --- ## What to Implement ### 1. New debug endpoint: `GET /api/debug/telemetry` **File:** `controller/internal/web/handler_debug.go` Add a new route case in `handleDebugAPI()` (between the existing "Section 5: Hub" and "Section 6: Self-Update" blocks, around line 83): ```go // Section: Telemetry testing case subpath == "telemetry" && r.Method == http.MethodGet: s.debugTelemetry(w, r) ``` Add the handler function: ```go func (s *Server) debugTelemetry(w http.ResponseWriter, r *http.Request) { start := time.Now() telemetry := report.BuildAppTelemetryForDebug(s.stackMgr, s.metricsStore, s.logger) latency := time.Since(start).Milliseconds() writeDebugJSON(w, http.StatusOK, true, fmt.Sprintf("Telemetria összegyűjtve: %d alkalmazás (%dms)", len(telemetry), latency), map[string]interface{}{ "latency_ms": latency, "app_count": len(telemetry), "app_telemetry": telemetry, }) } ``` **Problem:** The Server struct doesn't have `metricsStore`. There are two approaches: **Approach A (preferred): Add a `TriggerTelemetryTest` callback to `DebugCallbacks`** This follows the existing pattern for operations needing main.go wiring. The Server struct lacks `metricsStore` but main.go has it. In `handler_debug.go`, add to the `DebugCallbacks` struct: ```go type DebugCallbacks struct { TriggerHubReportPush func() error TriggerHubInfraPush func() error TriggerLocalInfraWrite func() error TriggerSetupMode func() error HubConnectivityTest func() (statusCode int, latencyMs int64, err error) GiteaConnectivityTest func() (statusCode int, latencyMs int64, err error) GetTelemetryPreview func() ([]report.AppTelemetry, error) // NEW } ``` Then the handler becomes: ```go func (s *Server) debugTelemetry(w http.ResponseWriter, r *http.Request) { if s.debugCallbacks == nil || s.debugCallbacks.GetTelemetryPreview == nil { writeDebugJSON(w, http.StatusNotImplemented, false, "Nem bekötött", nil) return } start := time.Now() telemetry, err := s.debugCallbacks.GetTelemetryPreview() latency := time.Since(start).Milliseconds() if err != nil { writeDebugJSON(w, http.StatusOK, false, err.Error(), map[string]interface{}{"latency_ms": latency}) return } // Compute summary stats totalErrors := 0 totalWarnings := 0 for _, app := range telemetry { totalErrors += app.LogErrors totalWarnings += app.LogWarnings } writeDebugJSON(w, http.StatusOK, true, fmt.Sprintf("Telemetria összegyűjtve: %d app, %d hiba, %d figyelmeztetés (%dms)", len(telemetry), totalErrors, totalWarnings, latency), map[string]interface{}{ "latency_ms": latency, "app_count": len(telemetry), "total_errors": totalErrors, "total_warnings": totalWarnings, "app_telemetry": telemetry, }) } ``` **Approach B: Export `buildAppTelemetrySection` from the report package** In `controller/internal/report/telemetry.go`, the function `buildAppTelemetrySection` is private (lowercase). Create a public wrapper: ```go // BuildAppTelemetryForDebug runs the telemetry collection pipeline (metrics + log scan) // and returns the result. Used by the debug endpoint. func BuildAppTelemetryForDebug(stackMgr *stacks.Manager, metricsStore *metrics.MetricsStore, logger *log.Logger) []AppTelemetry { return buildAppTelemetrySection(stackMgr, metricsStore, logger) } ``` Then wire the callback in main.go using this exported function. ### 2. Wire the callback in `cmd/controller/main.go` In the `DebugCallbacks` setup block (around line 615), add: ```go dc.GetTelemetryPreview = func() ([]report.AppTelemetry, error) { return report.BuildAppTelemetryForDebug(stackMgr, metricsStore, logger), nil } ``` This goes inside the existing `if cfg.Logging.Level == "debug"` block, alongside the other callback assignments. It does NOT need to be inside the `if hubPusher != nil` guard — telemetry works regardless of hub config. ### 3. Add the debug page section in `debug.html` **File:** `controller/internal/web/templates/debug.html` Add a new section between "Hub & Kapcsolatok" (section-hub) and "Önfrissítés teszt" (section-selfupdate). Insert after the closing `` of section-hub (line 128) and before the `` comment (line 130): ```html

Telemetria teszt

``` ### 4. Add JavaScript for the telemetry section in `debug.html` Add in the `