Skip to content

Commit 2c43865

Browse files
committed
Support newly added --storage.tsdb.delay-compact-file.path Prometheus flag
Prometheus has a new flag --storage.tsdb.delay-compact-file.path - prometheus/prometheus#17435. When this flag is passed Prometheus will check which blocks are marked as uploaded in external file and only compact these. Thanos should look for this flag and if it's set then it can stop forcing people to disable compactions. Signed-off-by: Lukasz Mierzwa <[email protected]>
1 parent 65be251 commit 2c43865

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

cmd/thanos/sidecar.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func runSidecar(
189189
iterCtx, iterCancel := context.WithTimeout(context.Background(), conf.prometheus.getConfigTimeout)
190190
defer iterCancel()
191191

192-
if err := validatePrometheus(iterCtx, m.client, logger, conf.shipper.ignoreBlockSize, m); err != nil {
192+
if err := validatePrometheus(iterCtx, m.client, logger, conf.shipper.ignoreBlockSize, conf.shipper.metaFileName, m); err != nil {
193193
level.Warn(logger).Log(
194194
"msg", "failed to validate prometheus flags. Is Prometheus running? Retrying",
195195
"err", err,
@@ -443,7 +443,7 @@ func runSidecar(
443443
return nil
444444
}
445445

446-
func validatePrometheus(ctx context.Context, client *promclient.Client, logger log.Logger, ignoreBlockSize bool, m *promMetadata) error {
446+
func validatePrometheus(ctx context.Context, client *promclient.Client, logger log.Logger, ignoreBlockSize bool, metaFileName string, m *promMetadata) error {
447447
var (
448448
flagErr error
449449
flags promclient.Flags
@@ -464,8 +464,16 @@ func validatePrometheus(ctx context.Context, client *promclient.Client, logger l
464464
return nil
465465
}
466466

467+
if flags.TSDBDelayCompact != "" && flags.TSDBDelayCompact != metaFileName {
468+
return errors.Errorf(
469+
"found that Prometheus and Thanos use different paths for tracking block uploads. "+
470+
"Prometheus uses --storage.tsdb.delay-compact-file.path=%s while Thanos uses --shipper.meta-file-name=%s, they must both use the same path.",
471+
flags.TSDBDelayCompact, metaFileName,
472+
)
473+
}
474+
467475
// Check if compaction is disabled.
468-
if flags.TSDBMinTime != flags.TSDBMaxTime {
476+
if flags.TSDBMinTime != flags.TSDBMaxTime && flags.TSDBDelayCompact == "" {
469477
if !ignoreBlockSize {
470478
return errors.Errorf("found that TSDB Max time is %s and Min time is %s. "+
471479
"Compaction needs to be disabled (storage.tsdb.min-block-duration = storage.tsdb.max-block-duration)", flags.TSDBMaxTime, flags.TSDBMinTime)

pkg/promclient/promclient.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ type Flags struct {
217217
TSDBRetention model.Duration `json:"storage.tsdb.retention"`
218218
TSDBMinTime model.Duration `json:"storage.tsdb.min-block-duration"`
219219
TSDBMaxTime model.Duration `json:"storage.tsdb.max-block-duration"`
220+
TSDBDelayCompact string `json:"storage.tsdb.delay-compact-file.path"`
220221
WebEnableAdminAPI bool `json:"web.enable-admin-api"`
221222
WebEnableLifecycle bool `json:"web.enable-lifecycle"`
222223
}
@@ -231,6 +232,7 @@ func (f *Flags) UnmarshalJSON(b []byte) error {
231232
TSDBRetention modelDuration `json:"storage.tsdb.retention"`
232233
TSDBMinTime modelDuration `json:"storage.tsdb.min-block-duration"`
233234
TSDBMaxTime modelDuration `json:"storage.tsdb.max-block-duration"`
235+
TSDBDelayCompact string `json:"storage.tsdb.delay-compact-file.path"`
234236
WebEnableAdminAPI modelBool `json:"web.enable-admin-api"`
235237
WebEnableLifecycle modelBool `json:"web.enable-lifecycle"`
236238
}{}
@@ -244,6 +246,7 @@ func (f *Flags) UnmarshalJSON(b []byte) error {
244246
TSDBRetention: model.Duration(parsableFlags.TSDBRetention),
245247
TSDBMinTime: model.Duration(parsableFlags.TSDBMinTime),
246248
TSDBMaxTime: model.Duration(parsableFlags.TSDBMaxTime),
249+
TSDBDelayCompact: parsableFlags.TSDBDelayCompact,
247250
WebEnableAdminAPI: bool(parsableFlags.WebEnableAdminAPI),
248251
WebEnableLifecycle: bool(parsableFlags.WebEnableLifecycle),
249252
}

0 commit comments

Comments
 (0)