Skip to content

Commit

Permalink
tools:replicate: Allow configuring min and max compaction range via f…
Browse files Browse the repository at this point in the history
…lags

Signed-off-by: Philip Gough <[email protected]>
  • Loading branch information
philipgough committed Jul 31, 2023
1 parent 2606855 commit 6b757a8
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion cmd/thanos/tools_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ type bucketWebConfig struct {

type bucketReplicateConfig struct {
resolutions []time.Duration
compactMin int
compactMax int
compactions []int
matcherStrs string
singleRun bool
Expand Down Expand Up @@ -207,7 +209,11 @@ func (tbc *bucketWebConfig) registerBucketWebFlag(cmd extkingpin.FlagClause) *bu
func (tbc *bucketReplicateConfig) registerBucketReplicateFlag(cmd extkingpin.FlagClause) *bucketReplicateConfig {
cmd.Flag("resolution", "Only blocks with these resolutions will be replicated. Repeated flag.").Default("0s", "5m", "1h").HintAction(listResLevel).DurationListVar(&tbc.resolutions)

cmd.Flag("compaction", "Only blocks with these compaction levels will be replicated. Repeated flag.").Default("1", "2", "3", "4").IntsVar(&tbc.compactions)
cmd.Flag("compaction-min", "Only blocks with at least this compaction level will be replicated.").Default("1").IntVar(&tbc.compactMin)

cmd.Flag("compaction-max", "Only blocks up to a maximum of this compaction level will be replicated.").Default("4").IntVar(&tbc.compactMax)

cmd.Flag("compaction", "Only blocks with these compaction levels will be replicated. Repeated flag. Overrides compact-min and compact-max if set.").Default().IntsVar(&tbc.compactions)

cmd.Flag("matcher", "blocks whose external labels match this matcher will be replicated. All Prometheus matchers are supported, including =, !=, =~ and !~.").StringVar(&tbc.matcherStrs)

Expand Down Expand Up @@ -721,6 +727,16 @@ func registerBucketReplicate(app extkingpin.AppClause, objStoreConfig *extflag.P
resolutionLevels = append(resolutionLevels, compact.ResolutionLevel(lvl.Milliseconds()))
}

if len(tbc.compactions) == 0 {
if tbc.compactMin > tbc.compactMax {
return errors.New("compaction-min must be less than or equal to compaction-max")
}
tbc.compactions = []int{}
for compactionLevel := tbc.compactMin; compactionLevel <= tbc.compactMax; compactionLevel++ {
tbc.compactions = append(tbc.compactions, compactionLevel)
}
}

blockIDs := make([]ulid.ULID, 0, len(*ids))
for _, id := range *ids {
bid, err := ulid.Parse(id)
Expand Down

0 comments on commit 6b757a8

Please sign in to comment.