Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compact: Add compactor time validation #7293

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
29 changes: 27 additions & 2 deletions cmd/thanos/compact.go
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
31 changes: 19 additions & 12 deletions docs/components/compact.md
Expand Up @@ -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.

Expand Down Expand Up @@ -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=<content>
Alternative to 'objstore.config-file'
flag (mutually exclusive). Content of
Expand Down