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

Prune in-memory blocks from missing tenants #314

Merged
merged 12 commits into from
Nov 10, 2020
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
* [ENHANCEMENT] Add command line flags for s3 credentials. [#308](https://github.com/grafana/tempo/pull/308)
* [BUGFIX] Increase Prometheus `notfound` metric on tempo-vulture. [#301](https://github.com/grafana/tempo/pull/301)
* [BUGFIX] Return 404 if searching for a tenant id that does not exist in the backend. [#321](https://github.com/grafana/tempo/pull/321)
* [BUGFIX] Prune in-memory blocks from missing tenants. [#314](https://github.com/grafana/tempo/pull/314)
7 changes: 7 additions & 0 deletions tempodb/tempodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,13 @@ func (rw *readerWriter) pollBlocklist() {
metricBlocklistErrors.WithLabelValues(tenantID).Inc()
level.Error(rw.logger).Log("msg", "error polling blocklist", "tenantID", tenantID, "err", err)
}
if len(blockIDs) == 0 {
dgzlopes marked this conversation as resolved.
Show resolved Hide resolved
rw.blockListsMtx.Lock()
delete(rw.blockLists, tenantID)
delete(rw.compactedBlockLists, tenantID)
rw.blockListsMtx.Unlock()
dgzlopes marked this conversation as resolved.
Show resolved Hide resolved
level.Info(rw.logger).Log("msg", "deleted in-memory blocklists", "tenantID", tenantID)
}

interfaceSlice := make([]interface{}, 0, len(blockIDs))
for _, id := range blockIDs {
Expand Down
52 changes: 52 additions & 0 deletions tempodb/tempodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,58 @@ func TestRetention(t *testing.T) {
checkBlocklists(t, blockID, 0, 0, rw)
}

func TestBlockCleanup(t *testing.T) {
tempDir, err := ioutil.TempDir("/tmp", "")
defer os.RemoveAll(tempDir)
assert.NoError(t, err, "unexpected error creating temp dir")

r, w, c, err := New(&Config{
Backend: "local",
Local: &local.Config{
Path: path.Join(tempDir, "traces"),
},
WAL: &wal.Config{
Filepath: path.Join(tempDir, "wal"),
IndexDownsample: 17,
BloomFP: .01,
},
BlocklistPoll: 0,
}, log.NewNopLogger())
assert.NoError(t, err)

c.EnableCompaction(&CompactorConfig{
ChunkSizeBytes: 10,
MaxCompactionRange: time.Hour,
BlockRetention: 0,
CompactedBlockRetention: 0,
}, &mockSharder{})

blockID := uuid.New()

wal := w.WAL()
assert.NoError(t, err)

head, err := wal.NewBlock(blockID, testTenantID)
assert.NoError(t, err)

complete, err := head.Complete(wal, &mockSharder{})
assert.NoError(t, err)
blockID = complete.BlockMeta().BlockID

err = w.WriteBlock(context.Background(), complete)
assert.NoError(t, err)

rw := r.(*readerWriter)

dgzlopes marked this conversation as resolved.
Show resolved Hide resolved
os.RemoveAll(tempDir + "/traces/" + testTenantID)

// poll
rw.pollBlocklist()

assert.Len(t, rw.blockLists[testTenantID], 0)
dgzlopes marked this conversation as resolved.
Show resolved Hide resolved
assert.Len(t, rw.compactedBlockLists[testTenantID], 0)
}

func checkBlocklists(t *testing.T, expectedID uuid.UUID, expectedB int, expectedCB int, rw *readerWriter) {
rw.pollBlocklist()

Expand Down