grafana/k6 · error
invalid duration
Error message
invalid duration
What it means
Dashboard options parsing (internal/dashboard/options.go:199 defines errInvalidDuration; used at lines 83 and 141) converts the sampling period to a Go time.Duration. If K6_WEB_DASHBOARD_PERIOD or the `period` query param of `--out web-dashboard=period=...` is not a valid Go duration string, errInvalidDuration is returned.
Solutions
- Use Go duration syntax: `K6_WEB_DASHBOARD_PERIOD=10s`, or `1m`, `500ms`.
- Double-check the `period=` value inside the `--out web-dashboard=...` query string.
Example fix
# before K6_WEB_DASHBOARD_PERIOD=10 k6 run --web-dashboard script.js # after K6_WEB_DASHBOARD_PERIOD=10s k6 run --web-dashboard script.js
Defensive patterns
Strategy: validation
Validate before calling
# validate Go duration syntax before launching k6
if [ -n "${K6_WEB_DASHBOARD_PERIOD:-}" ] && ! echo "$K6_WEB_DASHBOARD_PERIOD" | grep -qE '^[0-9]+(\.[0-9]+)?(ns|us|µs|ms|s|m|h)$'; then
echo "K6_WEB_DASHBOARD_PERIOD must look like 10s, 1m, 500ms"; exit 1
fi Prevention
- Remember k6 durations use Go syntax (10s) — never bare numbers or JS-style 10sec.
- Keep dashboard settings in one env block with a comment showing valid examples.
When it happens
Trigger: Setting K6_WEB_DASHBOARD_PERIOD=10 (no unit), =10seconds (wrong unit word), or =1sec instead of Go syntax like 10s, 1m, 500ms; the same value passed as `--out web-dashboard=period=10s`.
Common situations: Users assuming seconds-by-default or JS-style durations ('10sec'); porting configs between tools with different duration grammars.
Understand the failure class
Background: "invalid duration" / "failed to parse duration": why your timeout, interval, or TTL string is rejected and which formats each library accepts — this error's family across 32 libraries.
Related errors
- unknown metric
- access token not configured
- both K6_CLOUD_METRICS_PUSH_URL and K6_CLOUD_TEST_RUN_TOKEN…
- both K6_CLOUD_METRICS_PUSH_URL and K6_CLOUD_TEST_RUN_TOKEN…
- browser not found in registry. make sure to set browser…
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/d2a7fa7d1d9b16c7.
Report an issue: GitHub.
Appendix: source
Thrown at internal/dashboard/options.go:199
}
// period adjusts period, limit points per test run to 'points'.
func (opts *options) period(duration time.Duration) time.Duration {
if duration == 0 {
return opts.Period
}
optimal := float64(duration) / float64(points)
return time.Duration(math.Ceil(optimal/float64(opts.Period))) * opts.Period
}
/*
approx. 1MB max report size, 8 hours test run with 10sec event period.
*/
const points = 2880
var errInvalidDuration = errors.New("invalid duration")
const (
envPrefix = "K6_WEB_DASHBOARD_"
paramPort = "port"
envPort = envPrefix + "PORT"
paramHost = "host"
envHost = envPrefix + "HOST"
paramPeriod = "period"
envPeriod = envPrefix + "PERIOD"
paramOpen = "open"
envOpen = envPrefix + "OPEN"
paramReport = "report"
envReport = envPrefix + "REPORT"View on GitHub (pinned to 01ffac6f24)