File tree 5 files changed +22
-1
lines changed
5 files changed +22
-1
lines changed Original file line number Diff line number Diff line change 1
1
package convoy
2
2
3
+ import "time"
4
+
3
5
const (
4
6
HttpPost HttpMethod = "POST"
5
7
)
@@ -10,3 +12,14 @@ const (
10
12
Monthly
11
13
Yearly
12
14
)
15
+
16
+ const (
17
+ // With this Convoy will not process more than 3000
18
+ // concurrent requests per minute. We use github.com/go-chi/httprate
19
+ // which uses a sliding window algorithm, so we should be fine :)
20
+ // TODO(subomi): We need to configure rate limiting to be per
21
+ // client as well as implement distributed limiting backed by
22
+ // a distributed key value store.
23
+ RATE_LIMIT = 5000
24
+ RATE_LIMIT_DURATION = 1 * time .Minute
25
+ )
Original file line number Diff line number Diff line change 1
1
// Package docs GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
2
2
// This file was generated by swaggo/swag at
3
- // 2021-10-26 23:11:32.542301 +0100 WAT m=+26.721756418
3
+ // 2021-10-28 18:49:28.999858 +0100 WAT m=+27.284431293
4
4
package docs
5
5
6
6
import (
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ require (
9
9
github.com/getsentry/sentry-go v0.11.0
10
10
github.com/ghodss/yaml v1.0.0
11
11
github.com/go-chi/chi/v5 v5.0.3
12
+ github.com/go-chi/httprate v0.5.2 // indirect
12
13
github.com/go-chi/render v1.0.1
13
14
github.com/go-redis/redis/v8 v8.11.4
14
15
github.com/gobeam/mongo-go-pagination v0.0.7
Original file line number Diff line number Diff line change @@ -105,6 +105,8 @@ github.com/gin-gonic/gin v1.4.0/go.mod h1:OW2EZn3DO8Ln9oIKOvM++LBO+5UPHJJDH72/q/
105
105
github.com/go-check/check v0.0.0-20180628173108-788fd7840127 /go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98 =
106
106
github.com/go-chi/chi/v5 v5.0.3 h1:khYQBdPivkYG1s1TAzDQG1f6eX4kD2TItYVZexL5rS4 =
107
107
github.com/go-chi/chi/v5 v5.0.3 /go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8 =
108
+ github.com/go-chi/httprate v0.5.2 h1:pynJZu4jbSSHFRjpbT7EJJf8b9qt2CLZnqqKy0F+jH4 =
109
+ github.com/go-chi/httprate v0.5.2 /go.mod h1:kYR4lorHX3It9tTh4eTdHhcF2bzrYnCrRNlv5+IBm2M =
108
110
github.com/go-chi/render v1.0.1 h1:4/5tis2cKaNdnv9zFLfXzcquC9HbeZgCnxGnKrltBS8 =
109
111
github.com/go-chi/render v1.0.1 /go.mod h1:pq4Rr7HbnsdaeHagklXub+p6Wd16Af5l9koip1OvJns =
110
112
github.com/go-errors/errors v1.0.1 h1:LUHzmkK3GUKUrL/1gfBUxAHzcev3apQlezX/+O7ma6w =
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import (
14
14
"github.com/frain-dev/convoy/queue"
15
15
16
16
"github.com/go-chi/chi/v5/middleware"
17
+ "github.com/go-chi/httprate"
17
18
"github.com/prometheus/client_golang/prometheus"
18
19
"github.com/prometheus/client_golang/prometheus/promhttp"
19
20
log "github.com/sirupsen/logrus"
@@ -52,6 +53,10 @@ func buildRoutes(app *applicationHandler) http.Handler {
52
53
53
54
// Public API.
54
55
router .Route ("/api" , func (v1Router chi.Router ) {
56
+
57
+ // rate limit all requests.
58
+ v1Router .Use (httprate .LimitAll (convoy .RATE_LIMIT , convoy .RATE_LIMIT_DURATION ))
59
+
55
60
v1Router .Route ("/v1" , func (r chi.Router ) {
56
61
r .Use (middleware .AllowContentType ("application/json" ))
57
62
r .Use (jsonResponse )
You can’t perform that action at this time.
0 commit comments