Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX-2167: tempodb integer divide by zero error #2333

Merged
merged 4 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* [ENHANCEMENT] Extend `/flush` to support flushing a single tenant [#2260](https://github.com/grafana/tempo/pull/2260) (@kvrhdn)

## v2.1.0-rc.0 / 2023-04-12

* [BUGFIX] tempodb integer divide by zero error [#2167](https://github.com/grafana/tempo/issues/2167)
mghildiy marked this conversation as resolved.
Show resolved Hide resolved
* [CHANGE] Capture and update search metrics for TraceQL [#2087](https://github.com/grafana/tempo/pull/2087) (@electron0zero)
* [CHANGE] tempo-mixin: disable auto refresh every 10 seconds [#2290](https://github.com/grafana/tempo/pull/2290) (@electron0zero)
* [CHANGE] Update tempo-mixin to show request in Resources dashboard [#2281](https://github.com/grafana/tempo/pull/2281) (@electron0zero)
Expand Down
8 changes: 8 additions & 0 deletions tempodb/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ type CompactorConfig struct {
CompactionCycle time.Duration `yaml:"compaction_cycle"`
}

func (compactorConfig CompactorConfig) validate() error {
if compactorConfig.MaxCompactionRange == 0 {
return errors.New("Compaction window can't be 0")
}

return nil
}

func validateConfig(cfg *Config) error {
if cfg == nil {
return errors.New("config should be non-nil")
Expand Down
11 changes: 11 additions & 0 deletions tempodb/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,14 @@ func TestValidateConfig(t *testing.T) {
}
}
}

func TestValidateCompactorConfig(t *testing.T) {
compactorConfig := CompactorConfig{
MaxCompactionRange: 0,
}

expected := errors.New("Compaction window can't be 0")
actual := compactorConfig.validate()

require.Equal(t, expected, actual)
}
7 changes: 7 additions & 0 deletions tempodb/tempodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,13 @@ func (rw *readerWriter) Shutdown() {

// EnableCompaction activates the compaction/retention loops
func (rw *readerWriter) EnableCompaction(ctx context.Context, cfg *CompactorConfig, c CompactorSharder, overrides CompactorOverrides) {
// If compactor configuration is not as expected, no need to go any further
err := cfg.validate()
if err != nil {
level.Error(log.Logger).Log(err.Error())
return
}

// Set default if needed. This is mainly for tests.
if cfg.RetentionConcurrency == 0 {
cfg.RetentionConcurrency = DefaultRetentionConcurrency
Expand Down
13 changes: 13 additions & 0 deletions tempodb/tempodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,19 @@ func TestDB(t *testing.T) {
}
}

func TestNoCompactionWhenCompactionRange0(t *testing.T) {
_, _, c, _ := testConfig(t, backend.EncGZIP, 0)

c.EnableCompaction(context.Background(), &CompactorConfig{
MaxCompactionRange: 0,
}, &mockSharder{}, &mockOverrides{})

rw := c.(*readerWriter)

assert.Equal(t, 0, len(rw.blocklist.Tenants()))
assert.Equal(t, 0, len(rw.blocklist.Metas(testTenantID)))
}

func TestBlockSharding(t *testing.T) {
// push a req with some traceID
// cut headblock & write to backend
Expand Down