-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
compaction: remove all cache dirs at the end of each run #1587
Merged
bwplotka
merged 14 commits into
thanos-io:master
from
krasi-georgiev:cleanup-temp-files
Oct 10, 2019
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
95757ea
remove all cache dirs at the end of each run
krasi-georgiev acf199e
changelog
krasi-georgiev 3fe3fe5
.
krasi-georgiev 9c57518
changelog formating and pr num.
krasi-georgiev 4914be4
Merge remote-tracking branch 'upstream/master' into cleanup-temp-files
krasi-georgiev bb1610f
added test for the compaction cleanup
krasi-georgiev 3646e13
added tests
krasi-georgiev bd7f4fe
check error
krasi-georgiev 74fad16
move GatherAndCompare to tesutil
krasi-georgiev 808d83b
comment
krasi-georgiev 203ed41
nit
krasi-georgiev 3c678b2
Added back deletion of the downsampling dir.
bwplotka 5682646
Merge branch 'master' into krasi-georgiev-cleanup-temp-files
bwplotka c326cc8
Fix after pull master.
bwplotka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"io/ioutil" | ||
"os" | ||
"path" | ||
|
||
"testing" | ||
"time" | ||
|
||
"github.com/go-kit/kit/log" | ||
"github.com/oklog/ulid" | ||
"github.com/prometheus/client_golang/prometheus" | ||
promtest "github.com/prometheus/client_golang/prometheus/testutil" | ||
"github.com/prometheus/prometheus/tsdb" | ||
"github.com/prometheus/prometheus/tsdb/labels" | ||
"github.com/thanos-io/thanos/pkg/block" | ||
"github.com/thanos-io/thanos/pkg/compact" | ||
"github.com/thanos-io/thanos/pkg/compact/downsample" | ||
"github.com/thanos-io/thanos/pkg/objstore" | ||
"github.com/thanos-io/thanos/pkg/objstore/inmem" | ||
"github.com/thanos-io/thanos/pkg/testutil" | ||
) | ||
|
||
func TestCleanupCompactCacheFolder(t *testing.T) { | ||
ctx, logger, dir, _, bkt, actReg := bootstrap(t) | ||
defer func() { testutil.Ok(t, os.RemoveAll(dir)) }() | ||
|
||
sy, err := compact.NewSyncer(logger, actReg, bkt, 0*time.Second, 1, false, nil) | ||
testutil.Ok(t, err) | ||
|
||
expReg := prometheus.NewRegistry() | ||
syncExp := prometheus.NewCounter(prometheus.CounterOpts{ | ||
Name: compact.MetricSyncMetaName, | ||
Help: compact.MetricSyncMetaHelp, | ||
}) | ||
expReg.MustRegister(syncExp) | ||
|
||
testutil.GatherAndCompare(t, expReg, actReg, compact.MetricSyncMetaName) | ||
|
||
comp, err := tsdb.NewLeveledCompactor(ctx, nil, logger, []int64{1}, nil) | ||
testutil.Ok(t, err) | ||
|
||
bComp, err := compact.NewBucketCompactor(logger, sy, comp, dir, bkt, 1) | ||
testutil.Ok(t, err) | ||
|
||
// Even with with a single uploaded block the bucker compactor needs to | ||
// downloads the meta file to plan the compaction groups. | ||
testutil.Ok(t, bComp.Compact(ctx)) | ||
|
||
syncExp.Inc() | ||
|
||
testutil.GatherAndCompare(t, expReg, actReg, compact.MetricSyncMetaName) | ||
|
||
_, err = os.Stat(dir) | ||
testutil.Assert(t, os.IsNotExist(err), "index cache dir shouldn't not exist at the end of execution") | ||
|
||
} | ||
|
||
func TestCleanupIndexCacheFolder(t *testing.T) { | ||
ctx, logger, dir, _, bkt, actReg := bootstrap(t) | ||
defer func() { testutil.Ok(t, os.RemoveAll(dir)) }() | ||
|
||
expReg := prometheus.NewRegistry() | ||
genIndexExp := prometheus.NewCounter(prometheus.CounterOpts{ | ||
Name: MetricIndexGenerateName, | ||
Help: MetricIndexGenerateHelp, | ||
}) | ||
expReg.MustRegister(genIndexExp) | ||
|
||
testutil.GatherAndCompare(t, expReg, actReg, compact.MetricSyncMetaName) | ||
|
||
testutil.Ok(t, genMissingIndexCacheFiles(ctx, logger, actReg, bkt, dir)) | ||
|
||
genIndexExp.Inc() | ||
testutil.GatherAndCompare(t, expReg, actReg, compact.MetricSyncMetaName) | ||
|
||
_, err := os.Stat(dir) | ||
testutil.Assert(t, os.IsNotExist(err), "index cache dir shouldn't not exist at the end of execution") | ||
} | ||
|
||
func TestCleanupDownsampleCacheFolder(t *testing.T) { | ||
ctx, logger, dir, blckID, bkt, reg := bootstrap(t) | ||
defer func() { testutil.Ok(t, os.RemoveAll(dir)) }() | ||
|
||
meta, err := block.DownloadMeta(ctx, logger, bkt, blckID) | ||
testutil.Ok(t, err) | ||
|
||
metrics := newDownsampleMetrics(reg) | ||
testutil.Equals(t, 0.0, promtest.ToFloat64(metrics.downsamples.WithLabelValues(compact.GroupKey(meta)))) | ||
testutil.Ok(t, downsampleBucket(ctx, logger, metrics, bkt, dir)) | ||
testutil.Equals(t, 1.0, promtest.ToFloat64(metrics.downsamples.WithLabelValues(compact.GroupKey(meta)))) | ||
|
||
_, err = os.Stat(dir) | ||
testutil.Assert(t, os.IsNotExist(err), "index cache dir shouldn't not exist at the end of execution") | ||
} | ||
|
||
func bootstrap(t *testing.T) (context.Context, log.Logger, string, ulid.ULID, objstore.Bucket, *prometheus.Registry) { | ||
logger := log.NewLogfmtLogger(os.Stderr) | ||
dir, err := ioutil.TempDir("", "test-compact-cleanup") | ||
testutil.Ok(t, err) | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | ||
defer cancel() | ||
|
||
bkt := inmem.NewBucket() | ||
var blckID ulid.ULID | ||
|
||
// Create and upload a single block to the bucker. | ||
// The compaction will download the meta block of | ||
// this block to plan the compaction groups. | ||
{ | ||
blckID, err = testutil.CreateBlock( | ||
ctx, | ||
dir, | ||
[]labels.Labels{ | ||
{{Name: "a", Value: "1"}}, | ||
}, | ||
1, 0, downsample.DownsampleRange0+1, // Pass the minimum DownsampleRange0 check. | ||
labels.Labels{{Name: "e1", Value: "1"}}, | ||
downsample.ResLevel0) | ||
testutil.Ok(t, err) | ||
testutil.Ok(t, block.Upload(ctx, logger, bkt, path.Join(dir, blckID.String()))) | ||
} | ||
|
||
return ctx, logger, dir, blckID, bkt, prometheus.NewRegistry() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not having those inside package responsible for deleting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because it will require duplicating the bootstrap function.
I thought to put the bootstrap in some reusable package, but don't think it is generic enough to be useful anywhere else.
If it happens that that func becomes useful in other tests would revisit and refactor.