thanos-io/thanos · error
get compaction levels
Error message
get compaction levels
What it means
Wraps errors.Errorf returned by compactionSet.levels when --max-compaction-level exceeds the configured compaction level set (see error 0). runCompact adds this context so the operator knows the compaction-level flag is the problem.
Solutions
- Set --max-compaction-level to a valid value (e.g. 2 for the default 3-level set).
- Remove the --max-compaction-level flag to accept defaults.
- If a higher level is genuinely needed, upgrade Thanos / use a build with a larger default level set.
Example fix
// before thanos compact --max-compaction-level=4 ... // after thanos compact --max-compaction-level=2 ...
Defensive patterns
Strategy: validation
Validate before calling
if maxCompactionLevel < 0 || maxCompactionLevel >= len(thanos.CompactionLevels) {
return fmt.Errorf("--max-compaction-level out of range: %d", maxCompactionLevel)
} Prevention
- Default to omitting --max-compaction-level; add it only with a documented reason
- Clamp operator-supplied values in your config generation layer
When it happens
Trigger: runCompact with conf.maxCompactionLevel >= len(compactions), i.e. --max-compaction-level set to 4 or higher than the number of default levels.
Common situations: Operators misreading the flag as an absolute TSDB level (e.g. setting 4 to "allow level-4 blocks") instead of an index bound.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- level is bigger then default set of
- unknown sync strategy
- penalty based deduplication needs at least one replica…
- unrecognized label
- unsupported format for label
AI-assisted analysis of thanos-io/thanos@35b8b99117 (2026-09-07).
Data as JSON: /api/errors/338a43369baa654f.
Report an issue: GitHub.
Appendix: source
Thrown at cmd/thanos/compact.go:312
sy, err = compact.NewMetaSyncer(
logger,
reg,
insBkt,
cf,
duplicateBlocksFilter,
ignoreDeletionMarkFilter,
compactMetrics.blocksMarked.WithLabelValues(metadata.DeletionMarkFilename, ""),
compactMetrics.garbageCollectedBlocks,
syncMetasTimeout,
)
if err != nil {
return errors.Wrap(err, "create syncer")
}
}
levels, err := compactions.levels(conf.maxCompactionLevel)
if err != nil {
return errors.Wrap(err, "get compaction levels")
}
if conf.maxCompactionLevel < compactions.maxLevel() {
level.Warn(logger).Log("msg", "Max compaction level is lower than should be", "current", conf.maxCompactionLevel, "default", compactions.maxLevel())
}
ctx, cancel := context.WithCancel(context.Background())
ctx = tracing.ContextWithTracer(ctx, tracer)
defer func() {
if rerr != nil {
cancel()
}
}()
var mergeFunc storage.VerticalChunkSeriesMergeFunc
switch conf.dedupFunc {
case compact.DedupAlgorithmPenalty:View on GitHub (pinned to 35b8b99117)