Skip to content

Commit

Permalink
Add sync triggers debounce (#2631)
Browse files Browse the repository at this point in the history
  • Loading branch information
angelini committed Nov 22, 2022
1 parent 9c4fc4a commit 82d066b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions go.mod
Expand Up @@ -4,6 +4,7 @@ go 1.19

require (
github.com/Shopify/sarama v1.37.2
github.com/bep/debounce v1.2.1
github.com/dchest/uniuri v1.2.0
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815
github.com/dustin/go-humanize v1.0.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Expand Up @@ -119,6 +119,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bep/debounce v1.2.1 h1:v67fRdBA9UQu2NhLFXrSg0Brw7CexQekrBwDMM8bzeY=
github.com/bep/debounce v1.2.1/go.mod h1:H8yggRPQKLUhUoqrJC1bO2xNya7vanpDl7xR3ISbCJ0=
github.com/blend/go-sdk v1.20220112.5 h1:M1H3KB++HyPAek31WH2HNut1Xg1SI7LyT9giNE2fcPQ=
github.com/blend/go-sdk v1.20220112.5/go.mod h1:STLiO8ZA8doHtRV7QfW2mXgH/8U+85GHY9ge3phM3dY=
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
Expand Down
7 changes: 6 additions & 1 deletion pkg/router/httpTriggers.go
Expand Up @@ -22,6 +22,7 @@ import (
"strings"
"time"

"github.com/bep/debounce"
"github.com/gorilla/mux"
"go.uber.org/zap"
kerrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -60,6 +61,7 @@ type HTTPTriggerSet struct {
isDebugEnv bool
svcAddrUpdateThrottler *throttler.Throttler
unTapServiceTimeout time.Duration
syncDebouncer func(func())
}

func makeHTTPTriggerSet(logger *zap.Logger, fmap *functionServiceMap, fissionClient versioned.Interface,
Expand All @@ -77,6 +79,7 @@ func makeHTTPTriggerSet(logger *zap.Logger, fmap *functionServiceMap, fissionCli
isDebugEnv: isDebugEnv,
svcAddrUpdateThrottler: actionThrottler,
unTapServiceTimeout: unTapServiceTimeout,
syncDebouncer: debounce.New(time.Millisecond * 20),
}
httpTriggerSet.triggerInformer = utils.GetInformersForNamespaces(fissionClient, time.Minute*30, fv1.HttpTriggerResource)
httpTriggerSet.funcInformer = utils.GetInformersForNamespaces(fissionClient, time.Minute*30, fv1.FunctionResource)
Expand Down Expand Up @@ -368,7 +371,9 @@ func (ts *HTTPTriggerSet) runInformer(ctx context.Context, informer map[string]k
}

func (ts *HTTPTriggerSet) syncTriggers() {
ts.updateRouterRequestChannel <- struct{}{}
ts.syncDebouncer(func() {
ts.updateRouterRequestChannel <- struct{}{}
})
}

func (ts *HTTPTriggerSet) updateRouter() {
Expand Down

0 comments on commit 82d066b

Please sign in to comment.