{"record":{"id":"53507553a7fa83dd","repo":"thanos-io/thanos","slug":"unexpected-result-aggregate-type-v","errorCode":null,"errorMessage":"unexpected result aggregate type %v","messagePattern":"unexpected result aggregate type (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/query/iter.go","lineNumber":145,"sourceCode":"\t\t\tsit = newChunkSeriesIterator(its)\n\t\tcase storepb.Aggr_MIN:\n\t\t\tfor _, c := range s.chunks {\n\t\t\t\tits = append(its, getFirstIterator(c.Min, c.Raw))\n\t\t\t}\n\t\t\tsit = newChunkSeriesIterator(its)\n\t\tcase storepb.Aggr_MAX:\n\t\t\tfor _, c := range s.chunks {\n\t\t\t\tits = append(its, getFirstIterator(c.Max, c.Raw))\n\t\t\t}\n\t\t\tsit = newChunkSeriesIterator(its)\n\t\tcase storepb.Aggr_COUNTER:\n\t\t\tfor _, c := range s.chunks {\n\t\t\t\tits = append(its, getFirstIterator(c.Counter, c.Raw))\n\t\t\t}\n\t\t\t// TODO(bwplotka): This breaks resets function. See https://github.com/thanos-io/thanos/issues/3644\n\t\t\tsit = downsample.NewApplyCounterResetsIterator(its...)\n\t\tdefault:\n\t\t\treturn errSeriesIterator{err: errors.Errorf(\"unexpected result aggregate type %v\", s.aggrs)}\n\t\t}\n\t\treturn dedup.NewBoundedSeriesIterator(sit, s.mint, s.maxt)\n\t}\n\n\tif len(s.aggrs) != 2 {\n\t\treturn errSeriesIterator{err: errors.Errorf(\"unexpected result aggregate type %v\", s.aggrs)}\n\t}\n\n\tswitch {\n\tcase s.aggrs[0] == storepb.Aggr_SUM && s.aggrs[1] == storepb.Aggr_COUNT,\n\t\ts.aggrs[0] == storepb.Aggr_COUNT && s.aggrs[1] == storepb.Aggr_SUM:\n\n\t\tfor _, c := range s.chunks {\n\t\t\tif c.Raw != nil {\n\t\t\t\tits = append(its, getFirstIterator(c.Raw))\n\t\t\t} else {\n\t\t\t\tsum, cnt := getFirstIterator(c.Sum), getFirstIterator(c.Count)\n\t\t\t\tits = append(its, downsample.NewAverageChunkIterator(cnt, sum))","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/query/iter.go#L127-L163","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure all store endpoints serve aggregates limited to COUNT/SUM for single-agg series, or upgrade them to a compatible Thanos version.","Check the query's requested downsampling/aggregation selection; avoid requesting unsupported aggregates.","Audit custom/proxy StoreAPI implementations to only return supported aggr sets.","Pin query and store components to matching versions so Aggr enums align."],"exampleFix":"// before (store side returning unsupported agg)\nreturn &storepb.Series{Aggrs: []storepb.Aggr{storepb.Aggr_AVG}, Chunks: chunks}, nil\n\n// after\nreturn &storepb.Series{Aggrs: []storepb.Aggr{storepb.Aggr_COUNT, storepb.Aggr_SUM}, Chunks: chunks}, nil","handlingStrategy":"validation","validationCode":"// store-side check before sending Series\nif len(aggrs) == 1 && aggrs[0] != storepb.Aggr_COUNT && aggrs[0] != storepb.Aggr_SUM {\n\treturn status.Errorf(codes.InvalidArgument, \"unsupported single aggregate %v\", aggrs[0])\n}","typeGuard":"func supportedSingleAggrs(aggrs []storepb.Aggr) bool {\n\treturn len(aggrs) != 1 || aggrs[0] == storepb.Aggr_COUNT || aggrs[0] == storepb.Aggr_SUM\n}","tryCatchPattern":null,"preventionTips":["Keep querier and store components on compatible Thanos versions","Test custom StoreAPI implementations against the query iterator contract","Never emit aggregates beyond COUNT/SUM for single-aggregate series"],"tags":["thanos","query","iterator","protocol"],"backgroundTag":"invalid-enum-value","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}