Skip to content

Commit

Permalink
Remove data from DefaultBackoffBuilder
Browse files Browse the repository at this point in the history
Signed-off-by: Natalie Klestrup Röijezon <[email protected]>
  • Loading branch information
nightkr committed Nov 28, 2024
1 parent 656c270 commit 6a0ee68
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
2 changes: 1 addition & 1 deletion kube-runtime/src/utils/watch_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub trait WatchStreamExt: Stream {
where
Self: TryStream + Sized,
{
self.backoff(DefaultBackoffBuilder::default())
self.backoff(DefaultBackoffBuilder)
}

/// Apply a specific [`BackoffBuilder`] policy to a [`Stream`] using [`StreamBackoff`]
Expand Down
42 changes: 19 additions & 23 deletions kube-runtime/src/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -890,38 +890,34 @@ pub fn watch_object<K: Resource + Clone + DeserializeOwned + Debug + Send + 'sta
/// and should not be considered stable.
///
/// This struct implements [`Backoff`] and is the default strategy used
/// when calling `WatchStreamExt::default_backoff`. If you need to create
/// this manually then [`DefaultBackoff::default`] can be used.
#[derive(Debug, Clone)]
pub struct DefaultBackoffBuilder(Strategy);
type Strategy = ResetTimerBackoffBuilder<backon::ExponentialBuilder>;
/// when calling `WatchStreamExt::default_backoff`.
#[derive(Debug, Clone, Default)]
pub struct DefaultBackoffBuilder;

/// See [`DefaultBackoffBuilder`].
#[derive(Debug)]
pub struct DefaultBackoff(<Strategy as BackoffBuilder>::Backoff);

impl Default for DefaultBackoffBuilder {
fn default() -> Self {
Self(ResetTimerBackoffBuilder::new(
backon::ExponentialBuilder::default()
.with_min_delay(Duration::from_millis(800))
.with_max_delay(Duration::from_secs(30))
// .with_jitter() isn't quite a 1:1 match to randomization factor, it always *adds* 0..min_delay, vs multiplying
// the final delay by +-factor
.with_jitter()
// .with_randomization_factor(1.0)
.with_factor(2.0)
.without_max_times(),
Duration::from_secs(120),
))
}
}
type Strategy = ResetTimerBackoffBuilder<backon::ExponentialBuilder>;

impl BackoffBuilder for DefaultBackoffBuilder {
type Backoff = DefaultBackoff;

fn build(self) -> Self::Backoff {
DefaultBackoff(self.0.build())
DefaultBackoff(
ResetTimerBackoffBuilder::new(
backon::ExponentialBuilder::default()
.with_min_delay(Duration::from_millis(800))
.with_max_delay(Duration::from_secs(30))
// .with_jitter() isn't quite a 1:1 match to randomization factor, it always *adds* 0..min_delay, vs multiplying
// the final delay by +-factor
.with_jitter()
// .with_randomization_factor(1.0)
.with_factor(2.0)
.without_max_times(),
Duration::from_secs(120),
)
.build(),
)
}
}

Expand Down

0 comments on commit 6a0ee68

Please sign in to comment.