grafana/k6 · error

trend stats resolver is empty

Error message

trend stats resolver is empty

What it means

newExtendedTrendSink is a guard that refuses to build an extended trend sink when the supplied TrendStatsResolver map is empty — no trend-stat resolver functions were provided, so trend values cannot be computed.

Source

Thrown at internal/output/prometheusrw/remotewrite/trend.go:26

	prompb "buf.build/gen/go/prometheus/prometheus/protocolbuffers/go"
	"github.com/prometheus/client_golang/prometheus"
	dto "github.com/prometheus/client_model/go"
	"go.k6.io/k6/v2/metrics"
)

// TrendStatsResolver is a map of trend stats name and their relative resolver function
type TrendStatsResolver map[string]func(*metrics.TrendSink) float64

type extendedTrendSink struct {
	*metrics.TrendSink

	trendStats map[string]func(*metrics.TrendSink) float64
}

func newExtendedTrendSink(tsr TrendStatsResolver) (*extendedTrendSink, error) {
	if len(tsr) < 1 {
		return nil, fmt.Errorf("trend stats resolver is empty")
	}
	return &extendedTrendSink{
		TrendSink:  metrics.NewTrendSink(),
		trendStats: tsr,
	}, nil
}

// MapPrompb converts a k6 time series and its relative
// Sink into the equivalent TimeSeries model as defined from
// the Remote write specification.
func (sink *extendedTrendSink) MapPrompb(series metrics.TimeSeries, t time.Time) []*prompb.TimeSeries {
	// Prometheus metric system does not support Trend so this mapping will
	// store a counter for the number of reported values and gauges to keep
	// track of aggregated values. Also store a sum of the values to allow
	// the calculation of moving averages.
	// TODO: when Prometheus implements support for sparse histograms, re-visit this implementation

	tg := &trendAsGauges{

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Provide at least one trend stat resolver entry when constructing the sink
  2. Check K6_PROMETHEUS_RW_TREND_STATS or native-histogram configuration isn't leaving stats empty
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/output/prometheusrw/remotewrite/trend.go:26 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/784cae47a42ed7f4. Report an issue: GitHub.