Skip to content

Commit

Permalink
feat: trigger rate limit. Closes: #1087 (#1318)
Browse files Browse the repository at this point in the history
* feat: trigger rate limit. Closes: #1087

Signed-off-by: Derek Wang <[email protected]>

* ok

Signed-off-by: Derek Wang <[email protected]>

* lint

Signed-off-by: Derek Wang <[email protected]>
  • Loading branch information
whynowy authored Aug 23, 2021
1 parent f8825b8 commit 4ba6543
Show file tree
Hide file tree
Showing 14 changed files with 798 additions and 283 deletions.
17 changes: 17 additions & 0 deletions api/openapi-spec/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions api/sensor.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 64 additions & 0 deletions api/sensor.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions docs/sensors/more-about-sensors-and-triggers.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,17 @@ spec:
# Defaults to "1"
jitter: 2
```
## Trigger Rate Limit
There's no rate limit for a trigger unless you configure the spec as following:
```yaml
spec:
triggers:
- rateLimit:
# Second, Minute or Hour, defaults to Second
unit: Second
# Requests per unit
requestsPerUnit: 20
```
2 changes: 1 addition & 1 deletion eventbus/driver/nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func (n *natsStreaming) processEventSourceMsg(m *stan.Msg, msgHolder *eventSourc
}
log.Debugf("Triggering actions for client %s", n.clientID)

go action(messages)
action(messages)

msgHolder.reset(depName)
msgHolder.ackAndCache(m, event.ID())
Expand Down
9 changes: 5 additions & 4 deletions eventsources/sources/bitbucketserver/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ package bitbucketserver
import (
"context"
"encoding/json"
bitbucketv1 "github.com/gfleury/go-bitbucket-v1"
"github.com/mitchellh/mapstructure"
"io/ioutil"
"math/rand"
"net/http"
"reflect"
"time"

bitbucketv1 "github.com/gfleury/go-bitbucket-v1"
"github.com/mitchellh/mapstructure"

"github.com/argoproj/argo-events/common"
"github.com/argoproj/argo-events/common/logging"
"github.com/argoproj/argo-events/eventsources/common/webhook"
Expand Down Expand Up @@ -304,7 +305,7 @@ func (router *Router) CreateBitbucketWebhook(ctx context.Context, bitbucketConfi
}
router.hookID = createdHook.ID

logger.With("hook-id", createdHook.ID).Info("hook succesfully registered")
logger.With("hook-id", createdHook.ID).Info("hook successfully registered")

return nil
}
Expand All @@ -319,7 +320,7 @@ func (router *Router) CreateBitbucketWebhook(ctx context.Context, bitbucketConfi
return errors.Errorf("failed to update webhook. err: %+v", err)
}

logger.With("hook-id", existingHook.ID).Info("hook succesfully updated")
logger.With("hook-id", existingHook.ID).Info("hook successfully updated")
}

return nil
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ require (
github.com/tidwall/gjson v1.7.5
github.com/tidwall/sjson v1.1.1
github.com/xanzy/go-gitlab v0.50.2
go.uber.org/ratelimit v0.2.0
go.uber.org/zap v1.17.0
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129 h1:MzBOUgng9orim59UnfUTLRjMpd09C5uEVQ6RPGeCaVI=
github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129/go.mod h1:rFgpPQZYZ8vdbc+48xibu8ALc3yeyd64IhHS+PU6Yyg=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
Expand Down Expand Up @@ -1010,6 +1012,8 @@ go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/ratelimit v0.2.0 h1:UQE2Bgi7p2B85uP5dC2bbRtig0C+OeNRnNEafLjsLPA=
go.uber.org/ratelimit v0.2.0/go.mod h1:YYBV4e4naJvhpitQrWJu1vCpgB7CboMe0qhltKt6mUg=
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
go.uber.org/zap v1.8.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
Expand Down
Loading

0 comments on commit 4ba6543

Please sign in to comment.