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
Signed-off-by: Teo Klestrup Röijezon <teo@nullable.se>
@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 <sszynrae@gmail.com>

* move magic number into strategy

Signed-off-by: clux <sszynrae@gmail.com>

* expose backoff from watcher and semi-propagate into controller

awkward. will write a comment

Signed-off-by: clux <sszynrae@gmail.com>

* potential abstraction

Signed-off-by: clux <sszynrae@gmail.com>

* another builder layer; allow eliding ListParams

Signed-off-by: clux <sszynrae@gmail.com>

* forgot to add file

Signed-off-by: clux <sszynrae@gmail.com>

* easy parts of code review

Signed-off-by: clux <sszynrae@gmail.com>

* rewrite as a helper (take N)

jesus this stuff is hard.

Signed-off-by: clux <sszynrae@gmail.com>

* rename as suggested

Signed-off-by: clux <sszynrae@gmail.com>

* Reimplement watcher backoff as FSM (#720)

* Fix clippy warnings

Signed-off-by: Teo Klestrup Röijezon <teo@nullable.se>

* Reimplement watch backoff as FSM

Signed-off-by: Teo Klestrup Röijezon <teo@nullable.se>

* Remove useless lifetime bounds

Signed-off-by: Teo Klestrup Röijezon <teo@nullable.se>

* Silence clippy size warning

Signed-off-by: Teo Klestrup Röijezon <teo@nullable.se>

* Silence clippy properly this time around

Signed-off-by: Teo Klestrup Röijezon <teo@nullable.se>

* Split StreamBackoff into a separate utils module

Signed-off-by: Teo Klestrup Röijezon <teo@nullable.se>

* Backoff tests

Signed-off-by: Teo Klestrup Röijezon <teo@nullable.se>

* Add stream close test

Signed-off-by: Teo Klestrup Röijezon <teo@nullable.se>

* remove backoff pin, fix docs

Signed-off-by: clux <sszynrae@gmail.com>

* newline

Signed-off-by: clux <sszynrae@gmail.com>

* Add `Backoff` wrapper that implements client-go's reset timer behaviour (#729)

Signed-off-by: Teo Klestrup Röijezon <teo@nullable.se>

* use new reset backoff and replicate client-go reflector values

Signed-off-by: clux <sszynrae@gmail.com>

* fix node watcher example

Signed-off-by: clux <sszynrae@gmail.com>

* Use released `backoff`

Signed-off-by: Teo Klestrup Röijezon <teo@nullable.se>

* Factor out default `Backoff`

Signed-off-by: Teo Klestrup Röijezon <teo@nullable.se>

* Add note to `watcher` about backoff

Signed-off-by: Teo Klestrup Röijezon <teo@nullable.se>

* Added backoff to Controller

Signed-off-by: Teo Klestrup Röijezon <teo@nullable.se>

* Changelog

Signed-off-by: Teo Klestrup Röijezon <teo@nullable.se>

* Revert `Observer` for now

Signed-off-by: Teo Klestrup Röijezon <teo@nullable.se>

* 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 <teo@nullable.se>

* Fix build warnings

Signed-off-by: Teo Klestrup Röijezon <teo@nullable.se>

* remove backoff_watch

Signed-off-by: clux <sszynrae@gmail.com>

* doc tweaks

Signed-off-by: clux <sszynrae@gmail.com>

* sentence

Signed-off-by: clux <sszynrae@gmail.com>

* upgrading backoff is not actually breaking

Signed-off-by: clux <sszynrae@gmail.com>

Co-authored-by: Teo Klestrup Röijezon <teo.roijezon@stackable.de>
Co-authored-by: Teo Klestrup Röijezon <teo@nullable.se>
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