Skip to content

Commit bc1bc5c

Browse files
authored
Added dry-run option. (#181)
Signed-off-by: Peter Štibraný <[email protected]>
1 parent 7b94d8a commit bc1bc5c

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

cmd/blockscopy/main.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,22 @@ type config struct {
4242
copyPeriod time.Duration
4343
enabledUsers flagext.StringSliceCSV
4444
disabledUsers flagext.StringSliceCSV
45+
dryRun bool
4546

4647
httpListen string
4748
}
4849

4950
func (c *config) RegisterFlags(f *flag.FlagSet) {
50-
f.StringVar(&c.sourceBucket, "source-bucket", "", "Source GCS bucket with blocks")
51-
f.StringVar(&c.destBucket, "destination-bucket", "", "Destination GCS bucket with blocks")
52-
f.DurationVar(&c.minBlockDuration, "min-block-duration", 24*time.Hour, "If non-zero, ignore blocks that cover block range smaller than this")
51+
f.StringVar(&c.sourceBucket, "source-bucket", "", "Source GCS bucket with blocks.")
52+
f.StringVar(&c.destBucket, "destination-bucket", "", "Destination GCS bucket with blocks.")
53+
f.DurationVar(&c.minBlockDuration, "min-block-duration", 24*time.Hour, "If non-zero, ignore blocks that cover block range smaller than this.")
5354
f.IntVar(&c.tenantConcurrency, "tenant-concurrency", 5, "How many tenants to process at once.")
5455
f.IntVar(&c.blocksConcurrency, "block-concurrency", 5, "How many blocks to copy at once per tenant.")
5556
f.DurationVar(&c.copyPeriod, "copy-period", 0, "How often to repeat the copy. If set to 0, copy is done once, and program stops. Otherwise program keeps running and copying blocks until terminated.")
5657
f.Var(&c.enabledUsers, "enabled-users", "If not empty, only blocks for these users are copied.")
5758
f.Var(&c.disabledUsers, "disabled-users", "If not empty, blocks for these users are not copied.")
58-
f.StringVar(&c.httpListen, "http-listen-address", ":8080", "HTTP listen address")
59+
f.StringVar(&c.httpListen, "http-listen-address", ":8080", "HTTP listen address.")
60+
f.BoolVar(&c.dryRun, "dry-run", false, "Don't perform copy, only log what would happen.")
5961
}
6062

6163
type metrics struct {
@@ -139,12 +141,12 @@ func runCopy(ctx context.Context, cfg config, logger log.Logger, m *metrics) boo
139141
err := copyBlocks(ctx, cfg, logger, m)
140142
if err != nil {
141143
m.copyCyclesFailed.Inc()
142-
level.Error(logger).Log("msg", "failed to copy blocks", "err", err)
144+
level.Error(logger).Log("msg", "failed to copy blocks", "err", err, "dryRun", cfg.dryRun)
143145
return false
144146
}
145147

146148
m.copyCyclesSucceeded.Inc()
147-
level.Info(logger).Log("msg", "finished copying blocks")
149+
level.Info(logger).Log("msg", "finished copying blocks", "dryRun", cfg.dryRun)
148150
return true
149151
}
150152

@@ -229,6 +231,11 @@ func copyBlocks(ctx context.Context, cfg config, logger log.Logger, m *metrics)
229231
}
230232
}
231233

234+
if cfg.dryRun {
235+
level.Info(logger).Log("msg", "would copy block, but skipping due to dry-run")
236+
return nil
237+
}
238+
232239
level.Info(logger).Log("msg", "copying block")
233240

234241
err = copySingleBlock(ctx, tenantID, blockID, sourceBucket, destBucket)

0 commit comments

Comments
 (0)