-
-
Notifications
You must be signed in to change notification settings - Fork 320
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 WatchStreamExt::default_backoff
shorthand
#1232
Conversation
To allow the same chaining style without having to import all the backoff dependencies directly. This allows me to write more concise recommendation documentation in kube-rs/website. Signed-off-by: clux <[email protected]>
Signed-off-by: clux <[email protected]>
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #1232 +/- ##
==========================================
- Coverage 72.06% 71.94% -0.13%
==========================================
Files 71 71
Lines 5714 5725 +11
==========================================
+ Hits 4118 4119 +1
- Misses 1596 1606 +10
|
Existential types would be nice ... I like the helper, especially since this is already the controller default behaviour. Have you considered just encapsulating the default backoff in a new-type? pub struct DefaultBackoff(InnerStrategyNotPublic)
impl Default for DefaultBackoff {
fn default() -> Self {
Self(default_exponential_backoff())
}
}
impl Backoff for DefaultBackoff {
fn next_backoff(&mut self) -> Option<Duration> {
self.0.next_backoff()
}
} And then just expose |
That suggestion does have legs. I might change the naming a bit because you'd end up with EDIT: no, |
Signed-off-by: clux <[email protected]>
Signed-off-by: clux <[email protected]>
Signed-off-by: clux <[email protected]>
Ok, have done this properly now. It is still somewhat hampered by the fact that ResetTimerBackoff is actually public, but have at least managed to keep that type out of |
Signed-off-by: clux <[email protected]>
Giving a ping to @nightkr here in case of extra opinions since she wasn't cc'd on originally. |
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.
LGTM
This change adds a simplified recommended backoff construction for watcher streams:
This is advantageous because it's hard to advocate that users use backoff (fundamentally a good behaviour action) when the usage is verbose. So this makes it less verbose.
To do this properly we have made a new
DefaultBackoff
struct that encapsulates the type. This is slightly more verbose than relying onimpl Backoff
fromwatcher::default_backoff
, but it has the benefit of working in the stream setting where we are limited by existential type constraints.This also deprecates the
watcher::default_backoff
fn due to it now generally being more easily invoked elsewhere, and by the explicit type. This could be debated.old, now irrelevant commentary, left in a collapsible
The slight downside here is that `watcher::default_backoff()` returns an opaque type and cannot be used in the shortcut stream ext method so have exposed just our `ExponentialBackoff` default as an internal fn (which cannot be const), along with a const reset timeout and re-implemented the function in `WatchStreamExt::default_backoff` referencing our parameters.
An alternative could be doing the defaulting in the generally opaque type that most users don't interact with:
but i think that doesn't really help much. we still end up with an implementation in
WatchStreamExt
that is almost as big (except without the internal imports) and it's an awkward inversion of utils depending on core stuff. I'd probably rather keep the backoff parameters somewhere prominent.