grafana/k6 · error

malformed percentile value; reason: %w

Error message

malformed percentile value; reason: %w

What it means

Inside parseThresholdAggregationMethod, the value inside a percentile expression p(...) could not be parsed as a float64 by strconv.ParseFloat. The delimiters p( and ) matched, but the inner text is not a number (empty, NaN-like text, or garbage).

Source

Thrown at metrics/thresholds_parser.go:204

// It assumes the provided input argument is already trimmed and cleaned up.
// If it encounters a percentile method, it will parse it and verify it
// boils down to an expression of the form: `p(float64)`, but will return
// 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. Write the percentile as p(<number>), e.g. p(95), p(99.9)
  2. Remove spaces or units inside the parentheses
  3. Do not use NaN or expressions — only a literal number
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at metrics/thresholds_parser.go:204 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/d7ba18ff6cd902c3. Report an issue: GitHub.