Skip to content

job: Add debouncing trigger#7

Merged
joamaki merged 2 commits intocilium:mainfrom
pippolo84:pr/pippolo84/debounce
Aug 26, 2024
Merged

job: Add debouncing trigger#7
joamaki merged 2 commits intocilium:mainfrom
pippolo84:pr/pippolo84/debounce

Conversation

@pippolo84
Copy link
Copy Markdown
Member

The current Trigger implementation does not allow folding multiple requests over a time interval. In the cilium codebase, this feature is available in the "github.com/cilium/cilium/pkg/trigger" package (see cilium/cilium#32973 (comment) as an example) but lacks the benefits of the hive integration.

The PR adds the ability to specify a debounce interval to a timer trigger. Doing so, multiple trigger requests over the debounce interval are folded and the trigger is called just once. A debouncing trigger can work with:

  • a timer with a zero interval: in this case the job runs only when explicitly requested, through a call to its trigger
  • a timer with a non-zero interval: in this case the job runs also when the internal timer ticks, and the trigger is updated to account for this run

The job metrics interface is extended to make the trigger statistics available to the consumers. Right now, the trigger exports the latency between the first trigger and the actual job run, alongside the number of folded triggers in a debounce interval.

Notes about alternative implementations

  1. a new job type to implement the debouncing trigger behavior

What I dislike about this approach is the possible confusion around the already existent WithTrigger option for the timer job and the new trigger job. This could have been avoided removing the trigger option for the timer, but apart from breaking the package public interface with a non backward compatible change, it would have removed a nice feature of the Timer job.

Overall, the changes needed to implement the new semantic seem not too difficult and consistent, so I think extending the timer is better.

@pippolo84 pippolo84 requested a review from joamaki June 19, 2024 10:55
Comment thread job/timer.go Outdated
Add WithDebounce functional option to the timer job trigger.  This
allows to fold multiple triggers over the specified interval.  Also, it
is now possible to have a timer job with a zero interval, that runs its
function only when explicitly triggered.

This replicates the behavior of the github.com/cilium/cilium/pkg/trigger
package in the Cilium codebase, making the same semantic available
within a job from the hive framework.

Note that the debounce is striclty tied to the trigger and does not
affect the behavior of the timer job when the internal timer expires. In
that case, the job is run without taking into account the debounce
interval.

Signed-off-by: Fabio Falzoi <fabio.falzoi@isovalent.com>
Add support for reporting trigger statistics in job related metrics.
Specifically, the trigger reports the latency between the first trigger
and the next execution of the function, alongside the number of
coalesced triggers.

Signed-off-by: Fabio Falzoi <fabio.falzoi@isovalent.com>
@pippolo84 pippolo84 force-pushed the pr/pippolo84/debounce branch from 780df3d to 0be55ca Compare August 26, 2024 13:51
@pippolo84 pippolo84 requested a review from a team as a code owner August 26, 2024 13:51
@pippolo84 pippolo84 requested review from derailed and removed request for a team August 26, 2024 13:51
Copy link
Copy Markdown

@derailed derailed left a comment

Choose a reason for hiding this comment

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

@pippolo84 Nice work!

@joamaki joamaki merged commit af1b4bf into cilium:main Aug 26, 2024
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.

3 participants