-
Notifications
You must be signed in to change notification settings - Fork 93
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
chore(spool): Enable periodic unspool #2993
Conversation
|
||
// If there is nothing spooled, schedule the next check a little bit later. | ||
if keys.is_empty() { | ||
self.schedule_unspool(); |
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.
Is this to schedule the unspool before resetting?
Can we return in this branch to make it clear, e.g.
self.schedule_unspool();
self.buffer_unspool_backoff.reset();
return;
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.
nit: Should the reset of the backoff be part of schedule_unspool
?
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.
nope, since if there is nothing to unspool, I want to wait a little bit longer before trying to unspool again. Once the unspool finishes with anything, we reset the backoff to initial state (which currently 100ms)
@@ -913,6 +895,48 @@ impl ProjectCacheBroker { | |||
} | |||
} | |||
|
|||
/// Returns backoff timeout for an unspool attempt. | |||
fn next_unspool_attempt(&mut self) -> Duration { | |||
self.config.spool_envelopes_unspool_interval() + self.buffer_unspool_backoff.next_backoff() |
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.
nit: Instead of adding an interval to a backoff, could we use ExponentialBackoff
instead of RetryBackoff
and initialize it with an initial_interval
of self.config.spool_envelopes_unspool_interval()
?
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.
do you mean to use backoff::ExponentialBackoff
directly?
We have a little better interface and we also could add some functions to make the setting of things for it more convenient.
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.
Makes sense. We could make RetryBackoff
more flexible (i.e. accept a custom initial delay), but that's out of scope for this PR.
|
||
// If there is nothing spooled, schedule the next check a little bit later. | ||
if keys.is_empty() { | ||
self.schedule_unspool(); |
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.
nit: Should the reset of the backoff be part of schedule_unspool
?
if self | ||
.projects | ||
.get(project_key) | ||
.map_or(false, |state| state.valid_state().is_some()) |
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.
Is the project config actually being refreshed anywhere now? In the previous impl we had .get_cached_state(project_cache, false)
which did an implicit fetch.
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.
It will be refreshed as it was before like normal refresh operation.
Here I just want to check for the valid states, and if there are try to unspool them.
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.
Gotcha. It might not be related to the goal of this PR but I feel like we should trigger a prefetch at this point. Otherwise we still depend on incoming traffic to get old data unspooled, right?
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.
it's a valid point.
I've switched to using get_cached_state
instead, which will trigger the refresh of the project state if it's not valid or expired.
@@ -683,8 +663,10 @@ impl ProjectCacheBroker { | |||
no_cache, | |||
); | |||
|
|||
if !state.invalid() { | |||
self.dequeue(project_key); | |||
// Schedule unspool if nothing is running at the moment. |
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.
Should we check here too whether there are enough buffer guards available?
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.
nope, the check is done in handle_periodic_unspool
now.
@@ -913,6 +895,48 @@ impl ProjectCacheBroker { | |||
} | |||
} | |||
|
|||
/// Returns backoff timeout for an unspool attempt. | |||
fn next_unspool_attempt(&mut self) -> Duration { | |||
self.config.spool_envelopes_unspool_interval() + self.buffer_unspool_backoff.next_backoff() |
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.
Makes sense. We could make RetryBackoff
more flexible (i.e. accept a custom initial delay), but that's out of scope for this PR.
if self | ||
.projects | ||
.get(project_key) | ||
.map_or(false, |state| state.valid_state().is_some()) |
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.
Gotcha. It might not be related to the goal of this PR but I feel like we should trigger a prefetch at this point. Otherwise we still depend on incoming traffic to get old data unspooled, right?
@@ -1268,4 +1309,89 @@ mod tests { | |||
assert!(buffer_rx.try_recv().is_err()) | |||
} | |||
} | |||
|
|||
#[tokio::test] | |||
async fn periodic_unspool() { |
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.
@jjbayer Added a test, if you want to have a look.
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.
Nice!
Currently in order to trigger unspool of buffered envelopes the new project state update must be received from the upstream, which sometimes can take longer time.
To make unspool action a bit more predictable let's enable periodic unspool initiated by project cache. This way:
part of: https://github.com/getsentry/team-ingest/issues/267