{"record":{"id":"52d562f3ac08a268","repo":"thanos-io/thanos","slug":"could-not-calculate-retention-progress","errorCode":null,"errorMessage":"could not calculate retention progress","messagePattern":"could not calculate retention progress","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/thanos/compact.go","lineNumber":679,"sourceCode":"\t\t\t\t\t}\n\n\t\t\t\t\tmetas := sy.Metas()\n\t\t\t\t\tgroups, err := grouper.Groups(metas)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn errors.Wrapf(err, \"could not group metadata for compaction\")\n\t\t\t\t\t}\n\n\t\t\t\t\tif err = ps.ProgressCalculate(ctx, groups); err != nil {\n\t\t\t\t\t\treturn errors.Wrapf(err, \"could not calculate compaction progress\")\n\t\t\t\t\t}\n\n\t\t\t\t\tretGroups, err := grouper.Groups(metas)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn errors.Wrapf(err, \"could not group metadata for retention\")\n\t\t\t\t\t}\n\n\t\t\t\t\tif err = rs.ProgressCalculate(ctx, retGroups); err != nil {\n\t\t\t\t\t\treturn errors.Wrapf(err, \"could not calculate retention progress\")\n\t\t\t\t\t}\n\n\t\t\t\t\tif !conf.disableDownsampling {\n\t\t\t\t\t\tgroups, err = grouper.Groups(metas)\n\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\treturn errors.Wrapf(err, \"could not group metadata into downsample groups\")\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif err := ds.ProgressCalculate(ctx, groups); err != nil {\n\t\t\t\t\t\t\treturn errors.Wrapf(err, \"could not calculate downsampling progress\")\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\treturn nil\n\t\t\t\t})\n\t\t\t}, func(err error) {\n\t\t\t\tcancel()\n\t\t\t})\n\t\t}","sourceCodeStart":661,"sourceCodeEnd":697,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/cmd/thanos/compact.go#L661-L697","documentation":"rs.ProgressCalculate(ctx, retGroups) runs the RetentionProgressCalculator, which estimates how many blocks would be deleted by the configured retention policy per resolution. Failures are wrapped as 'could not calculate retention progress'. It is a metrics-only step in the periodic progress worker.","triggerScenarios":"The retention calculator errors while applying retentionByResolution to the groups — typically when ctx is cancelled (shutdown) or when group/block state is inconsistent from earlier metadata problems.","commonSituations":"Most often seen as 'context canceled' during compactor shutdown while the progress loop is mid-calculation; also after bad grouping state caused by duplicate blocks.","solutions":["If the inner error is 'context canceled', ignore it — it happens during graceful shutdown; check shutdown ordering in run.Group.","Inspect the wrapped error for the failing group and validate block metadata with 'thanos tools bucket inspect'.","Confirm retention flag values (--retention-resolution-raw etc.) parse as valid durations; fix invalid retention configuration.","Upgrade Thanos if the calculator errors on valid groups."],"exampleFix":"// before\n--retention-resolution-raw=14d --retention-resolution-5m=bd    # invalid duration\n// after\n--retention-resolution-raw=14d --retention-resolution-5m=1s    # or omit 5m retention","handlingStrategy":"try-catch","validationCode":"// Validate retention flags parse as durations before wiring the calculator\nfor _, d := range []string{rawRetention, res5mRetention, res1hRetention} {\n    if _, err := time.ParseDuration(d); err != nil {\n        log.Fatalf(\"invalid retention duration %q\", d)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := rs.ProgressCalculate(ctx, retGroups); err != nil {\n    if ctx.Err() != nil {\n        return nil // graceful shutdown\n    }\n    log.Errorf(\"could not calculate retention progress: %v\", err)\n    return nil\n}","preventionTips":["Pass retention flags as valid Go durations (e.g. 14d handled by Thanos, otherwise 336h).","Ignore 'context canceled' during shutdown — it's expected.","Fix grouping issues upstream before retention calculation.","Keep retention config in one reviewed place (YAML where available)."],"tags":["thanos","retention","metrics"],"backgroundTag":"invalid-config-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"}