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 13 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
2 changes: 1 addition & 1 deletion limitador-server/examples/envoy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static_resources:
- 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: ":method", descriptor_key: "req_method" } }
alexsnaps marked this conversation as resolved.
Show resolved Hide resolved
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'"
- "req_method == 'POST'"
variables:
- user_id
8 changes: 4 additions & 4 deletions limitador-server/sandbox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ bin/grpcurl -plaintext -d @ 127.0.0.1:18081 envoy.service.ratelimit.v3.RateLimit
{
"entries": [
{
"key": "req.method",
"key": "req_method",
"value": "POST"
},
{
"key": "req.path",
"key": "req_path",
"value": "/"
}
]
Expand All @@ -125,11 +125,11 @@ while :; do bin/grpcurl -plaintext -d @ 127.0.0.1:18081 envoy.service.ratelimit.
{
"entries": [
{
"key": "req.method",
"key": "req_method",
"value": "POST"
},
{
"key": "req.path",
"key": "req_path",
"value": "/"
}
]
Expand Down
4 changes: 2 additions & 2 deletions limitador-server/sandbox/envoy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ static_resources:
- actions:
- request_headers:
header_name: :method
descriptor_key: req.method
descriptor_key: req_method
- request_headers:
header_name: :path
descriptor_key: req.path
descriptor_key: req_path
http_filters:
- name: envoy.filters.http.ratelimit
typed_config:
Expand Down
4 changes: 2 additions & 2 deletions limitador-server/sandbox/envoy2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ static_resources:
- actions:
- request_headers:
header_name: :method
descriptor_key: req.method
descriptor_key: req_method
- request_headers:
header_name: :path
descriptor_key: req.path
descriptor_key: req_path
http_filters:
- name: envoy.filters.http.ratelimit
typed_config:
Expand Down
Loading
Loading