Skip to content

Commit

Permalink
Require empty tenant deletion to be enabled in the config
Browse files Browse the repository at this point in the history
  • Loading branch information
zalegrala committed May 3, 2024
1 parent 914e559 commit 2bc07c7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
18 changes: 18 additions & 0 deletions integration/poller/poller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ func TestTenantDeletion(t *testing.T) {
r := backend.NewReader(rr)
w := backend.NewWriter(ww)

// Tenant deletion is not enabled by default
blocklistPoller := blocklist.NewPoller(&blocklist.PollerConfig{
PollConcurrency: 3,
TenantIndexBuilders: 1,
Expand Down Expand Up @@ -352,6 +353,23 @@ func TestTenantDeletion(t *testing.T) {
_, _, err = blocklistPoller.Do(l)
require.NoError(t, err)

tennants, err = r.Tenants(ctx)
t.Logf("tennants: %v", tennants)
require.NoError(t, err)
require.Equal(t, 1, len(tennants))

// Create a new poller with tenantion deletion enabled
blocklistPoller = blocklist.NewPoller(&blocklist.PollerConfig{
PollConcurrency: 3,
TenantIndexBuilders: 1,
EmptyTenantDeletionAge: 100 * time.Millisecond,
EmptyTenantDeletionEnabled: true,
}, OwnsEverythingSharder, r, cc, w, logger)

// Again
_, _, err = blocklistPoller.Do(l)
require.NoError(t, err)

tennants, err = r.Tenants(ctx)
t.Logf("tennants: %v", tennants)
require.NoError(t, err)
Expand Down
20 changes: 13 additions & 7 deletions tempodb/blocklist/poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,14 @@ var (

// Config is used to configure the poller
type PollerConfig struct {
PollConcurrency uint
PollFallback bool
TenantIndexBuilders int
StaleTenantIndex time.Duration
PollJitterMs int
TolerateConsecutiveErrors int
EmptyTenantDeletionAge time.Duration
PollConcurrency uint
PollFallback bool
TenantIndexBuilders int
StaleTenantIndex time.Duration
PollJitterMs int
TolerateConsecutiveErrors int
EmptyTenantDeletionAge time.Duration
EmptyTenantDeletionEnabled bool
}

// JobSharder is used to determine if a particular job is owned by this process
Expand Down Expand Up @@ -468,6 +469,11 @@ func (p *Poller) tenantIndexPollError(idx *backend.TenantIndex, err error) error

// deleteTenant will delete all of a tenant's objects if there is not a tenant index present.
func (p *Poller) deleteTenant(ctx context.Context, tenantID string) error {
// If we have not enabled empty tenant deletion, do nothing.
if !p.cfg.EmptyTenantDeletionEnabled {
return nil
}

level.Info(p.logger).Log("msg", "deleting tenant", "tenant", tenantID)

if p.cfg.EmptyTenantDeletionAge == 0 {
Expand Down
3 changes: 2 additions & 1 deletion tempodb/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ type Config struct {
BlocklistPollJitterMs int `yaml:"blocklist_poll_jitter_ms"`
BlocklistPollTolerateConsecutiveErrors int `yaml:"blocklist_poll_tolerate_consecutive_errors"`

EmptyTenantDeletionAge time.Duration `yaml:"empty_tenant_deletion_age"`
EmptyTenantDeletionEnabled bool `yaml:"empty_tenant_deletion_enabled"`
EmptyTenantDeletionAge time.Duration `yaml:"empty_tenant_deletion_age"`

// backends
Backend string `yaml:"backend"`
Expand Down
15 changes: 8 additions & 7 deletions tempodb/tempodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,13 +509,14 @@ func (rw *readerWriter) EnablePolling(ctx context.Context, sharder blocklist.Job
level.Info(rw.logger).Log("msg", "polling enabled", "interval", rw.cfg.BlocklistPoll, "blocklist_concurrency", rw.cfg.BlocklistPollConcurrency)

blocklistPoller := blocklist.NewPoller(&blocklist.PollerConfig{
PollConcurrency: rw.cfg.BlocklistPollConcurrency,
PollFallback: rw.cfg.BlocklistPollFallback,
TenantIndexBuilders: rw.cfg.BlocklistPollTenantIndexBuilders,
StaleTenantIndex: rw.cfg.BlocklistPollStaleTenantIndex,
PollJitterMs: rw.cfg.BlocklistPollJitterMs,
TolerateConsecutiveErrors: rw.cfg.BlocklistPollTolerateConsecutiveErrors,
EmptyTenantDeletionAge: rw.cfg.EmptyTenantDeletionAge,
PollConcurrency: rw.cfg.BlocklistPollConcurrency,
PollFallback: rw.cfg.BlocklistPollFallback,
TenantIndexBuilders: rw.cfg.BlocklistPollTenantIndexBuilders,
StaleTenantIndex: rw.cfg.BlocklistPollStaleTenantIndex,
PollJitterMs: rw.cfg.BlocklistPollJitterMs,
TolerateConsecutiveErrors: rw.cfg.BlocklistPollTolerateConsecutiveErrors,
EmptyTenantDeletionAge: rw.cfg.EmptyTenantDeletionAge,
EmptyTenantDeletionEnabled: rw.cfg.EmptyTenantDeletionEnabled,
}, sharder, rw.r, rw.c, rw.w, rw.logger)

rw.blocklistPoller = blocklistPoller
Expand Down

0 comments on commit 2bc07c7

Please sign in to comment.