diff --git a/CHANGELOG.md b/CHANGELOG.md index a0c85fc820..da61dd9c44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ NOTE: As semantic versioning states all 0.y.z releases can contain breaking chan We use *breaking :warning:* to mark changes that are not backward compatible (relates only to v0.y.z releases.) ## Unreleased +- [#4970](https://github.com/thanos-io/thanos/pull/4970) Added a new flag `exclude-delete` to `tools bucket ls`, which excludes blocks marked for deletion. ### Added diff --git a/cmd/thanos/tools_bucket.go b/cmd/thanos/tools_bucket.go index b605b03b24..8e979db2d4 100644 --- a/cmd/thanos/tools_bucket.go +++ b/cmd/thanos/tools_bucket.go @@ -107,7 +107,8 @@ type bucketVerifyConfig struct { } type bucketLsConfig struct { - output string + output string + excludeDelete bool } type bucketWebConfig struct { @@ -168,6 +169,8 @@ func (tbc *bucketVerifyConfig) registerBucketVerifyFlag(cmd extkingpin.FlagClaus func (tbc *bucketLsConfig) registerBucketLsFlag(cmd extkingpin.FlagClause) *bucketLsConfig { cmd.Flag("output", "Optional format in which to print each block's information. Options are 'json', 'wide' or a custom template."). Short('o').Default("").StringVar(&tbc.output) + cmd.Flag("exclude-delete", "Exclude blocks marked for deletion."). + Default("false").BoolVar(&tbc.excludeDelete) return tbc } @@ -377,7 +380,13 @@ func registerBucketLs(app extkingpin.AppClause, objStoreConfig *extflag.PathOrCo return err } - fetcher, err := block.NewMetaFetcher(logger, block.FetcherConcurrency, bkt, "", extprom.WrapRegistererWithPrefix(extpromPrefix, reg), nil, nil) + var filters []block.MetadataFilter + + if tbc.excludeDelete { + ignoreDeletionMarkFilter := block.NewIgnoreDeletionMarkFilter(logger, bkt, 0, block.FetcherConcurrency) + filters = append(filters, ignoreDeletionMarkFilter) + } + fetcher, err := block.NewMetaFetcher(logger, block.FetcherConcurrency, bkt, "", extprom.WrapRegistererWithPrefix(extpromPrefix, reg), filters, nil) if err != nil { return err } diff --git a/docs/components/tools.md b/docs/components/tools.md index fe4f42b632..a5d33606d6 100644 --- a/docs/components/tools.md +++ b/docs/components/tools.md @@ -402,6 +402,7 @@ usage: thanos tools bucket ls [] List all blocks in the bucket. Flags: + --exclude-delete Exclude blocks marked for deletion. -h, --help Show context-sensitive help (also try --help-long and --help-man). --log.format=logfmt Log format to use. Possible options: logfmt or json.