Skip to content

Commit

Permalink
worker: run doWork at fixed rate
Browse files Browse the repository at this point in the history
Currently controller waits for `pollingInterval` after each `doWork` run that takes `W` time long.
Work rate and metrics counter change rate is therefore equal to `1 / (pollingInterval + W)`
which makes it hard to configure alerts based on the counter change rate thresholds due to unknown `W`.

This change runs controller work cycle at fixed rate of `1 / pollingInterval`.

For the existing deployments the side effect would be reduced work cycle and increased API request rates,
e.g. for `W` of 15s and default `pollingInterval` of 30s the work cycle is reduced from 45s to 30s (-33%).

Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
  • Loading branch information
AlexanderYastrebov committed May 10, 2022
1 parent 7da0ab3 commit ab03e92
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ func startPolling(
pollingInterval time.Duration,
globalWAFACL string,
) {
ticker := time.NewTicker(pollingInterval)
defer ticker.Stop()
for {
if errs := doWork(certsProvider, certsPerALB, certTTL, awsAdapter, kubeAdapter, globalWAFACL).Errors(); len(errs) > 0 {
for _, err := range errs {
Expand All @@ -246,9 +248,9 @@ func startPolling(
}
firstRun = false

log.Debugf("Start polling sleep %s", pollingInterval)
select {
case <-time.After(pollingInterval):
case now := <-ticker.C:
log.Debugf("Starting controller cycle at %v", now)
case <-ctx.Done():
return
}
Expand Down

0 comments on commit ab03e92

Please sign in to comment.