Skip to content

Commit

Permalink
Add timely head compaction support (#7372)
Browse files Browse the repository at this point in the history
* Add timely head compaction support
  • Loading branch information
jhalterman committed Feb 13, 2024
1 parent 55950ca commit 82f4ad8
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
* [FEATURE] Alertmanager API: added `-alertmanager.grafana-alertmanager-compatibility-enabled` CLI flag (and respective YAML config option) to enable an experimental API endpoints that support the migration of the Grafana Alertmanager. #7057
* [FEATURE] Alertmanager: Added `-alertmanager.utf8-strict-mode-enabled` to control support for any UTF-8 character as part of Alertmanager configuration/API matchers and labels. It's default value is set to `false`. #6898
* [FEATURE] Querier: added `histogram_avg()` function support to PromQL. #7293
* [FEATURE] Ingester: added `-blocks-storage.tsdb.timely-head-compaction` flag, which enables more timely head compaction, and defaults to `false`. #7372
* [ENHANCEMENT] Vault: add lifecycle manager for token used to authenticate to Vault. This ensures the client token is always valid. Includes a gauge (`cortex_vault_token_lease_renewal_active`) to check whether token renewal is active, and the counters `cortex_vault_token_lease_renewal_success_total` and `cortex_vault_auth_success_total` to see the total number of successful lease renewals / authentications. #7337
* [ENHANCEMENT] Store-gateway: add no-compact details column on store-gateway tenants admin UI. #6848
* [ENHANCEMENT] PromQL: ignore small errors for bucketQuantile #6766
Expand Down
11 changes: 11 additions & 0 deletions cmd/mimir/config-descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -8781,6 +8781,17 @@
"fieldFlag": "blocks-storage.tsdb.early-head-compaction-min-estimated-series-reduction-percentage",
"fieldType": "int",
"fieldCategory": "experimental"
},
{
"kind": "field",
"name": "timely_head_compaction_enabled",
"required": false,
"desc": "Allows head compaction to happen when the min block range can no longer be appended, without requiring 1.5x the chunk range worth of data in the head.",
"fieldValue": null,
"fieldDefaultValue": false,
"fieldFlag": "blocks-storage.tsdb.timely-head-compaction-enabled",
"fieldType": "boolean",
"fieldCategory": "experimental"
}
],
"fieldValue": null,
Expand Down
2 changes: 2 additions & 0 deletions cmd/mimir/help-all.txt.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,8 @@ Usage of ./cmd/mimir/mimir:
How frequently the TSDB blocks are scanned and new ones are shipped to the storage. 0 means shipping is disabled. (default 1m0s)
-blocks-storage.tsdb.stripe-size int
The number of shards of series to use in TSDB (must be a power of 2). Reducing this will decrease memory footprint, but can negatively impact performance. (default 16384)
-blocks-storage.tsdb.timely-head-compaction-enabled
[experimental] Allows head compaction to happen when the min block range can no longer be appended, without requiring 1.5x the chunk range worth of data in the head.
-blocks-storage.tsdb.wal-compression-enabled
True to enable TSDB WAL compression.
-blocks-storage.tsdb.wal-replay-concurrency int
Expand Down
1 change: 1 addition & 0 deletions docs/sources/mimir/configure/about-versioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ The following features are currently experimental:
- Early TSDB Head compaction to reduce in-memory series:
- `-blocks-storage.tsdb.early-head-compaction-min-in-memory-series`
- `-blocks-storage.tsdb.early-head-compaction-min-estimated-series-reduction-percentage`
- Timely head compaction (`-blocks-storage.tsdb.timely-head-compaction-enabled`)
- Ingester client
- Per-ingester circuit breaking based on requests timing out or hitting per-instance limits
- `-ingester.client.circuit-breaker.enabled`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3932,6 +3932,12 @@ tsdb:
# percentage (0-100).
# CLI flag: -blocks-storage.tsdb.early-head-compaction-min-estimated-series-reduction-percentage
[early_head_compaction_min_estimated_series_reduction_percentage: <int> | default = 15]
# (experimental) Allows head compaction to happen when the min block range can
# no longer be appended, without requiring 1.5x the chunk range worth of data
# in the head.
# CLI flag: -blocks-storage.tsdb.timely-head-compaction-enabled
[timely_head_compaction_enabled: <boolean> | default = false]
```

### compactor
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ require (
)

// Using a fork of Prometheus with Mimir-specific changes.
replace github.com/prometheus/prometheus => github.com/grafana/mimir-prometheus v0.0.0-20240205112357-84eae046431c
replace github.com/prometheus/prometheus => github.com/grafana/mimir-prometheus v0.0.0-20240213153929-d32b69f03433

// Replace memberlist with our fork which includes some fixes that haven't been
// merged upstream yet:
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,8 @@ github.com/grafana/gomemcache v0.0.0-20231023152154-6947259a0586 h1:/of8Z8taCPft
github.com/grafana/gomemcache v0.0.0-20231023152154-6947259a0586/go.mod h1:PGk3RjYHpxMM8HFPhKKo+vve3DdlPUELZLSDEFehPuU=
github.com/grafana/memberlist v0.3.1-0.20220714140823-09ffed8adbbe h1:yIXAAbLswn7VNWBIvM71O2QsgfgW9fRXZNR0DXe6pDU=
github.com/grafana/memberlist v0.3.1-0.20220714140823-09ffed8adbbe/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE=
github.com/grafana/mimir-prometheus v0.0.0-20240205112357-84eae046431c h1:jrkiLy8SjrLKbCeF1SCq6bKfdM2bR5/1hlnx+wwxAPQ=
github.com/grafana/mimir-prometheus v0.0.0-20240205112357-84eae046431c/go.mod h1:IMaHPfxuCuOjlEoyUE0AG7FGZLEwCg6WHXHLNQwPrJQ=
github.com/grafana/mimir-prometheus v0.0.0-20240213153929-d32b69f03433 h1:mW1Cet0WSipL2fBpfWnUyIlS7cZqvg2/5j6IP6lbogA=
github.com/grafana/mimir-prometheus v0.0.0-20240213153929-d32b69f03433/go.mod h1:IMaHPfxuCuOjlEoyUE0AG7FGZLEwCg6WHXHLNQwPrJQ=
github.com/grafana/opentracing-contrib-go-stdlib v0.0.0-20230509071955-f410e79da956 h1:em1oddjXL8c1tL0iFdtVtPloq2hRPen2MJQKoAWpxu0=
github.com/grafana/opentracing-contrib-go-stdlib v0.0.0-20230509071955-f410e79da956/go.mod h1:qtI1ogk+2JhVPIXVc6q+NHziSmy2W5GbdQZFUHADCBU=
github.com/grafana/pyroscope-go/godeltaprof v0.1.6 h1:nEdZ8louGAplSvIJi1HVp7kWvFvdiiYg3COLlTwJiFo=
Expand Down
1 change: 1 addition & 0 deletions pkg/ingester/ingester.go
Original file line number Diff line number Diff line change
Expand Up @@ -2440,6 +2440,7 @@ func (i *Ingester) createTSDB(userID string, walReplayConcurrency int) (*userTSD
EnableSharding: true, // Always enable query sharding support.
OutOfOrderTimeWindow: oooTW.Milliseconds(), // The unit must be same as our timestamps.
OutOfOrderCapMax: int64(i.cfg.BlocksStorageConfig.TSDB.OutOfOrderCapacityMax),
TimelyCompaction: i.cfg.BlocksStorageConfig.TSDB.TimelyHeadCompaction,
HeadPostingsForMatchersCacheTTL: i.cfg.BlocksStorageConfig.TSDB.HeadPostingsForMatchersCacheTTL,
HeadPostingsForMatchersCacheMaxItems: i.cfg.BlocksStorageConfig.TSDB.HeadPostingsForMatchersCacheMaxItems,
HeadPostingsForMatchersCacheMaxBytes: i.cfg.BlocksStorageConfig.TSDB.HeadPostingsForMatchersCacheMaxBytes,
Expand Down
5 changes: 5 additions & 0 deletions pkg/storage/tsdb/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ type TSDBConfig struct {

// HeadCompactionIntervalJitterEnabled is enabled by default, but allows to disable it in tests.
HeadCompactionIntervalJitterEnabled bool `yaml:"-"`

// TimelyHeadCompaction allows head compaction to happen when min block range can no longer be appended,
// without requiring 1.5x the chunk range worth of data in the head.
TimelyHeadCompaction bool `yaml:"timely_head_compaction_enabled" category:"experimental"`
}

// RegisterFlags registers the TSDBConfig flags.
Expand Down Expand Up @@ -308,6 +312,7 @@ func (cfg *TSDBConfig) RegisterFlags(f *flag.FlagSet) {
f.BoolVar(&cfg.BlockPostingsForMatchersCacheForce, "blocks-storage.tsdb.block-postings-for-matchers-cache-force", tsdb.DefaultPostingsForMatchersCacheForce, "Force the cache to be used for postings for matchers in compacted blocks, even if it's not a concurrent (query-sharding) call.")
f.Int64Var(&cfg.EarlyHeadCompactionMinInMemorySeries, "blocks-storage.tsdb.early-head-compaction-min-in-memory-series", 0, fmt.Sprintf("When the number of in-memory series in the ingester is equal to or greater than this setting, the ingester tries to compact the TSDB Head. The early compaction removes from the memory all samples and inactive series up until -%s time ago. After an early compaction, the ingester will not accept any sample with a timestamp older than -%s time ago (unless out of order ingestion is enabled). The ingester checks every -%s whether an early compaction is required. Use 0 to disable it.", activeseries.IdleTimeoutFlag, activeseries.IdleTimeoutFlag, headCompactionIntervalFlag))
f.IntVar(&cfg.EarlyHeadCompactionMinEstimatedSeriesReductionPercentage, "blocks-storage.tsdb.early-head-compaction-min-estimated-series-reduction-percentage", 15, "When the early compaction is enabled, the early compaction is triggered only if the estimated series reduction is at least the configured percentage (0-100).")
f.BoolVar(&cfg.TimelyHeadCompaction, "blocks-storage.tsdb.timely-head-compaction-enabled", false, "Allows head compaction to happen when the min block range can no longer be appended, without requiring 1.5x the chunk range worth of data in the head.")

cfg.HeadCompactionIntervalJitterEnabled = true
}
Expand Down
5 changes: 5 additions & 0 deletions vendor/github.com/prometheus/prometheus/tsdb/db.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion vendor/github.com/prometheus/prometheus/tsdb/head.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/modules.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 82f4ad8

Please sign in to comment.