Skip to content

Commit

Permalink
Move retention at the start of the compactor loop.
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Biesmans <[email protected]>
  • Loading branch information
Olivier Biesmans committed Jan 28, 2020
1 parent 51d584e commit ba8e2d9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ We use *breaking* word for marking changes that are not backward compatible (rel
### Added
- [#1852](https://github.com/thanos-io/thanos/pull/1852) Add support for `AWS_CONTAINER_CREDENTIALS_FULL_URI` by upgrading to minio-go v6.0.44
- [#1854](https://github.com/thanos-io/thanos/pull/1854) Update Rule UI to support alerts count displaying and filtering.
- [#1735](https://github.com/thanos-io/thanos/pull/1735) Retention policies are now applied at the start of the compactor loop. Retentions policies that break downsampling are now logged as warnings.

## [v0.9.0](https://github.com/thanos-io/thanos/releases/tag/v0.9.0) - 2019.12.03

Expand Down
21 changes: 20 additions & 1 deletion cmd/thanos/compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,17 +266,35 @@ func runCompact(
return errors.Wrap(err, "create bucket compactor")
}

if retentionByResolution[compact.ResolutionLevelRaw].Seconds() != 0 {
if gretentionByResolution[compact.ResolutionLevelRaw].Seconds() != 0 {
level.Info(logger).Log("msg", "retention policy of raw samples is enabled", "duration", retentionByResolution[compact.ResolutionLevelRaw])
if retentionByResolution[compact.ResolutionLevelRaw].Seconds() <= downsample.DownsampleRange0 {
level.Warn(logger).Log("msg", "retention policy of raw samples is too low to generate 5 min aggregated samples", "duration", retentionByResolution[compact.ResolutionLevelRaw])
}
}
if retentionByResolution[compact.ResolutionLevel5m].Seconds() != 0 {
level.Info(logger).Log("msg", "retention policy of 5 min aggregated samples is enabled", "duration", retentionByResolution[compact.ResolutionLevel5m])
if retentionByResolution[compact.ResolutionLevel5m].Seconds() <= downsample.DownsampleRange1 {
level.Warn(logger).Log("msg", "retention policy of 5 min aggregated samples is too low to generate 1h aggregated samples", "duration", retentionByResolution[compact.ResolutionLevel5m])
}
}
if retentionByResolution[compact.ResolutionLevel1h].Seconds() != 0 {
level.Info(logger).Log("msg", "retention policy of 1 hour aggregated samples is enabled", "duration", retentionByResolution[compact.ResolutionLevel1h])
}

f := func() error {
// At first, we need at least to be able to genetes 1h resolution metrics
// from the lower resolutions, so remove only up to 1h resolution retention.
initialRetention := map[compact.ResolutionLevel]time.Duration{
compact.ResolutionLevelRaw: initialRetention[compact.ResolutionLevel1h],
compact.ResolutionLevel5m: initialRetention[compact.ResolutionLevel1h],
compact.ResolutionLevel1h: initialRetention[compact.ResolutionLevel1h],
}

if err := compact.ApplyRetentionPolicyByResolution(ctx, logger, bkt, initialRetention); err != nil {
return errors.Wrap(err, fmt.Sprintf("retention failed"))
}

if err := compactor.Compact(ctx); err != nil {
return errors.Wrap(err, "compaction failed")
}
Expand Down Expand Up @@ -306,6 +324,7 @@ func runCompact(
if err := compact.ApplyRetentionPolicyByResolution(ctx, logger, bkt, retentionByResolution); err != nil {
return errors.Wrap(err, fmt.Sprintf("retention failed"))
}

return nil
}

Expand Down

0 comments on commit ba8e2d9

Please sign in to comment.