diff --git a/CHANGELOG.md b/CHANGELOG.md index e4c8a2304cd..0ff39814874 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re ### Added +- [#7293](https://github.com/thanos-io/thanos/pull/7293) Compact: Add validation to --min-time and --max-time flags - [#7231](https://github.com/thanos-io/thanos/pull/7231) Tracing: added missing sampler types - [#7194](https://github.com/thanos-io/thanos/pull/7194) Downsample: retry objstore related errors - [#7105](https://github.com/thanos-io/thanos/pull/7105) Rule: add flag `--query.enable-x-functions` to allow usage of extended promql functions (xrate, xincrease, xdelta) in loaded rules diff --git a/cmd/thanos/compact.go b/cmd/thanos/compact.go index f1437efc645..ce5484fe19a 100644 --- a/cmd/thanos/compact.go +++ b/cmd/thanos/compact.go @@ -228,6 +228,10 @@ func runCompact( } }() + if err := validateFilterConf(conf.filterConf); err != nil { + return fmt.Errorf("invalid time filters: %s", err.Error()) + } + // While fetching blocks, we filter out blocks that were marked for deletion by using IgnoreDeletionMarkFilter. // The delay of deleteDelay/2 is added to ensure we fetch blocks that are meant to be deleted but do not have a replacement yet. // This is to make sure compactor will not accidentally perform compactions with gap instead. @@ -689,6 +693,27 @@ func runCompact( return nil } +func validateFilterConf(filterConf *store.FilterConfig) error { + if filterConf.MinTime.PrometheusTimestamp() > filterConf.MaxTime.PrometheusTimestamp() { + return errors.New("max time must be a time or duration after min time") + } + + if err := checkIfDurInFuture(filterConf.MinTime.Dur); err != nil { + return fmt.Errorf("min time: %s", err.Error()) + } + return nil +} + +func checkIfDurInFuture(dur *model.Duration) error { + if dur == nil { + return nil + } + if !strings.HasPrefix("-", dur.String()) { + return errors.New("duration cannot be in the future") + } + return nil +} + type compactConfig struct { haltOnError bool acceptMalformedIndex bool @@ -823,9 +848,9 @@ func (cc *compactConfig) registerFlag(cmd extkingpin.FlagClause) { 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."). + cmd.Flag("min-time", "Start of time range limit to compact. Thanos Compactor will only compact blocks whose max time is at a date more recent than this value. Option can be a constant time in RFC3339 format or time duration relative to current time, such as -1d or -2h45m. Durations must be negative, and valid 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."). + cmd.Flag("max-time", "End of time range limit to compact. Thanos Compactor will only compact blocks whose min time is at a date less recent this value. Option can be a constant time in RFC3339 format or time duration relative to current time, such as -1d or -2h45m. Valid units for duration are ms, s, m, h, d, w, y."). Default("9999-12-31T23:59:59Z").SetValue(&cc.filterConf.MaxTime) cmd.Flag("web.disable", "Disable Block Viewer UI.").Default("false").BoolVar(&cc.disableWeb) diff --git a/docs/components/compact.md b/docs/components/compact.md index aa47143a257..ddf57e1f3d9 100644 --- a/docs/components/compact.md +++ b/docs/components/compact.md @@ -251,7 +251,13 @@ Generally there two scalability directions: 1. Too many producers/sources (e.g Prometheus-es) are uploading to same object storage. Too many "streams" of work for Compactor. Compactor has to scale with the number of producers in the bucket. -You should horizontally scale Compactor to cope with this using [label sharding](../sharding.md#compactor). This allows to assign multiple streams to each instance of compactor. +You can horizontally scale Compactor to cope with this via +- [label sharding](../sharding.md#compactor): This allows to assign multiple streams to each instance of compactor. +- [time sharding](../sharding.md#compactor): This allows for compactors to only handle blocks that fall within a given time range + +For example, to have an instance of compactor only working on blocks that fall within the time range of 14 days ago to 7 days ago, the flags would be `--min-time=-14d --max-time=-7d` + +Absolute times can be specified as well. 2. TSDB blocks from single stream is too big, it takes too much time or resources. @@ -399,20 +405,21 @@ Flags: 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 + End of time range limit to compact. Thanos + Compactor will only compact blocks whose min + time is at a date less recent 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. + or -2h45m. Valid units for duration 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. + Start of time range limit to compact. Thanos + Compactor will only compact blocks whose max + time is at a date more recent than this value. + Option can be a constant time in RFC3339 format + or time duration relative to current time, such + as -1d or -2h45m. Durations must be negative, + and valid units are ms, s, m, h, d, w, y. --objstore.config= Alternative to 'objstore.config-file' flag (mutually exclusive). Content of