-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
951 finalize ratelimitpolicy v1beta3 #976
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #976 +/- ##
==========================================
+ Coverage 76.15% 76.24% +0.09%
==========================================
Files 111 111
Lines 8986 9050 +64
==========================================
+ Hits 6843 6900 +57
- Misses 1852 1855 +3
- Partials 291 295 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
|
f6df582
to
d7d3c3b
Compare
Signed-off-by: Eguzki Astiz Lezaun <[email protected]>
Signed-off-by: Eguzki Astiz Lezaun <[email protected]>
Signed-off-by: Eguzki Astiz Lezaun <[email protected]>
Signed-off-by: Eguzki Astiz Lezaun <[email protected]>
Signed-off-by: Eguzki Astiz Lezaun <[email protected]>
Signed-off-by: Eguzki Astiz Lezaun <[email protected]>
Signed-off-by: Eguzki Astiz Lezaun <[email protected]>
Signed-off-by: Eguzki Astiz Lezaun <[email protected]>
Signed-off-by: Eguzki Astiz Lezaun <[email protected]>
4769bca
to
c5fafcc
Compare
Signed-off-by: Eguzki Astiz Lezaun <[email protected]>
Signed-off-by: Eguzki Astiz Lezaun <[email protected]>
Signed-off-by: Eguzki Astiz Lezaun <[email protected]>
Signed-off-by: Eguzki Astiz Lezaun <[email protected]>
Signed-off-by: Eguzki Astiz Lezaun <[email protected]>
Signed-off-by: Eguzki Astiz Lezaun <[email protected]>
Signed-off-by: Eguzki Astiz Lezaun <[email protected]>
Signed-off-by: Eguzki Astiz Lezaun <[email protected]>
Signed-off-by: Eguzki Astiz Lezaun <[email protected]>
Nice work @eguzki love how the API is looking in those examples. |
@@ -46,6 +41,9 @@ const ( | |||
var ( | |||
RateLimitPolicyGroupKind = schema.GroupKind{Group: SchemeGroupVersion.Group, Kind: "RateLimitPolicy"} | |||
RateLimitPoliciesResource = SchemeGroupVersion.WithResource("ratelimitpolicies") | |||
// Top level predicate rules key starting with # to prevent conflict with limit names | |||
// TODO(eastizle): this coupling between limit names and rule IDs is a bad smell. Merging implementation should be enhanced. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can ID the rules however we want, as long as each rule has a unique ID. That was the case of limits as the only kind of rule before this PR. It made sense IDing the rule after the unique limit name rather than coming up with something different and possibly more opaque for the rule ID.
Now, we want to differentiate these two kinds of rules (conditions and limits) within a RateLimitPolicy spec. Similarly to how we handle this in the AuthPolicy (where there are 10 different kinds of rules), we can define different prefixes for each kind. E.g. conditions could be conditions#<condition-index>
and limits limits#<limit-name>
.
Sure, the new rule ID limits prefix would ultimately show up in the Limitador CR and wasm config as limit.limits_<limit-name>__<hash:rlp_ns/rlp_name>
. To avoida that, a trick that I think would work is setting the prefix in Rules()
/SetRules()
to limit.
and changing this line to identifier := ""
.
@@ -123,6 +121,13 @@ func (p *RateLimitPolicy) Rules() map[string]kuadrantv1.MergeableRule { | |||
rules := make(map[string]kuadrantv1.MergeableRule) | |||
policyLocator := p.GetLocator() | |||
|
|||
if len(p.Spec.Proper().When) > 0 { | |||
rules[RulesKeyTopLevelPredicates] = kuadrantv1.NewMergeableRule( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a single key for all conditions as if the conditions in a policy were a single rule will effectively cause the merging of policies to select one entire set or another (atomically). I.e., the two sets of conditions will not be merged into one.
Maybe that's what we want. If so, then I'd would recommend applying the same behavior to the AuthPolicy, which is not the case today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've chatted with @eguzki offline about #976 (comment).
We made a call together that the approach proposed by this PR is preferable than the behaviour implemented in the AuthPolicy. Merging conditions based on index position feels like dark magic and better avoiding it.
I will unblock this PR with the promise of the work on the AuthPolicy to copy the one here (i.e. the entire set of top-level when
conditions always treated as one single rule) will follow this one ASAP.
* Finalize ratelimitpolicy v1beta3 Signed-off-by: Eguzki Astiz Lezaun <[email protected]> * ratelimit_workflow_test.go: fix and add new unittests Signed-off-by: Eguzki Astiz Lezaun <[email protected]> * update helm charts· Signed-off-by: Eguzki Astiz Lezaun <[email protected]> * ratelimitpolicy v1beta3 counter expression Signed-off-by: Eguzki Astiz Lezaun <[email protected]> * fix predicate from HTTPRouteMatch Signed-off-by: Eguzki Astiz Lezaun <[email protected]> * fix e2e tests Signed-off-by: Eguzki Astiz Lezaun <[email protected]> * RLP Duration as GwAPI Signed-off-by: Eguzki Astiz Lezaun <[email protected]> * predicates as full object and window name for limit duration Signed-off-by: Eguzki Astiz Lezaun <[email protected]> * fix rebase issues Signed-off-by: Eguzki Astiz Lezaun <[email protected]> * ratelimitpolicy_types: fix typo in a comment Signed-off-by: Eguzki Astiz Lezaun <[email protected]> * move WhenCondition type to authpolicy type Signed-off-by: Eguzki Astiz Lezaun <[email protected]> * update bundle and fix e2e tests Signed-off-by: Eguzki Astiz Lezaun <[email protected]> * new rate limit policy doc Signed-off-by: Eguzki Astiz Lezaun <[email protected]> * fix e2e tests Signed-off-by: Eguzki Astiz Lezaun <[email protected]> * bundle update Signed-off-by: Eguzki Astiz Lezaun <[email protected]> * change tests to increase coverage Signed-off-by: Eguzki Astiz Lezaun <[email protected]> * limits reconciler needs to filter out top level rules Signed-off-by: Eguzki Astiz Lezaun <[email protected]> * no upperlimit for predicates and expressions strings Signed-off-by: Eguzki Astiz Lezaun <[email protected]> --------- Signed-off-by: Eguzki Astiz Lezaun <[email protected]>
What
Finalize ratelimitpolicy v1beta3. Basically, exposing CEL at RateLimitPolicy level to express predicates at top level and limit levels.
Updates applied
predicate
'spredicate
'swindow
in GEP-2257: Gateway API Duration Formatexpression
TODO:
Verification
Export the gateway hostname and port:
Verify the route works:
Enforce rate limiting on requests to the Toy Store API
Verify the rate limiting works by sending requests in a loop.
Up to 5 successful (
200 OK
) requests every 10 seconds toGET /cars
, then429 Too Many Requests
:Unlimited successful (
200 OK
) toGET /admin
:Check wasm plugin