Skip to content
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

🔥 conditions et at, replacing with proper cel::Predicates & ::Expressions #396

Merged
merged 20 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'"
Comment on lines +20 to +21
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now a breaking change obviously...
We could tell the server to not do that tho. But this is the only way I can think of to support multiple RateLimitDescriptor coming in from envoy, as well as the fact that each of their entries are String, String... i.e. any valid utf-8 string, which for the key has to be exposed as a Map<String, _> somehow.

For Kuadrant tho, we can now use the limit.id == '3f5e80af-1056-4349-bb84-c8010f34ecbb' if we'd wanted (and wire the id field of the Limit itself in the config)... eventually this semantic could then be optimized for

variables: []
Loading
Loading