Skip to content

[surfacers.probestatus] Don't panic when the dashboard window is under a minute - #1448

Merged
manugarg merged 1 commit into
cloudprober:mainfrom
erik-bessegato:fix-dashboard-durations-panic
Sep 12, 2026
Merged

manugarg merged 1 commit into
cloudprober:mainfrom
erik-bessegato:fix-dashboard-durations-panic

Conversation

@erik-bessegato

Copy link
Copy Markdown
Contributor

Description

dashboardDurations() builds the duration list for the status page dashboard:

for _, td := range baseDurations {
    if td <= maxDuration {
        result = append(result, td)
    }
}
if result[len(result)-1] != maxDuration {

maxDuration is resolution_sec * timeseries_size, and baseDurations starts
at one minute. If that product is under 60s, nothing is appended and
result[len(result)-1] indexes an empty slice.

New() calls it at probestatus.go:183 before returning, so this is a startup
panic rather than a bad page. With:

surfacer {
  type: PROBESTATUS
  probestatus_surfacer {
    resolution_sec: 1
    timeseries_size: 30
  }
}

cloudprober exits immediately:

panic: runtime error: index out of range [-1]

goroutine 1 [running]:
...probestatus.dashboardDurations(0x6fc23ac00)
	internal/surfacers/probestatus/dashboard.go:36
...probestatus.New(...)
	internal/surfacers/probestatus/probestatus.go:183
...surfacers.initSurfacer(...)
	surfacers/surfacers.go:238
...prober.Init(...)
	prober/prober.go:393
main.main()
	cmd/cloudprober/main.go:157

The defaults (60s x 4320) are far above the threshold, so this only shows up on
a deliberately short window -- a high-resolution, small-buffer setup.

Fix

Handle the empty case. When maxDuration is below the smallest base duration
it is the only sensible entry in the list, so the existing append is right;
it just needs to not read the slice first.

Tests

Two cases added to TestDashboardDurations (30s and 59s). Both panic against
current main and pass with the change.

Verification

go test ./internal/surfacers/probestatus/... passes. Reverting dashboard.go
while keeping the new test cases reproduces the panic in the test run, so the
cases genuinely cover the guard rather than just passing alongside it. Also
confirmed the config above now starts normally and the status page renders with
a 30s dashboard option.

Note

A zero resolution_sec or timeseries_size makes maxDuration 0, which no
longer panics with this change but produces a "0d" dashboard entry. That looked
like a separate question about validating the surfacer config in New(), so I
left it out of this PR -- happy to follow up if you'd like it rejected at
config time instead.

…r a minute

dashboardDurations() collects the base durations that fit within
resolution_sec * timeseries_size, then reads result[len(result)-1] to decide
whether to append maxDuration. baseDurations starts at one minute, so any
product below 60s leaves result empty and the index panics. New() calls this
before returning, so cloudprober dies at startup rather than surfacing a
config error.

Handle the empty case: when maxDuration is smaller than the smallest base
duration it is the only sensible entry. Covered by two new cases in
TestDashboardDurations, both of which panic without the guard.
@erik-bessegato
erik-bessegato marked this pull request as ready for review August 31, 2026 21:18
@manugarg manugarg changed the title [surfacers/probestatus] Don't panic when the dashboard window is under a minute [surfacers.probestatus] Don't panic when the dashboard window is under a minute Sep 12, 2026
@manugarg
manugarg merged commit 121b3cc into cloudprober:main Sep 12, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants