grafana/k6 · error

invalid duration

Error message

invalid duration

What it means

The web dashboard output parses its `period` setting with Go's time.ParseDuration (options.go:81 and :139); on parse failure it discards the underlying detail and returns the generic errInvalidDuration. Period controls how often metric points are sampled into the report.

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 93accf6570)

Solutions

  1. Use Go duration syntax with an explicit unit: K6_WEB_DASHBOARD_PERIOD=10s or --out web-dashboard=period=30s
  2. Supported units: ns, us (µs), ms, s, m, h; compound values like 1m30s work
  3. Leave period unset to keep the 10s default

Example fix

# before
K6_WEB_DASHBOARD_PERIOD=10 k6 run --out web-dashboard script.js

# after
K6_WEB_DASHBOARD_PERIOD=10s k6 run --out web-dashboard script.js
Defensive patterns

Strategy: validation

Validate before calling

# Reject unit-less dashboard periods before launching
period="${K6_WEB_DASHBOARD_PERIOD:-10s}"
case "$period" in
  *[0-9](ns|us|ms|s|m|h)) ;;
  *) echo "K6_WEB_DASHBOARD_PERIOD must use Go duration units (e.g. 10s, 1m)" >&2; exit 1;;
esac

Prevention

When it happens

Trigger: Setting K6_WEB_DASHBOARD_PERIOD or `--out web-dashboard=period=...` to a bare number ('10', '500') or unit-less/misspelled value ('10 seconds', '10sec') — values must carry a Go duration unit such as '10s', '1m', '1m30s'.

Common situations: Assuming milliseconds or seconds are the default unit; copying duration syntax from other tools; CI env vars written without units.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/d2a7fa7d1d9b16c7. Report an issue: GitHub.