-
-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* implement backoff for watcher - for #577 Signed-off-by: clux <[email protected]> * move magic number into strategy Signed-off-by: clux <[email protected]> * expose backoff from watcher and semi-propagate into controller awkward. will write a comment Signed-off-by: clux <[email protected]> * potential abstraction Signed-off-by: clux <[email protected]> * another builder layer; allow eliding ListParams Signed-off-by: clux <[email protected]> * forgot to add file Signed-off-by: clux <[email protected]> * easy parts of code review Signed-off-by: clux <[email protected]> * rewrite as a helper (take N) jesus this stuff is hard. Signed-off-by: clux <[email protected]> * rename as suggested Signed-off-by: clux <[email protected]> * Reimplement watcher backoff as FSM (#720) * Fix clippy warnings Signed-off-by: Teo Klestrup Röijezon <[email protected]> * Reimplement watch backoff as FSM Signed-off-by: Teo Klestrup Röijezon <[email protected]> * Remove useless lifetime bounds Signed-off-by: Teo Klestrup Röijezon <[email protected]> * Silence clippy size warning Signed-off-by: Teo Klestrup Röijezon <[email protected]> * Silence clippy properly this time around Signed-off-by: Teo Klestrup Röijezon <[email protected]> * Split StreamBackoff into a separate utils module Signed-off-by: Teo Klestrup Röijezon <[email protected]> * Backoff tests Signed-off-by: Teo Klestrup Röijezon <[email protected]> * Add stream close test Signed-off-by: Teo Klestrup Röijezon <[email protected]> * remove backoff pin, fix docs Signed-off-by: clux <[email protected]> * newline Signed-off-by: clux <[email protected]> * Add `Backoff` wrapper that implements client-go's reset timer behaviour (#729) Signed-off-by: Teo Klestrup Röijezon <[email protected]> * use new reset backoff and replicate client-go reflector values Signed-off-by: clux <[email protected]> * fix node watcher example Signed-off-by: clux <[email protected]> * Use released `backoff` Signed-off-by: Teo Klestrup Röijezon <[email protected]> * Factor out default `Backoff` Signed-off-by: Teo Klestrup Röijezon <[email protected]> * Add note to `watcher` about backoff Signed-off-by: Teo Klestrup Röijezon <[email protected]> * Added backoff to Controller Signed-off-by: Teo Klestrup Röijezon <[email protected]> * Changelog Signed-off-by: Teo Klestrup Röijezon <[email protected]> * Revert `Observer` for now Signed-off-by: Teo Klestrup Röijezon <[email protected]> * The clippyman comes for us all, eventually And we must all pay our due respects, or pay the price. Signed-off-by: Teo Klestrup Röijezon <[email protected]> * Fix build warnings Signed-off-by: Teo Klestrup Röijezon <[email protected]> * remove backoff_watch Signed-off-by: clux <[email protected]> * doc tweaks Signed-off-by: clux <[email protected]> * sentence Signed-off-by: clux <[email protected]> * upgrading backoff is not actually breaking Signed-off-by: clux <[email protected]> Co-authored-by: Teo Klestrup Röijezon <[email protected]> Co-authored-by: Teo Klestrup Röijezon <[email protected]>
- Loading branch information
1 parent
155859b
commit 276719c
Showing
22 changed files
with
372 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
use jsonpath_lib; | ||
use k8s_openapi::api::core::v1::Pod; | ||
use kube::{ | ||
api::{Api, ListParams}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
use std::time::{Duration, Instant}; | ||
|
||
use backoff::{backoff::Backoff, Clock, SystemClock}; | ||
|
||
/// A [`Backoff`] wrapper that resets after a fixed duration has elapsed. | ||
pub struct ResetTimerBackoff<B, C = SystemClock> { | ||
backoff: B, | ||
clock: C, | ||
last_backoff: Option<Instant>, | ||
reset_duration: Duration, | ||
} | ||
|
||
impl<B: Backoff> ResetTimerBackoff<B> { | ||
pub fn new(backoff: B, reset_duration: Duration) -> Self { | ||
Self::new_with_custom_clock(backoff, reset_duration, SystemClock {}) | ||
} | ||
} | ||
|
||
impl<B: Backoff, C: Clock> ResetTimerBackoff<B, C> { | ||
fn new_with_custom_clock(backoff: B, reset_duration: Duration, clock: C) -> Self { | ||
Self { | ||
backoff, | ||
clock, | ||
last_backoff: None, | ||
reset_duration, | ||
} | ||
} | ||
} | ||
|
||
impl<B: Backoff, C: Clock> Backoff for ResetTimerBackoff<B, C> { | ||
fn next_backoff(&mut self) -> Option<Duration> { | ||
if let Some(last_backoff) = self.last_backoff { | ||
if self.clock.now() > last_backoff + self.reset_duration { | ||
tracing::debug!( | ||
?last_backoff, | ||
reset_duration = ?self.reset_duration, | ||
"Resetting backoff, since reset duration has expired" | ||
); | ||
self.backoff.reset(); | ||
} | ||
} | ||
self.last_backoff = Some(self.clock.now()); | ||
self.backoff.next_backoff() | ||
} | ||
|
||
fn reset(&mut self) { | ||
// Do not even bother trying to reset here, since `next_backoff` will take care of this when the timer expires. | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use backoff::{backoff::Backoff, Clock}; | ||
use tokio::time::advance; | ||
|
||
use super::ResetTimerBackoff; | ||
use crate::utils::stream_backoff::tests::LinearBackoff; | ||
use std::time::{Duration, Instant}; | ||
|
||
#[tokio::test] | ||
async fn should_reset_when_timer_expires() { | ||
tokio::time::pause(); | ||
let mut backoff = ResetTimerBackoff::new_with_custom_clock( | ||
LinearBackoff::new(Duration::from_secs(2)), | ||
Duration::from_secs(60), | ||
TokioClock, | ||
); | ||
assert_eq!(backoff.next_backoff(), Some(Duration::from_secs(2))); | ||
advance(Duration::from_secs(40)).await; | ||
assert_eq!(backoff.next_backoff(), Some(Duration::from_secs(4))); | ||
advance(Duration::from_secs(40)).await; | ||
assert_eq!(backoff.next_backoff(), Some(Duration::from_secs(6))); | ||
advance(Duration::from_secs(80)).await; | ||
assert_eq!(backoff.next_backoff(), Some(Duration::from_secs(2))); | ||
advance(Duration::from_secs(80)).await; | ||
assert_eq!(backoff.next_backoff(), Some(Duration::from_secs(2))); | ||
} | ||
|
||
struct TokioClock; | ||
|
||
impl Clock for TokioClock { | ||
fn now(&self) -> Instant { | ||
tokio::time::Instant::now().into_std() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.