Skip to content

Commit

Permalink
copyblocks: add option to bypass duration check for no-compact blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
andyasp committed Sep 26, 2024
1 parent 62cdd31 commit afb5414
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@
* [ENHANCEMENT] `tsdb-series`: Added `-min-time` and `-max-time` options to filter samples that are used for computing data-points per minute. #8844
* [ENHANCEMENT] `mimir-rules-action`: Added new input to support matching target namespaces by regex. #9244
* [ENHANCEMENT] `mimir-rules-action`: Added new inputs to support ignoring namespaces and ignoring namespaces by regex. #9258 #9324
* [ENHANCEMENT] `copyblocks`: Added `--any-no-compact-block-duration`, which defaults to `false`, to simplify targeting blocks that are not awaiting compaction. #9439
* [BUGFIX] `copyblocks`, `undelete-blocks`, `copyprefix`: use a multipart upload to server-side copy objects greater than 5GiB in size on S3. #9357

## 2.13.0
Expand Down
2 changes: 1 addition & 1 deletion tools/copyblocks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The currently supported services are Amazon Simple Storage Service (S3 and S3-co
- Prevents copying blocks multiple times to the same destination bucket by uploading block marker files to the source bucket
- Runs continuously with periodic checks when supplied a time duration with `--copy-period`, otherwise runs one check then exits
- Include or exclude users from having blocks copied (`--enabled-users` and `--disabled-users`)
- Configurable minimum block duration (`--min-block-duration`) to avoid copying blocks that will be compacted
- Configurable minimum block duration (`--min-block-duration`) and (`--any-no-compact-block-duration`) to target blocks that are not awaiting compaction
- Configurable time range (`--min-time` and `--max-time`) to only copy blocks inclusively within a provided range
- Log what would be copied without actually copying anything with `--dry-run`

Expand Down
27 changes: 15 additions & 12 deletions tools/copyblocks/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,18 @@ import (
)

type config struct {
copyConfig objtools.CopyBucketConfig
minBlockDuration time.Duration
minTime flagext.Time
maxTime flagext.Time
tenantConcurrency int
blockConcurrency int
copyPeriod time.Duration
enabledUsers flagext.StringSliceCSV
disabledUsers flagext.StringSliceCSV
dryRun bool
httpListen string
copyConfig objtools.CopyBucketConfig
minBlockDuration time.Duration
minTime flagext.Time
maxTime flagext.Time
tenantConcurrency int
blockConcurrency int
copyPeriod time.Duration
enabledUsers flagext.StringSliceCSV
disabledUsers flagext.StringSliceCSV
dryRun bool
anyNoCompactBlockDuration bool
httpListen string
}

func (c *config) registerFlags(f *flag.FlagSet) {
Expand All @@ -59,6 +60,7 @@ func (c *config) registerFlags(f *flag.FlagSet) {
f.Var(&c.enabledUsers, "enabled-users", "If not empty, only blocks for these users are copied.")
f.Var(&c.disabledUsers, "disabled-users", "If not empty, blocks for these users are not copied.")
f.BoolVar(&c.dryRun, "dry-run", false, "Don't perform any copy; only log what would happen.")
f.BoolVar(&c.anyNoCompactBlockDuration, "any-no-compact-block-duration", false, "If set, blocks marked as no-compact are not checked against min-block-duration")
f.StringVar(&c.httpListen, "http-listen-address", ":8080", "HTTP listen address.")
}

Expand Down Expand Up @@ -269,7 +271,8 @@ func copyBlocks(ctx context.Context, cfg config, logger log.Logger, m *metrics)
return nil
}

if cfg.minBlockDuration > 0 {
skipDurationCheck := cfg.anyNoCompactBlockDuration && markers[blockID].noCompact
if !skipDurationCheck && cfg.minBlockDuration > 0 {
blockDuration := time.Millisecond * time.Duration(blockMeta.MaxTime-blockMeta.MinTime)
if blockDuration < cfg.minBlockDuration {
level.Debug(logger).Log("msg", "skipping block, block duration is less than the configured minimum duration", "block_duration", blockDuration, "configured_min_duration", cfg.minBlockDuration)
Expand Down

0 comments on commit afb5414

Please sign in to comment.