grafana/k6 · error

metric flush period should be positive but was %s

Error message

metric flush period should be positive but was %s

What it means

NewPeriodicFlusher rejected the requested flush period because it was zero or negative. The periodic flusher needs a strictly positive interval to schedule its flush goroutine; callers typically derive it from a flush-period configuration option, so the real fault is an invalid configured period.

Source

Thrown at output/helpers.go:91

			return
		}
	}
}

// Stop waits for the periodic flusher flush one last time and exit. You can
// safely call Stop() multiple times from different goroutines, you just can't
// call it from inside of the flushing function.
func (pf *PeriodicFlusher) Stop() {
	pf.once.Do(func() {
		close(pf.stop)
	})
	<-pf.stopped
}

// NewPeriodicFlusher creates a new PeriodicFlusher and starts its goroutine.
func NewPeriodicFlusher(period time.Duration, flushCallback func()) (*PeriodicFlusher, error) {
	if period <= 0 {
		return nil, fmt.Errorf("metric flush period should be positive but was %s", period)
	}

	pf := &PeriodicFlusher{
		period:        period,
		flushCallback: flushCallback,
		stop:          make(chan struct{}),
		stopped:       make(chan struct{}),
		once:          &sync.Once{},
	}

	go pf.run()

	return pf, nil
}

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Set the relevant flush period option to a positive duration (e.g. K6_METRIC_FLUSH_INTERVAL='1s' or output-specific flush period settings)
  2. Check the units — a bare number may parse as nanoseconds or fail validation
  3. Ensure no configuration layer sets the period to 0 or a negative value
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at output/helpers.go:91 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/c658a91f3fc40033. Report an issue: GitHub.