-
Notifications
You must be signed in to change notification settings - Fork 105
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 support for applying jitter when requeuing resources after reconcile #523
Conversation
pkg/reconciler/managed/reconciler.go
Outdated
@@ -1073,16 +1087,18 @@ func (r *Reconciler) Reconcile(ctx context.Context, req reconcile.Request) (resu | |||
} | |||
} | |||
|
|||
reconcileAfter := r.pollInterval + time.Duration((rand.Float64()-0.5)*2*float64(r.pollJitter)) //#nosec G404 -- no need for secure randomness |
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.
To provide more flexibility to provider developers it might make sense to not hardcode the jitter algorithm and instead provide a hook via a delegate that can be passed via an option:
reconcileAfter := r.pollInterval + time.Duration((rand.Float64()-0.5)*2*float64(r.pollJitter)) //#nosec G404 -- no need for secure randomness | |
reconcileAfter := r.modifyRequeueAfter(managed, r.pollInterval) |
In the future this might also be a way for providers to individually decide on the requeue time for individual resources.
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.
How do you feel about doing both, and having the modifyRequeueAfter
hook accept both the configured poll interval and computed jitter (with the default implementation being to add them together)?
I think the library should strongly encourage provider developers to include support for jitter as a relatively well-establish best practice (whether they hardcode the amount or expose a flag), rather than it being something they each have to remember to do when they discover the hook exists?
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.
I am not opposed to the Jitter itself or the formular it is calculated with. I also think it makes sense to provide a default Jitter with the NewReconciler
. I just would prefer to have the Jitter algorithm (or any kind of "delay" mechanic) not directly implemented within the reconciler but provide it via some form of plugin mechanism.
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.
What do you think of this approach, with the WithJitter option implemented as a WithPollIntervalHook?
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.
Looks good to me. However, is support for multiple hooks really necessary? I think it makes the hook mechanic more complex then it needs to be. And I spontaneously cannot think of a scenario where two hooks are dependent on each other (unlike overwriting).
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.
The main situation I'm thinking of is letting somebody do resource-based customisation, and have jitter applied on top, without them having to write(/copy-and-paste) their own jitter logic. Happy to change it to a single hook if you think that's insufficient justification.
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.
If you would have multiple hooks they would be called for every resource anyway and since it is all inside a single controller I think one hook should be fine. If people want to apply resource-based jitter then I assume it would suffice if they only implement one hook that can decide on it.
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.
Okay, switched it to a single hook
b5a3b77
to
1b1b951
Compare
Signed-off-by: Samuel Littley <[email protected]>
Signed-off-by: Samuel Littley <[email protected]>
Signed-off-by: Samuel Littley <[email protected]>
Signed-off-by: Samuel Littley <[email protected]>
0c6dd7e
to
188f2b6
Compare
Signed-off-by: Samuel Littley <[email protected]>
Also, can this be released as a patch on v1.13, or will it wait for v1.14 (which looks like it's not going to be released until end of October based on https://github.com/crossplane/crossplane/milestone/17?) |
I can't merge since I am not a maintainer - only a reviewer. |
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.
Looking good! Thanks for your contribution @toastwaffle!
Description of your changes
Adds a WithPollJitter option to managed.Reconciler to support adding jitter to reconcile delay. Jitter defaults to 0, meaning this has no behavioural change unless the WithPollJitter option is set.
Fixes #312
I have:
make reviewable test
to ensure this PR is ready for review.How has this code been tested
Ran tests in pkg/reconciler/managed/reconciler_test.go