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

Add -compactor.first-level-compaction-wait-period support #4401

Merged
merged 5 commits into from
Mar 7, 2023

Conversation

pracucci
Copy link
Collaborator

@pracucci pracucci commented Mar 6, 2023

What this PR does

In this PR I proposed to introduce compactor.first-level-compaction-wait-period configuration option to address the issue described by #4365.

Notes:

  • When the wait period is enabled, the compactor will issue an HEAD request for each block in a job (used to fetch the last modified timestamp). I plan to add the bucket metadata cache support to compactor too in a follow up PR.

Which issue(s) this PR fixes or relates to

Part of #4365

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

@pracucci pracucci requested review from a team as code owners March 6, 2023 18:07
@@ -673,15 +675,15 @@ func (c *MultitenantCompactor) compactUserWithRetries(ctx context.Context, userI
}

func (c *MultitenantCompactor) compactUser(ctx context.Context, userID string) error {
bucket := bucket.NewUserBucketClient(userID, c.bucketClient, c.cfgProvider)
userBucket := bucket.NewUserBucketClient(userID, c.bucketClient, c.cfgProvider)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to reviewers: renamed just to clarify it's the "user bucket".

reg := prometheus.NewRegistry()
defer c.syncerMetrics.gatherThanosSyncerMetrics(reg)

ulogger := util_log.WithUserID(userID, c.logger)
userLogger := util_log.WithUserID(userID, c.logger)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to reviewers: renamed just to clarify it's the "user logger".

@pracucci pracucci requested a review from pstibrany March 6, 2023 18:11
Copy link
Contributor

@56quarters 56quarters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with some non-blocking feedback.

return true, nil
}

if ok, err := jobContainsBlocksUploadedAfter(ctx, job, userBucket, time.Now().Add(-waitPeriod)); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Maybe it makes sense to pass time.Now() as an argument to avoid calling it in a loop?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly don't think will make any visible difference. We're not calling it millions of times.

// We expect only 1 compaction job has been expected, while the 2nd has been skipped.
tsdbPlanner.AssertNumberOfCalls(t, "Plan", 1)

assert.ElementsMatch(t, []string{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this isn't the first test to do this, but I really don't like asserting on side effects of an operation (info log statements) instead of the results (some sort of "compaction result" object?).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point. I've simplified it in 6e8f723. I'm still checking logs, but asserting only on 1 log line, which is what we care about in this test.

Signed-off-by: Marco Pracucci <marco@pracucci.com>
Signed-off-by: Marco Pracucci <marco@pracucci.com>
Signed-off-by: Marco Pracucci <marco@pracucci.com>
Copy link
Member

@pstibrany pstibrany left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, left some minor comments. Happy to see this option!

pkg/compactor/bucket_compactor.go Outdated Show resolved Hide resolved
pkg/compactor/bucket_compactor.go Outdated Show resolved Hide resolved

// Mock two tenants, each with the same exact overlapping blocks. However,
// the 2nd tenant has uploaded the blocks less than "wait period" ago.
bucketClient := &bucket.ClientMock{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] Could we use a real bucket instead? (inmem or filesystem) These "mocks" create brittle tests that are tightly coupled with the implementation (eg. we need to provide response for deletion-mark.json or no-compact-mark.json files, even if they are not important for this test at all).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Done in 6e8f723.

// We expect only 1 compaction job has been expected, while the 2nd has been skipped.
tsdbPlanner.AssertNumberOfCalls(t, "Plan", 1)

assert.ElementsMatch(t, []string{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of matching all elements, we should only check for message that's relevant for this test, to avoid creating very fragile test that needs changes on every log message change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 6e8f723.

pkg/compactor/job_wait_period.go Outdated Show resolved Hide resolved
pkg/compactor/job_wait_period.go Outdated Show resolved Hide resolved
Signed-off-by: Marco Pracucci <marco@pracucci.com>
…tLevelCompactionBlocksAndWaitPeriodNotElapsed to use a real bucket client and only assert on a specific log message

Signed-off-by: Marco Pracucci <marco@pracucci.com>
Copy link
Member

@pstibrany pstibrany left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing my feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants