Skip to content

Commit

Permalink
Add set-style rate-limiting capability - part 3 (#3893)
Browse files Browse the repository at this point in the history
* don't create empty ratelimits, export CustomStage so enterprise can create ratelimits
* changelog
  • Loading branch information
arianaw66 committed Nov 18, 2020
1 parent 55fb3bb commit 7c908dc
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 9 deletions.
6 changes: 6 additions & 0 deletions changelog/v1.6.0-beta12/set-rate-limiting.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
changelog:
- type: NON_USER_FACING
description: >
Minor updates to allow for set-style rate limiting.
issueLink: https://github.com/solo-io/gloo/issues/2695
resolvesIssue: false
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,23 @@ setDescriptors:
requestsPerUnit: 20
unit: MINUTE

It would also match the following setDescriptor which includes only a subset of the setActions enumerated:

setDescriptors:
- simpleDescriptors:
- key: account_id
rateLimit:
requestsPerUnit: 20
unit: MINUTE

It would even match the following setDescriptor.
Any setActions list would match this setDescriptor which has simpleDescriptors omitted entirely:

setDescriptors:
- rateLimit:
requestsPerUnit: 20
unit: MINUTE

```yaml
"actions": []ratelimit.api.solo.io.Action
"setActions": []ratelimit.api.solo.io.Action
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ require (
github.com/solo-io/protoc-gen-ext v0.0.9
github.com/solo-io/reporting-client v0.1.2
github.com/solo-io/skv2 v0.8.1
github.com/solo-io/solo-apis v0.0.0-20201103221621-bbe4f60f466d
github.com/solo-io/solo-apis v0.0.0-20201118222008-1b098636eb85
github.com/solo-io/solo-kit v0.13.14
github.com/solo-io/wasm/tools/wasme/pkg v0.0.0-20200922223809-7fff932e9e9a
github.com/spf13/afero v1.2.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1070,8 +1070,8 @@ github.com/solo-io/reporting-client v0.1.2/go.mod h1:FmBDzwc1zEwayCCrlP+1w7NcpM0
github.com/solo-io/skv2 v0.7.2/go.mod h1:08Hye4vNGdG+E3BlLS+gpCDjd9fXAbQzGPCSlsWfjSQ=
github.com/solo-io/skv2 v0.8.1 h1:M45iMM97a3z5pSRYxcw8hScmqYcP6+oFxrtjauos8Ms=
github.com/solo-io/skv2 v0.8.1/go.mod h1:Da9SOUuIlb61Fxi3E/aFFXjxzRAAvx34qglWrNg3wEQ=
github.com/solo-io/solo-apis v0.0.0-20201103221621-bbe4f60f466d h1:vYHs1At/VRlQfbnp3agZweAhx8ycUbPx4cTI6lozdJo=
github.com/solo-io/solo-apis v0.0.0-20201103221621-bbe4f60f466d/go.mod h1:wyrnIh/q2p7wCWq8ZSvIw5zJ3jpAp/dtWatk+SULCqk=
github.com/solo-io/solo-apis v0.0.0-20201118222008-1b098636eb85 h1:vbqfPIgEkutzvhPYxx3G++YoTHXCpzeFOTb5mYFTLpY=
github.com/solo-io/solo-apis v0.0.0-20201118222008-1b098636eb85/go.mod h1:wyrnIh/q2p7wCWq8ZSvIw5zJ3jpAp/dtWatk+SULCqk=
github.com/solo-io/solo-kit v0.13.8/go.mod h1:1cSoxO1Cgzn++03nnp5V1iGf0S45OLDTUmj70rD/+hY=
github.com/solo-io/solo-kit v0.13.9/go.mod h1:1cSoxO1Cgzn++03nnp5V1iGf0S45OLDTUmj70rD/+hY=
github.com/solo-io/solo-kit v0.13.14 h1:563vn7XCMpL6MsiAqJFGUG8VtaNKBCnX5b9mXUH85D0=
Expand Down
2 changes: 1 addition & 1 deletion projects/gloo/pkg/plugins/ratelimit/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const (
CustomDomain = "custom"
requestType = "both"

customStage = 1
CustomStage = 1
DefaultTimeout = 100 * time.Millisecond
)

Expand Down
12 changes: 7 additions & 5 deletions projects/gloo/pkg/plugins/ratelimit/raw_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@ import (
)

func generateEnvoyConfigForCustomFilter(ref core.ResourceRef, timeout *time.Duration, denyOnFail bool) *envoyratelimit.RateLimit {
return GenerateEnvoyConfigForFilterWith(ref, CustomDomain, customStage, timeout, denyOnFail)
return GenerateEnvoyConfigForFilterWith(ref, CustomDomain, CustomStage, timeout, denyOnFail)
}

func generateCustomEnvoyConfigForVhost(ctx context.Context, rlactions []*gloorl.RateLimitActions) []*envoyvhostratelimit.RateLimit {
var ret []*envoyvhostratelimit.RateLimit
for _, rlaction := range rlactions {
rl := &envoyvhostratelimit.RateLimit{
Stage: &wrappers.UInt32Value{Value: customStage},
if len(rlaction.Actions) != 0 {
rl := &envoyvhostratelimit.RateLimit{
Stage: &wrappers.UInt32Value{Value: CustomStage},
}
rl.Actions = ConvertActions(ctx, rlaction.Actions)
ret = append(ret, rl)
}
rl.Actions = ConvertActions(ctx, rlaction.Actions)
ret = append(ret, rl)
}
return ret
}
Expand Down

0 comments on commit 7c908dc

Please sign in to comment.