Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Fix HEALTHY-on-empty and surface AI discoverability in reports
rcourtman371a04ad4396
diff --git a/pkg/reporting/pdf.go b/pkg/reporting/pdf.goindex b9e4c02252..9cb4a70b5d 100644--- a/pkg/reporting/pdf.go+++ b/pkg/reporting/pdf.go@@ -224,6 +224,16 @@ func (g *PDFGenerator) writeExecutiveSummary(pdf *fpdf.Fpdf, data *ReportData) {} else {healthMessage = fmt.Sprintf("%d warnings detected - review recommended", warningAlerts)}+ } else if data.TotalPoints == 0 && len(data.Summary.ByMetric) == 0 {+ // No metrics arrived for the requested window. Reporting+ // HEALTHY would green-light an empty report and mislead the+ // operator into thinking the resource is fine when really+ // Pulse has no data to evaluate. Fall back to a muted+ // "NO DATA" card so the executive summary stays consistent+ // with the "Data Points: 0" line on the cover.+ healthStatus = "NO DATA"+ healthColor = colorTextMuted+ healthMessage = "No metrics reported during the selected window"}// Health Status Card@@ -412,6 +422,19 @@ func (g *PDFGenerator) writeExecutiveSummary(pdf *fpdf.Fpdf, data *ReportData) {pdf.SetFont("Arial", "I", 8)pdf.SetTextColor(colorTextMuted[0], colorTextMuted[1], colorTextMuted[2])pdf.MultiCell(pageWidth-40, 4, disclaimer, "", "L", false)+ } else if data.Narrative.Source == NarrativeSourceHeuristic {+ // Discoverability nudge: when the report fell back to the+ // deterministic heuristic narrator, surface a one-line tip+ // so users learn the AI upgrade exists. Without this, a+ // user whose AI is unconfigured (or whose provider failed)+ // has zero indication that AI-narrated reports are a+ // separate capability behind Pulse Assistant.+ pdf.Ln(4)+ pdf.SetFont("Arial", "I", 8)+ pdf.SetTextColor(colorTextMuted[0], colorTextMuted[1], colorTextMuted[2])+ pdf.MultiCell(pageWidth-40, 4,+ "Tip: Configure Pulse Assistant in Settings to add AI-narrated executive summaries, fleet outlier detection, and period-over-period comparison to future reports.",+ "", "L", false)}}@@ -2009,6 +2032,18 @@ func writeFleetNarrativeSection(pdf *fpdf.Fpdf, fn *FleetNarrative) {pdf.SetFont("Arial", "I", 8)pdf.SetTextColor(colorTextMuted[0], colorTextMuted[1], colorTextMuted[2])pdf.MultiCell(bodyWidth, 4, disclaimer, "", "L", false)+ } else if fn.Source == NarrativeSourceHeuristic {+ // Same discoverability nudge as the single-resource path: a+ // heuristic fleet narrative is functional but doesn't surface+ // the AI capability that would have produced this section.+ // Without the nudge, the user has no signal that fleet AI+ // synthesis is a thing they could enable.+ pdf.Ln(4)+ pdf.SetFont("Arial", "I", 8)+ pdf.SetTextColor(colorTextMuted[0], colorTextMuted[1], colorTextMuted[2])+ pdf.MultiCell(bodyWidth, 4,+ "Tip: Configure Pulse Assistant in Settings to add AI-narrated fleet synthesis with named outliers, cross-cutting patterns, and period-over-period comparison to future reports.",+ "", "L", false)}}diff --git a/pkg/reporting/pdf_ux_test.go b/pkg/reporting/pdf_ux_test.gonew file mode 100644index 0000000000..b233d9b6e9--- /dev/null+++ b/pkg/reporting/pdf_ux_test.go@@ -0,0 +1,229 @@+package reporting++import (+ "bytes"+ "compress/zlib"+ "io"+ "regexp"+ "strings"+ "testing"+ "time"++ "github.com/go-pdf/fpdf"+)++// TestExecutiveSummary_EmptyDataShowsNoData asserts that when a report+// runs against a window that produced zero data points and no alerts,+// the executive summary renders a muted "NO DATA" card rather than the+// green HEALTHY card it shipped with originally. This was a real UX+// bug found by generating an actual PDF: a user looking at an+// empty-window report would see "All systems operating normally" and+// believe their resource was fine when really Pulse had no metrics to+// evaluate.+func TestExecutiveSummary_EmptyDataShowsNoData(t *testing.T) {+ data := &ReportData{+ Title: "Empty",+ ResourceType: "node",+ ResourceID: "empty",+ Start: time.Now().Add(-time.Hour),+ End: time.Now(),+ GeneratedAt: time.Now(),+ Metrics: map[string][]MetricDataPoint{},+ Summary: MetricSummary{ByMetric: map[string]MetricStats{}},+ TotalPoints: 0,+ }+ text := renderExecutiveSummaryText(t, data)+ if !strings.Contains(text, "NO DATA") {+ t.Errorf("expected 'NO DATA' card on empty data, got:\n%s", text)+ }+ if strings.Contains(text, "All systems operating normally") {+ t.Errorf("HEALTHY message should not appear on empty data, got:\n%s", text)+ }+}++// TestExecutiveSummary_HealthyWhenDataPresent_NoAlerts confirms the+// HEALTHY path still works when there IS data and no alerts. This is+// the regression guard: the empty-data fix above must not change the+// behavior for actually-quiet resources.+func TestExecutiveSummary_HealthyWhenDataPresent_NoAlerts(t *testing.T) {+ data := &ReportData{+ Title: "Quiet",+ ResourceType: "node",+ ResourceID: "quiet",+ Start: time.Now().Add(-time.Hour),+ End: time.Now(),+ GeneratedAt: time.Now(),+ Summary: MetricSummary{ByMetric: map[string]MetricStats{+ "cpu": {Avg: 5, Max: 12, Count: 60},+ "memory": {Avg: 30, Max: 35, Count: 60},+ }},+ TotalPoints: 120,+ }+ text := renderExecutiveSummaryText(t, data)+ if !strings.Contains(text, "HEALTHY") {+ t.Errorf("expected HEALTHY card on quiet resource, got:\n%s", text)+ }+}++// TestExecutiveSummary_HeuristicSourceShowsDiscoverabilityTip asserts+// that when the narrative came from the heuristic narrator (no AI+// configured or AI failed), the executive summary surfaces a one-line+// tip pointing operators at Pulse Assistant. Without this nudge a+// user has no signal that AI-narrated reports are a separate+// capability they could enable.+func TestExecutiveSummary_HeuristicSourceShowsDiscoverabilityTip(t *testing.T) {+ data := &ReportData{+ Title: "Quiet",+ ResourceType: "node",+ ResourceID: "quiet",+ Start: time.Now().Add(-time.Hour),+ End: time.Now(),+ GeneratedAt: time.Now(),+ Summary: MetricSummary{ByMetric: map[string]MetricStats{+ "cpu": {Avg: 10, Max: 20, Count: 60},+ }},+ TotalPoints: 60,+ Narrative: &Narrative{+ Source: NarrativeSourceHeuristic,+ HealthStatus: "HEALTHY",+ HealthMessage: "OK",+ Observations: []NarrativeBullet{{Text: "Looks fine", Severity: NarrativeSeverityOK}},+ },+ }+ text := renderExecutiveSummaryText(t, data)+ if !strings.Contains(text, "Configure Pulse Assistant") {+ t.Errorf("expected discoverability tip on heuristic-source narrative, got:\n%s", text)+ }+}++// TestExecutiveSummary_AISourceDoesNotShowDiscoverabilityTip is the+// converse: when AI actually fired, the disclaimer footer (which the+// AI narrator populates) replaces the tip. Showing both would be+// noisy and contradict the AI provenance line.+func TestExecutiveSummary_AISourceDoesNotShowDiscoverabilityTip(t *testing.T) {+ data := &ReportData{+ Title: "Quiet",+ ResourceType: "node",+ ResourceID: "quiet",+ Start: time.Now().Add(-time.Hour),+ End: time.Now(),+ GeneratedAt: time.Now(),+ Summary: MetricSummary{ByMetric: map[string]MetricStats{+ "cpu": {Avg: 10, Max: 20, Count: 60},+ }},+ TotalPoints: 60,+ Narrative: &Narrative{+ Source: NarrativeSourceAI,+ HealthStatus: "HEALTHY",+ HealthMessage: "OK",+ Observations: []NarrativeBullet{{Text: "AI prose here", Severity: NarrativeSeverityOK}},+ Disclaimer: "Narrative generated by Pulse Assistant.",+ },+ }+ text := renderExecutiveSummaryText(t, data)+ if strings.Contains(text, "Configure Pulse Assistant") {+ t.Errorf("discoverability tip should not appear when AI fired, got:\n%s", text)+ }+ if !strings.Contains(text, "Narrative generated by Pulse Assistant") {+ t.Errorf("expected AI provenance disclaimer when source is ai, got:\n%s", text)+ }+}++// TestFleetSummary_HeuristicSourceShowsDiscoverabilityTip mirrors the+// single-resource test for the fleet path. The fleet narrative has a+// distinct nudge (mentions outliers / patterns) so the copy doesn't+// over-promise single-resource synthesis.+func TestFleetSummary_HeuristicSourceShowsDiscoverabilityTip(t *testing.T) {+ now := time.Now()+ multi := &MultiReportData{+ Title: "Fleet",+ Start: now.Add(-time.Hour),+ End: now,+ GeneratedAt: now,+ Resources: []*ReportData{+ {+ ResourceID: "a",+ ResourceType: "node",+ Resource: &ResourceInfo{Name: "alpha", Status: "online"},+ Summary: MetricSummary{ByMetric: map[string]MetricStats{"cpu": {Avg: 10, Max: 15, Count: 60}}},+ TotalPoints: 60,+ },+ },+ FleetNarrative: &FleetNarrative{+ Source: NarrativeSourceHeuristic,+ HealthStatus: "HEALTHY",+ HealthMessage: "Fleet quiet",+ },+ }+ text := renderFleetSummaryText(t, multi)+ if !strings.Contains(text, "Configure Pulse Assistant") {+ t.Errorf("expected fleet discoverability tip on heuristic source, got:\n%s", text)+ }+ if !strings.Contains(text, "outliers") && !strings.Contains(text, "patterns") {+ t.Errorf("fleet tip should mention outliers/patterns, got:\n%s", text)+ }+}++// renderExecutiveSummaryText runs writeExecutiveSummary against a+// fresh fpdf, extracts text by parsing the resulting PDF, and returns+// the rendered text content. Used by the UX assertions above.+func renderExecutiveSummaryText(t *testing.T, data *ReportData) string {+ t.Helper()+ gen := NewPDFGenerator()+ bytes, err := gen.Generate(data)+ if err != nil {+ t.Fatalf("Generate: %v", err)+ }+ return extractPDFText(t, bytes)+}++func renderFleetSummaryText(t *testing.T, data *MultiReportData) string {+ t.Helper()+ gen := NewPDFGenerator()+ bytes, err := gen.GenerateMulti(data)+ if err != nil {+ t.Fatalf("GenerateMulti: %v", err)+ }+ return extractPDFText(t, bytes)+}++// extractPDFText pulls plain text out of a PDF blob by finding every+// FlateDecode'd content stream, inflating it, and harvesting the+// parenthesised string literals used by Tj operators. fpdf always+// compresses its content streams, so a substring scan over the raw+// bytes misses everything visible to a reader.+var streamRe = regexp.MustCompile(`(?s)stream\r?\n(.*?)\r?\nendstream`)+var literalRe = regexp.MustCompile(`\(([^()\\]*(?:\\.[^()\\]*)*)\)`)++func extractPDFText(t *testing.T, data []byte) string {+ t.Helper()+ var out bytes.Buffer+ for _, m := range streamRe.FindAllSubmatch(data, -1) {+ raw := m[1]+ decoded, err := inflateStream(raw)+ if err != nil {+ // Stream may not be Flate'd (e.g. xref tables) — skip.+ continue+ }+ for _, lit := range literalRe.FindAllSubmatch(decoded, -1) {+ out.Write(lit[1])+ out.WriteByte(' ')+ }+ }+ return out.String()+}++func inflateStream(b []byte) ([]byte, error) {+ r, err := zlib.NewReader(bytes.NewReader(b))+ if err != nil {+ return nil, err+ }+ defer r.Close()+ return io.ReadAll(r)+}++// Compile-time assertion the fpdf import isn't dropped by goimports+// when this test file is processed in isolation; the import lives in+// pdf.go but tests referencing fpdf.New constants confirm we still+// resolve the package.+var _ = fpdf.New