diff --git a/go.mod b/go.mod index e3ad8fbe34..5983492ab9 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 4625c96502..7864dab01d 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/pkg/router/httpTriggers.go b/pkg/router/httpTriggers.go index 542e503120..38d0e69dba 100644 --- a/pkg/router/httpTriggers.go +++ b/pkg/router/httpTriggers.go @@ -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" @@ -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, @@ -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) @@ -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() {