thanos-io/thanos · error

unexpected result aggregate type

Error message

unexpected result aggregate type %v

What it means

pkg/query's NewSeriesIterator builds a series iterator from storepb Series aggrs. When exactly one aggregate is requested but it is not COUNT or SUM (the only supported single-aggregates), the iterator returns errSeriesIterator with "unexpected result aggregate type %v". This indicates the store returned (or caller requested) an aggregate combination the query iterator cannot decode.

Solutions

  1. Ensure all store endpoints serve aggregates limited to COUNT/SUM for single-agg series, or upgrade them to a compatible Thanos version.
  2. Check the query's requested downsampling/aggregation selection; avoid requesting unsupported aggregates.
  3. Audit custom/proxy StoreAPI implementations to only return supported aggr sets.
  4. Pin query and store components to matching versions so Aggr enums align.

Example fix

// before (store side returning unsupported agg)
return &storepb.Series{Aggrs: []storepb.Aggr{storepb.Aggr_AVG}, Chunks: chunks}, nil

// after
return &storepb.Series{Aggrs: []storepb.Aggr{storepb.Aggr_COUNT, storepb.Aggr_SUM}, Chunks: chunks}, nil
Defensive patterns

Strategy: validation

Validate before calling

// store-side check before sending Series
if len(aggrs) == 1 && aggrs[0] != storepb.Aggr_COUNT && aggrs[0] != storepb.Aggr_SUM {
	return status.Errorf(codes.InvalidArgument, "unsupported single aggregate %v", aggrs[0])
}

Type guard

func supportedSingleAggrs(aggrs []storepb.Aggr) bool {
	return len(aggrs) != 1 || aggrs[0] == storepb.Aggr_COUNT || aggrs[0] == storepb.Aggr_SUM
}

Prevention

When it happens

Trigger: In Iterator(): len(s.aggrs)==1 and s.aggrs[0] is neither storepb.Aggr_COUNT nor storepb.Aggr_SUM (e.g. Aggr_COUNTER or Aggr_AVG requested/returned) — first default branch of the switch over single-aggregate series.

Common situations: A storeAPI implementation (custom/proxy store) returning unsupported aggregates; query fan-out against a store that ignores the requested agg selection; version mismatch between query frontend and store returning newer aggregate types.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of thanos-io/thanos@35b8b99117 (2026-09-07). Data as JSON: /api/errors/53507553a7fa83dd. Report an issue: GitHub.

Appendix: source

Thrown at pkg/query/iter.go:145

			sit = newChunkSeriesIterator(its)
		case storepb.Aggr_MIN:
			for _, c := range s.chunks {
				its = append(its, getFirstIterator(c.Min, c.Raw))
			}
			sit = newChunkSeriesIterator(its)
		case storepb.Aggr_MAX:
			for _, c := range s.chunks {
				its = append(its, getFirstIterator(c.Max, c.Raw))
			}
			sit = newChunkSeriesIterator(its)
		case storepb.Aggr_COUNTER:
			for _, c := range s.chunks {
				its = append(its, getFirstIterator(c.Counter, c.Raw))
			}
			// TODO(bwplotka): This breaks resets function. See https://github.com/thanos-io/thanos/issues/3644
			sit = downsample.NewApplyCounterResetsIterator(its...)
		default:
			return errSeriesIterator{err: errors.Errorf("unexpected result aggregate type %v", s.aggrs)}
		}
		return dedup.NewBoundedSeriesIterator(sit, s.mint, s.maxt)
	}

	if len(s.aggrs) != 2 {
		return errSeriesIterator{err: errors.Errorf("unexpected result aggregate type %v", s.aggrs)}
	}

	switch {
	case s.aggrs[0] == storepb.Aggr_SUM && s.aggrs[1] == storepb.Aggr_COUNT,
		s.aggrs[0] == storepb.Aggr_COUNT && s.aggrs[1] == storepb.Aggr_SUM:

		for _, c := range s.chunks {
			if c.Raw != nil {
				its = append(its, getFirstIterator(c.Raw))
			} else {
				sum, cnt := getFirstIterator(c.Sum), getFirstIterator(c.Count)
				its = append(its, downsample.NewAverageChunkIterator(cnt, sum))

View on GitHub (pinned to 35b8b99117)