Skip to content

Commit 9c1b094

Browse files
serghei-devsergeyklay
authored andcommitted
fix(server): handle collapsed row panels and deduplicate metric list in tests
Walk nested panels inside collapsed row panels so the dashboard coverage test does not silently miss metrics when a re-exported JSON uses Grafana's collapsed row format. Reuse knownSortieMetrics in TestNewPromMetrics to eliminate the duplicated metric list and prevent drift between the two tests.
1 parent 5e4c8a3 commit 9c1b094

2 files changed

Lines changed: 19 additions & 36 deletions

File tree

internal/server/grafana_coverage_test.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,34 @@ func TestGrafanaDashboardCoversAllMetrics(t *testing.T) {
6363
t.Fatalf("reading grafana dashboard: %v", err)
6464
}
6565

66+
type panelJSON struct {
67+
Targets []struct {
68+
Expr string `json:"expr"`
69+
} `json:"targets"`
70+
Panels []panelJSON `json:"panels"` // collapsed rows nest panels here
71+
}
6672
var dash struct {
67-
Panels []struct {
68-
Targets []struct {
69-
Expr string `json:"expr"`
70-
} `json:"targets"`
71-
} `json:"panels"`
73+
Panels []panelJSON `json:"panels"`
7274
}
7375
if err := json.Unmarshal(raw, &dash); err != nil {
7476
t.Fatalf("parsing grafana dashboard JSON: %v", err)
7577
}
7678

77-
// Collect all sortie_ base metric names referenced across all panels.
79+
// Collect all sortie_ base metric names referenced across all panels,
80+
// including panels nested inside collapsed rows.
7881
referenced := make(map[string]bool, len(knownSortieMetrics))
79-
for _, panel := range dash.Panels {
80-
for _, target := range panel.Targets {
81-
for _, match := range promqlMetricRE.FindAllString(target.Expr, -1) {
82-
referenced[stripHistogramSuffix(match)] = true
82+
var walkPanels func([]panelJSON)
83+
walkPanels = func(panels []panelJSON) {
84+
for _, panel := range panels {
85+
for _, target := range panel.Targets {
86+
for _, match := range promqlMetricRE.FindAllString(target.Expr, -1) {
87+
referenced[stripHistogramSuffix(match)] = true
88+
}
8389
}
90+
walkPanels(panel.Panels)
8491
}
8592
}
93+
walkPanels(dash.Panels)
8694

8795
for _, name := range knownSortieMetrics {
8896
if !referenced[name] {

internal/server/metrics_test.go

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -134,32 +134,7 @@ func TestNewPromMetrics(t *testing.T) {
134134

135135
families := gatherFamilies(t, m)
136136

137-
sortieMetrics := []string{
138-
"sortie_sessions_running",
139-
"sortie_sessions_retrying",
140-
"sortie_slots_available",
141-
"sortie_active_sessions_elapsed_seconds",
142-
"sortie_tokens_total",
143-
"sortie_agent_runtime_seconds_total",
144-
"sortie_dispatches_total",
145-
"sortie_worker_exits_total",
146-
"sortie_retries_total",
147-
"sortie_reconciliation_actions_total",
148-
"sortie_poll_cycles_total",
149-
"sortie_tracker_requests_total",
150-
"sortie_handoff_transitions_total",
151-
"sortie_dispatch_transitions_total",
152-
"sortie_tracker_comments_total",
153-
"sortie_tool_calls_total",
154-
"sortie_poll_duration_seconds",
155-
"sortie_worker_duration_seconds",
156-
"sortie_ssh_host_usage",
157-
"sortie_ci_status_checks_total",
158-
"sortie_ci_escalations_total",
159-
"sortie_build_info",
160-
}
161-
162-
for _, name := range sortieMetrics {
137+
for _, name := range knownSortieMetrics {
163138
if _, ok := families[name]; !ok {
164139
t.Errorf("expected metric family %q not found", name)
165140
}

0 commit comments

Comments
 (0)