grafana/k6 · error

malformed percentile value, provide a number between 0 and 1

Error message

malformed percentile value, provide a number between 0 and 100

What it means

The percentile value inside p(...) parsed as a float but is outside the valid range: it is NaN, negative, or greater than 100. Percentiles are interpreted as values between 0 and 100.

Source

Thrown at metrics/thresholds_parser.go:207

// it verbatim, as a string.
func parseThresholdAggregationMethod(input string) (string, null.Float, error) {
	// Is the input one of the methods keywords?
	for _, m := range aggregationMethodTokens {
		// Percentile expressions being of the form p(value),
		// they won't be matched here.
		if m == input {
			return m, null.Float{}, nil
		}
	}

	// Otherwise, attempt to parse a percentile expression
	if strings.HasPrefix(input, tokenPercentile+"(") && strings.HasSuffix(input, ")") {
		aggregationValue, err := strconv.ParseFloat(trimDelimited("p(", input, ")"), 64)
		if err != nil {
			return "", null.Float{}, fmt.Errorf("malformed percentile value; reason: %w", err)
		}
		if math.IsNaN(aggregationValue) || aggregationValue < 0 || aggregationValue > 100 {
			return "", null.Float{}, fmt.Errorf("malformed percentile value, provide a number between 0 and 100")
		}

		return tokenPercentile, null.FloatFrom(aggregationValue), nil
	}

	return "", null.Float{}, fmt.Errorf("failed parsing method from expression")
}

func trimDelimited(prefix, input, suffix string) string {
	return strings.TrimSuffix(strings.TrimPrefix(input, prefix), suffix)
}

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Use a percentile between 0 and 100 inclusive, e.g. p(90), p(95), p(99)
  2. For fractional percentiles keep them within range, e.g. p(99.9)
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at metrics/thresholds_parser.go:207 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


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