diff --git a/CHANGELOG.md b/CHANGELOG.md index abd540da48..896cc8d89d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re - [#4868](https://github.com/thanos-io/thanos/pull/4868) Rule: Support ruleGroup limit introduced by Prometheus v2.31.0. - [#4897](https://github.com/thanos-io/thanos/pull/4897) Querier: Add validation for querier address flags. - [#4903](https://github.com/thanos-io/thanos/pull/4903) Compactor: Added tracing support for compaction. +- [#4909](https://github.com/thanos-io/thanos/pull/4909) Compactor: Add flag --max-time / --min-time to filter blocks that are ready to be compacted. ### Fixed diff --git a/cmd/thanos/compact.go b/cmd/thanos/compact.go index ce24c7e486..13d6da56e2 100644 --- a/cmd/thanos/compact.go +++ b/cmd/thanos/compact.go @@ -42,6 +42,7 @@ import ( "github.com/thanos-io/thanos/pkg/prober" "github.com/thanos-io/thanos/pkg/runutil" httpserver "github.com/thanos-io/thanos/pkg/server/http" + "github.com/thanos-io/thanos/pkg/store" "github.com/thanos-io/thanos/pkg/tracing" "github.com/thanos-io/thanos/pkg/ui" ) @@ -231,6 +232,7 @@ func runCompact( noCompactMarkerFilter := compact.NewGatherNoCompactionMarkFilter(logger, bkt, conf.blockMetaFetchConcurrency) labelShardedMetaFilter := block.NewLabelShardedMetaFilter(relabelConfig) consistencyDelayMetaFilter := block.NewConsistencyDelayMetaFilter(logger, conf.consistencyDelay, extprom.WrapRegistererWithPrefix("thanos_", reg)) + timePartitionMetaFilter := block.NewTimePartitionMetaFilter(conf.filterConf.MinTime, conf.filterConf.MaxTime) baseMetaFetcher, err := block.NewBaseFetcher(logger, conf.blockMetaFetchConcurrency, bkt, "", extprom.WrapRegistererWithPrefix("thanos_", reg)) if err != nil { @@ -270,6 +272,7 @@ func runCompact( ignoreDeletionMarkFilter, duplicateBlocksFilter, noCompactMarkerFilter, + timePartitionMetaFilter, }, []block.MetadataModifier{block.NewReplicaLabelRemover(logger, conf.dedupReplicaLabels)}, ) cf.UpdateOnChange(func(blocks []metadata.Meta, err error) { @@ -646,6 +649,7 @@ type compactConfig struct { dedupFunc string skipBlockWithOutOfOrderChunks bool progressCalculateInterval time.Duration + filterConf *store.FilterConfig } func (cc *compactConfig) registerFlag(cmd extkingpin.FlagClause) { @@ -739,6 +743,12 @@ func (cc *compactConfig) registerFlag(cmd extkingpin.FlagClause) { cmd.Flag("hash-func", "Specify which hash function to use when calculating the hashes of produced files. If no function has been specified, it does not happen. This permits avoiding downloading some files twice albeit at some performance cost. Possible values are: \"\", \"SHA256\"."). Default("").EnumVar(&cc.hashFunc, "SHA256", "") + cc.filterConf = &store.FilterConfig{} + cmd.Flag("min-time", "Start of time range limit to compact. Thanos Compactor will compact only blocks, which happened later than this value. Option can be a constant time in RFC3339 format or time duration relative to current time, such as -1d or 2h45m. Valid duration units are ms, s, m, h, d, w, y."). + Default("0000-01-01T00:00:00Z").SetValue(&cc.filterConf.MinTime) + cmd.Flag("max-time", "End of time range limit to compact. Thanos Compactor will compact only blocks, which happened earlier than this value. Option can be a constant time in RFC3339 format or time duration relative to current time, such as -1d or 2h45m. Valid duration units are ms, s, m, h, d, w, y."). + Default("9999-12-31T23:59:59Z").SetValue(&cc.filterConf.MaxTime) + cc.selectorRelabelConf = *extkingpin.RegisterSelectorRelabelFlags(cmd) cc.webConf.registerFlag(cmd) diff --git a/docs/components/compact.md b/docs/components/compact.md index c90cbe522d..d5ffad27c4 100644 --- a/docs/components/compact.md +++ b/docs/components/compact.md @@ -372,6 +372,21 @@ Flags: --log.format=logfmt Log format to use. Possible options: logfmt or json. --log.level=info Log filtering level. + --max-time=9999-12-31T23:59:59Z + End of time range limit to compact. Thanos + Compactor will compact only blocks, which + happened earlier than this value. Option can be + a constant time in RFC3339 format or time + duration relative to current time, such as -1d + or 2h45m. Valid duration units are ms, s, m, h, + d, w, y. + --min-time=0000-01-01T00:00:00Z + Start of time range limit to compact. Thanos + Compactor will compact only blocks, which + happened later than this value. Option can be a + constant time in RFC3339 format or time duration + relative to current time, such as -1d or 2h45m. + Valid duration units are ms, s, m, h, d, w, y. --objstore.config= Alternative to 'objstore.config-file' flag (mutually exclusive). Content of YAML file that