Skip to content

Commit 2a5a856

Browse files
tools: Extend bucket ls options (#8225)
* tools: Extend bucket ls command with min and max time, selector config and timeout options Signed-off-by: Philip Gough <[email protected]> * make: docs Signed-off-by: Philip Gough <[email protected]> Update cmd/thanos/tools_bucket.go Co-authored-by: Saswata Mukherjee <[email protected]> Signed-off-by: Philip Gough <[email protected]> Update cmd/thanos/tools_bucket.go Co-authored-by: Saswata Mukherjee <[email protected]> Signed-off-by: Philip Gough <[email protected]> --------- Signed-off-by: Philip Gough <[email protected]> Signed-off-by: Philip Gough <[email protected]> Co-authored-by: Saswata Mukherjee <[email protected]>
1 parent cff147d commit 2a5a856

File tree

3 files changed

+64
-4
lines changed

3 files changed

+64
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
1111
## Unreleased
1212
- [#8190](https://github.com/thanos-io/thanos/pull/8190) Fix markdown formatting in CHANGELOG.
1313
- [#8202](https://github.com/thanos-io/thanos/pull/8202) Receive: Unhide `--tsdb.enable-native-histograms` flag
14+
- [#8225](https://github.com/thanos-io/thanos/pull/8225) tools: Extend bucket ls options.
1415

1516
### Added
1617

cmd/thanos/tools_bucket.go

+33-4
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,11 @@ type bucketVerifyConfig struct {
110110
}
111111

112112
type bucketLsConfig struct {
113-
output string
114-
excludeDelete bool
113+
output string
114+
excludeDelete bool
115+
selectorRelabelConf extflag.PathOrContent
116+
filterConf *store.FilterConfig
117+
timeout time.Duration
115118
}
116119

117120
type bucketWebConfig struct {
@@ -181,10 +184,18 @@ func (tbc *bucketVerifyConfig) registerBucketVerifyFlag(cmd extkingpin.FlagClaus
181184
}
182185

183186
func (tbc *bucketLsConfig) registerBucketLsFlag(cmd extkingpin.FlagClause) *bucketLsConfig {
187+
tbc.selectorRelabelConf = *extkingpin.RegisterSelectorRelabelFlags(cmd)
188+
tbc.filterConf = &store.FilterConfig{}
189+
184190
cmd.Flag("output", "Optional format in which to print each block's information. Options are 'json', 'wide' or a custom template.").
185191
Short('o').Default("").StringVar(&tbc.output)
186192
cmd.Flag("exclude-delete", "Exclude blocks marked for deletion.").
187193
Default("false").BoolVar(&tbc.excludeDelete)
194+
cmd.Flag("min-time", "Start of time range limit to list blocks. Thanos Tools will list blocks, which were created 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.").
195+
Default("0000-01-01T00:00:00Z").SetValue(&tbc.filterConf.MinTime)
196+
cmd.Flag("max-time", "End of time range limit to list. Thanos Tools will list only blocks, which were created 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.").
197+
Default("9999-12-31T23:59:59Z").SetValue(&tbc.filterConf.MaxTime)
198+
cmd.Flag("timeout", "Timeout to download metadata from remote storage").Default("5m").DurationVar(&tbc.timeout)
188199
return tbc
189200
}
190201

@@ -418,12 +429,30 @@ func registerBucketLs(app extkingpin.AppClause, objStoreConfig *extflag.PathOrCo
418429
}
419430
insBkt := objstoretracing.WrapWithTraces(objstore.WrapWithMetrics(bkt, extprom.WrapRegistererWithPrefix("thanos_", reg), bkt.Name()))
420431

421-
var filters []block.MetadataFilter
432+
if tbc.timeout < time.Minute {
433+
level.Warn(logger).Log("msg", "Timeout less than 1m could lead to frequent failures")
434+
}
435+
436+
relabelContentYaml, err := tbc.selectorRelabelConf.Content()
437+
if err != nil {
438+
return errors.Wrap(err, "get content of relabel configuration")
439+
}
440+
441+
relabelConfig, err := block.ParseRelabelConfig(relabelContentYaml, block.SelectorSupportedRelabelActions)
442+
if err != nil {
443+
return err
444+
}
445+
446+
filters := []block.MetadataFilter{
447+
block.NewLabelShardedMetaFilter(relabelConfig),
448+
block.NewTimePartitionMetaFilter(tbc.filterConf.MinTime, tbc.filterConf.MaxTime),
449+
}
422450

423451
if tbc.excludeDelete {
424452
ignoreDeletionMarkFilter := block.NewIgnoreDeletionMarkFilter(logger, insBkt, 0, block.FetcherConcurrency)
425453
filters = append(filters, ignoreDeletionMarkFilter)
426454
}
455+
427456
baseBlockIDsFetcher := block.NewConcurrentLister(logger, insBkt)
428457
fetcher, err := block.NewMetaFetcher(logger, block.FetcherConcurrency, insBkt, baseBlockIDsFetcher, "", extprom.WrapRegistererWithPrefix(extpromPrefix, reg), filters)
429458
if err != nil {
@@ -435,7 +464,7 @@ func registerBucketLs(app extkingpin.AppClause, objStoreConfig *extflag.PathOrCo
435464

436465
defer runutil.CloseWithLogOnErr(logger, insBkt, "bucket client")
437466

438-
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
467+
ctx, cancel := context.WithTimeout(context.Background(), tbc.timeout)
439468
defer cancel()
440469

441470
var (

docs/components/tools.md

+30
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,20 @@ Flags:
471471
--log.format=logfmt Log format to use. Possible options: logfmt or
472472
json.
473473
--log.level=info Log filtering level.
474+
--max-time=9999-12-31T23:59:59Z
475+
End of time range limit to list. Thanos Tools
476+
will list only blocks, which were created
477+
earlier than this value. Option can be a
478+
constant time in RFC3339 format or time duration
479+
relative to current time, such as -1d or 2h45m.
480+
Valid duration units are ms, s, m, h, d, w, y.
481+
--min-time=0000-01-01T00:00:00Z
482+
Start of time range limit to list blocks.
483+
Thanos Tools will list blocks, which were
484+
created later than this value. Option can be a
485+
constant time in RFC3339 format or time duration
486+
relative to current time, such as -1d or 2h45m.
487+
Valid duration units are ms, s, m, h, d, w, y.
474488
--objstore.config=<content>
475489
Alternative to 'objstore.config-file'
476490
flag (mutually exclusive). Content of
@@ -484,6 +498,22 @@ Flags:
484498
-o, --output="" Optional format in which to print each block's
485499
information. Options are 'json', 'wide' or a
486500
custom template.
501+
--selector.relabel-config=<content>
502+
Alternative to 'selector.relabel-config-file'
503+
flag (mutually exclusive). Content of YAML
504+
file with relabeling configuration that allows
505+
selecting blocks to act on based on their
506+
external labels. It follows thanos sharding
507+
relabel-config syntax. For format details see:
508+
https://thanos.io/tip/thanos/sharding.md/#relabelling
509+
--selector.relabel-config-file=<file-path>
510+
Path to YAML file with relabeling
511+
configuration that allows selecting blocks
512+
to act on based on their external labels.
513+
It follows thanos sharding relabel-config
514+
syntax. For format details see:
515+
https://thanos.io/tip/thanos/sharding.md/#relabelling
516+
--timeout=5m Timeout to download metadata from remote storage
487517
--tracing.config=<content>
488518
Alternative to 'tracing.config-file' flag
489519
(mutually exclusive). Content of YAML file

0 commit comments

Comments
 (0)