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

VAULT-14733: Split logic of precomputedQueryWorker #20073

Merged
merged 6 commits into from
May 16, 2023

Conversation

miagilepner
Copy link
Contributor

This PR splits up the precomputed query worker so that the logic transforming a segment to a precomputed query sits in its own method. This method will later be used by the client count generation endpoint.

@miagilepner miagilepner added this to the 1.14 milestone Apr 11, 2023
@miagilepner miagilepner requested review from raskchanky, mpalmi, hghaf099 and a team April 11, 2023 10:15
@miagilepner miagilepner marked this pull request as ready for review April 11, 2023 14:55
Copy link
Contributor

@mpalmi mpalmi left a comment

Choose a reason for hiding this comment

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

This is another dramatic improvement. Looks great! I threw in some initial superficial review comments regarding the method signatures. I'm going to do another pass on this with more impactful feedback, but just wanted to get the conversation started on a couple of things.

vault/activity_log.go Show resolved Hide resolved
vault/activity_log.go Show resolved Hide resolved

// pqOptions holds fields that will be used when creating precomputed queries
// These fields will remain the same for every segment that a precomputed query worker is handling
type pqOptions struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is terrific!

Copy link
Contributor

@mpalmi mpalmi left a comment

Choose a reason for hiding this comment

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

Nit-heavy review. I threw in a bunch of items around clarity/comment usefulness that I think could help. There's also one reverse-logic item that I'd like to see addressed.

vault/activity_log.go Outdated Show resolved Hide resolved
vault/activity_log.go Outdated Show resolved Hide resolved
// reverse ordering). If yes, we remove those references. This way a
// client is considered new only in the earliest month of its use in
// the billing period.
for currMonth := timeutil.StartOfMonth(segmentTime).UTC(); currMonth != timeutil.StartOfMonth(opts.activePeriodEnd).UTC(); currMonth = timeutil.StartOfNextMonth(currMonth).UTC() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like it could maybe be abstracted out into a rangeMonths method in timeutil, especially if it's used elsewhere (I haven't looked).

Copy link
Contributor

Choose a reason for hiding this comment

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

Barring that approach, I think capturing lastMonth := timeutil.StartOfMonth(opts.activePeriodEnd).UTC() outside of this loop and just using that variable in a currMonth.Before(lastMonth) could be useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is only used in one place, so i didn't make a new method in timeutil. I did clean it up according to your suggestion.

vault/activity_log.go Outdated Show resolved Hide resolved
vault/activity_log.go Show resolved Hide resolved
vault/activity_log.go Show resolved Hide resolved
a.logger.Warn("failed to read segment", "error", err)
return err
}
err = a.handleEntitySegment(entity, segmentTime, hyperloglog, opts)
Copy link
Contributor

Choose a reason for hiding this comment

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

I wish there was a way for us to avoid 3 levels of nested for loops, but I suppose there's a lot going on here, so it's kind of unavoidable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😢

vault/activity_log.go Outdated Show resolved Hide resolved
@miagilepner miagilepner force-pushed the miagilepner/VAULT-14733-split-pq branch from d51cd82 to 0625e2f Compare May 16, 2023 11:13
@miagilepner miagilepner merged commit 730d0e2 into main May 16, 2023
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.

3 participants