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

Add Backoff wrapper that implements client-go's reset timer behaviour #729

Merged

Conversation

nightkr
Copy link
Member

@nightkr nightkr commented Nov 22, 2021

See #703 (comment)

Not sure how we want to expose this. Feels like kube-runtime is starting to pick up on a lot of utility stuff that doesn't have much to do with Kubernetes.

@nightkr nightkr requested a review from clux November 22, 2021 15:05
@nightkr nightkr force-pushed the backoff-watcher-/reset-duration branch from d8ad2fa to bb273ce Compare November 22, 2021 15:06
assert_eq!(backoff.next_backoff(), Some(Duration::from_secs(2)));
}

struct TokioClock;
Copy link
Member Author

Choose a reason for hiding this comment

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

Need a pausable clock source for tests.

Copy link
Member

Choose a reason for hiding this comment

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

Great tests once again.


use backoff::{backoff::Backoff, Clock, SystemClock};

/// A [`Backoff`] wrapper that resets after a fixed duration has elapsed.
Copy link
Member

@clux clux Nov 22, 2021

Choose a reason for hiding this comment

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

Think this is great. I was initially going to suggest

/// A [`Backoff`] wrapper that resets after a fixed duration has elapsed
///
/// This is used to reduce load during upstream unhealthiness and is similar to
/// [apimachinery's backoffmanager](https://github.com/kubernetes/apimachinery/blob/7149480564b7d40046f19040efa20171b49059ae/pkg/util/wait/wait.go#L310-L349).

but will leave a comment for that in the place where we instantiate it in Observer wrapping ExponentialBackoff.

what you have here is a more generic building block.

assert_eq!(backoff.next_backoff(), Some(Duration::from_secs(2)));
}

struct TokioClock;
Copy link
Member

Choose a reason for hiding this comment

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

Great tests once again.

@clux
Copy link
Member

clux commented Nov 22, 2021

As for where to put this; maybe we should try to upstream this into backoff long term?

@clux
Copy link
Member

clux commented Nov 22, 2021

other possibilities could be to:

  • fork and tweak backoff (should they fail to release your changes in a month)
  • put this under kube-core (the analogue of this sits inside apimachinery after all)

@clux clux merged commit be2dc1c into kube-rs:backoff-watcher Nov 22, 2021
clux added a commit that referenced this pull request Dec 21, 2021
* 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]>
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.

2 participants