Skip to content

Commit

Permalink
Merge pull request #396 from Kuadrant/cel_predicates
Browse files Browse the repository at this point in the history
🔥 conditions et at, replacing with proper `cel::Predicate`s & `::Expression`s
  • Loading branch information
alexsnaps authored Dec 6, 2024
2 parents cb9f572 + 8941898 commit bf6a26f
Show file tree
Hide file tree
Showing 27 changed files with 1,508 additions and 1,344 deletions.
178 changes: 178 additions & 0 deletions Cargo.lock

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

19 changes: 0 additions & 19 deletions doc/migrations/conditions.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,3 @@ case `foo` was the identifier of the variable, while `bar` was the value to eval
after the operator `==` would be equally important. SO that `foo == bar` would test for a `foo ` variable being equal
to ` bar` where the trailing whitespace after the identifier, and the one prefixing the value, would have been
evaluated.

## Server binary users

The server still allows for the deprecated syntax, but warns about its usage. You can easily migrate your limits file,
using the following command:

```commandline
limitador-server --validate old_limits.yaml > updated_limits.yaml
```

Which should output `Deprecated syntax for conditions corrected!` to `stderr` while `stdout` would be the limits using
the new syntax. It is recommended you manually verify the resulting `LIMITS_FILE`.


## Crate users

A feature `lenient_conditions` has been added, which lets you use the syntax used in previous version of the crate.
The function `limitador::limit::check_deprecated_syntax_usages_and_reset()` lets you verify if the deprecated syntax
has been used as `limit::Limit`s are created with their condition strings using the deprecated syntax.
2 changes: 1 addition & 1 deletion doc/server/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Here is an example of such a limit definition:
max_value: 10
seconds: 60
conditions:
- "req.method == 'GET'"
- "req_method == 'GET'"
variables:
- user_id
```
Expand Down
2 changes: 1 addition & 1 deletion limitador-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ distributed_storage = ["limitador/distributed_storage"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
limitador = { path = "../limitador", features = ['lenient_conditions'] }
limitador = { path = "../limitador" }
tokio = { version = "1", features = ["full"] }
thiserror = "2"
tonic = "0.12.3"
Expand Down
4 changes: 2 additions & 2 deletions limitador-server/examples/envoy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ static_resources:
rate_limits:
- stage: 0
actions:
- {request_headers: {header_name: "userid", descriptor_key: "user_id"}}
- {request_headers: {header_name: ":method", descriptor_key: "req.method"}}
- { request_headers: { header_name: "userid", descriptor_key: "user_id" } }
- { request_headers: { header_name: ":method", descriptor_key: "descriptors[0]['method']" } }
http_filters:
- name: envoy.filters.http.ratelimit
typed_config:
Expand Down
2 changes: 1 addition & 1 deletion limitador-server/examples/limits.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
max_value: 5
seconds: 60
conditions:
- "req.method == 'POST'"
- "descriptors[0]['req.method'] == 'POST'"
variables:
- user_id
12 changes: 6 additions & 6 deletions limitador-server/sandbox/limits.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
max_value: 10
seconds: 60
conditions:
- "req.method == 'GET'"
- "req.path != '/json'"
- "descriptors[0]['req.method'] == 'GET'"
- "descriptors[0]['req.path'] != '/json'"
variables: []
- namespace: test_namespace
max_value: 5
seconds: 60
conditions:
- "req.method == 'POST'"
- "req.path != '/json'"
- "descriptors[0]['req.method'] == 'POST'"
- "descriptors[0]['req.path'] != '/json'"
variables: []
- namespace: test_namespace
max_value: 50000
seconds: 10
conditions:
- "req.method == 'GET'"
- "req.path == '/json'"
- "descriptors[0]['req.method'] == 'GET'"
- "descriptors[0]['req.path'] == '/json'"
variables: []
Loading

0 comments on commit bf6a26f

Please sign in to comment.