Skip to content

Commit

Permalink
Allow compaction disable per tenant (#3965)
Browse files Browse the repository at this point in the history
* Allow compaction disable per tenant

* Update mock

* Rename legacy yaml key

* Rename methods and fields for clarity about disablement

* Rename methods and fields for clarity about disablement

* Update changelog
  • Loading branch information
zalegrala authored Aug 15, 2024
1 parent 89b8d7d commit 7dffd0e
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
* [ENHANCEMENT] Added new Traces api V2[#3912](https://github.com/grafana/tempo/pull/3912) (@javiermolinar)
* [ENHANCEMENT] Update to the latest dskit [#3915](https://github.com/grafana/tempo/pull/3915) (@andreasgerstmayr)
* [ENHANCEMENT] Reduce allocs building queriers sharded requests [#3932](https://github.com/grafana/tempo/pull/3932) (@javiermolinar)
* [ENHANCEMENT] Allow compaction disablement per-tenant [#3965](https://github.com/grafana/tempo/pull/3965) (@zalegrala)

* [ENHANCEMENT] Implement polling tenants concurrently [#3647](https://github.com/grafana/tempo/pull/3647) (@zalegrala)
* [BUGFIX] Fix panic in certain metrics queries using `rate()` with `by` [#3847](https://github.com/grafana/tempo/pull/3847) (@stoewer)
Expand Down
5 changes: 5 additions & 0 deletions modules/compactor/compactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ func (c *Compactor) BlockRetentionForTenant(tenantID string) time.Duration {
return c.overrides.BlockRetention(tenantID)
}

// CompactionDisabledForTenant implements CompactorOverrides
func (c *Compactor) CompactionDisabledForTenant(tenantID string) bool {
return c.overrides.CompactionDisabled(tenantID)
}

func (c *Compactor) MaxBytesPerTraceForTenant(tenantID string) int {
return c.overrides.MaxBytesPerTrace(tenantID)
}
Expand Down
5 changes: 3 additions & 2 deletions modules/overrides/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ type ReadOverrides struct {

type CompactionOverrides struct {
// Compactor enforced overrides.
BlockRetention model.Duration `yaml:"block_retention,omitempty" json:"block_retention,omitempty"`
CompactionWindow model.Duration `yaml:"compaction_window,omitempty" json:"compaction_window,omitempty"`
BlockRetention model.Duration `yaml:"block_retention,omitempty" json:"block_retention,omitempty"`
CompactionWindow model.Duration `yaml:"compaction_window,omitempty" json:"compaction_window,omitempty"`
CompactionDisabled bool `yaml:"compaction_disabled,omitempty" json:"compaction_disabled,omitempty"`
}

type GlobalOverrides struct {
Expand Down
10 changes: 6 additions & 4 deletions modules/overrides/config_legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ type LegacyOverrides struct {
MetricsGeneratorIngestionSlack time.Duration `yaml:"metrics_generator_ingestion_time_range_slack" json:"metrics_generator_ingestion_time_range_slack"`

// Compactor enforced limits.
BlockRetention model.Duration `yaml:"block_retention" json:"block_retention"`
CompactionWindow model.Duration `yaml:"compaction_window" json:"compaction_window"`
BlockRetention model.Duration `yaml:"block_retention" json:"block_retention"`
CompactionDisabled bool `yaml:"compaction_disabled" json:"compaction_disabled"`
CompactionWindow model.Duration `yaml:"compaction_window" json:"compaction_window"`

// Querier and Ingester enforced limits.
MaxBytesPerTagValuesQuery int `yaml:"max_bytes_per_tag_values_query" json:"max_bytes_per_tag_values_query"`
Expand Down Expand Up @@ -155,8 +156,9 @@ func (l *LegacyOverrides) toNewLimits() Overrides {
UnsafeQueryHints: l.UnsafeQueryHints,
},
Compaction: CompactionOverrides{
BlockRetention: l.BlockRetention,
CompactionWindow: l.CompactionWindow,
BlockRetention: l.BlockRetention,
CompactionDisabled: l.CompactionDisabled,
CompactionWindow: l.CompactionWindow,
},
MetricsGenerator: MetricsGeneratorOverrides{
RingSize: l.MetricsGeneratorRingSize,
Expand Down
1 change: 1 addition & 0 deletions modules/overrides/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type Interface interface {
MetricsGeneratorProcessorServiceGraphsEnableVirtualNodeLabel(userID string) bool
MetricsGeneratorProcessorSpanMetricsTargetInfoExcludedDimensions(userID string) []string
BlockRetention(userID string) time.Duration
CompactionDisabled(userID string) bool
MaxSearchDuration(userID string) time.Duration
MaxMetricsDuration(userID string) time.Duration
DedicatedColumns(userID string) backend.DedicatedColumns
Expand Down
5 changes: 5 additions & 0 deletions modules/overrides/runtime_config_overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,11 @@ func (o *runtimeConfigOverridesManager) BlockRetention(userID string) time.Durat
return time.Duration(o.getOverridesForUser(userID).Compaction.BlockRetention)
}

// CompactionDisabled will not compact tenants which have this enabled.
func (o *runtimeConfigOverridesManager) CompactionDisabled(userID string) bool {
return o.getOverridesForUser(userID).Compaction.CompactionDisabled
}

func (o *runtimeConfigOverridesManager) DedicatedColumns(userID string) backend.DedicatedColumns {
return o.getOverridesForUser(userID).Storage.DedicatedColumns
}
Expand Down
6 changes: 6 additions & 0 deletions tempodb/compactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ func (rw *readerWriter) doCompaction(ctx context.Context) {

// Select the next tenant to run compaction for
tenantID := tenants[rw.compactorTenantOffset]

// Skip compaction for tenants which have it disabled.
if rw.compactorOverrides.CompactionDisabledForTenant(tenantID) {
return
}

// Get the meta file of all non-compacted blocks for the given tenant
blocklist := rw.blocklist.Metas(tenantID)

Expand Down
5 changes: 5 additions & 0 deletions tempodb/compactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func (m *mockJobSharder) Owns(string) bool { return true }

type mockOverrides struct {
blockRetention time.Duration
disabled bool
maxBytesPerTrace int
maxCompactionWindow time.Duration
}
Expand All @@ -56,6 +57,10 @@ func (m *mockOverrides) BlockRetentionForTenant(_ string) time.Duration {
return m.blockRetention
}

func (m *mockOverrides) CompactionDisabledForTenant(_ string) bool {
return m.disabled
}

func (m *mockOverrides) MaxBytesPerTraceForTenant(_ string) int {
return m.maxBytesPerTrace
}
Expand Down
1 change: 1 addition & 0 deletions tempodb/tempodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ type CompactorSharder interface {

type CompactorOverrides interface {
BlockRetentionForTenant(tenantID string) time.Duration
CompactionDisabledForTenant(tenantID string) bool
MaxBytesPerTraceForTenant(tenantID string) int
MaxCompactionRangeForTenant(tenantID string) time.Duration
}
Expand Down

0 comments on commit 7dffd0e

Please sign in to comment.