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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

alexsnaps
Copy link
Member

fix #385

limitador/src/counter.rs Outdated Show resolved Hide resolved
}

impl Context<'_> {
pub(crate) fn new(limit: &Limit, root: String, values: &HashMap<String, String>) -> Self {
Copy link
Member Author

Choose a reason for hiding this comment

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

So, this root relates to this point from #385

Should the descriptor(s) and their entries be first class citizens and have their own root binding?

Right now, limit binds the limit info (id & name), I was thinking that possibly we could have some root binding for the descriptor entries (e.g. descriptor), which... could then also be a List and hold multiple of them and all their entries: descriptor[0].foo == '1' && descriptor[1].bar != 'bad'... See this issue here, so it'd probably be a List<HashMap<String, String>> as well then...

Whatever the case, who would set that root namespace/binding to something? I'd expect it to be the server code... but that then creates further issues in the (de)serialization paths... Also, the logic of resolving the Limit.variables() would need to account for that (along side what happens in the wasm-shim's code to lazily resolve attributes from the host).

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, doing so would tie releasing this with a release of the kuadrant-operator... right now, this isn't necessary.

@alexsnaps alexsnaps marked this pull request as ready for review November 27, 2024 20:14
@alexsnaps alexsnaps requested a review from a team November 27, 2024 20:14
@alexsnaps
Copy link
Member Author

Pretty big PR, but I tried to keep a somewhat meaningful history and broke it down according to the #385
Thanks... and... sorry 🤦

@@ -333,6 +334,15 @@ fn encode_counter_to_key(counter: &Counter) -> Vec<u8> {
}

fn encode_limit_to_key(limit: &Limit) -> Vec<u8> {
let counter = Counter::new(limit.clone(), HashMap::default());
// fixme this is broken!
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 has always been broken... and will need revisiting! But we can't just fake a the variables values like this (and they were simply left empty before, but this won't work now, as they'd fail resolution. I could "just" use the new Counter::resolved_vars, but that would just hide the problem a little more again.

Comment on lines +151 to +167
let var = "timestamp(ts).getHours()";
let limit = Limit::new(
"",
10,
60,
Vec::default(),
[var.try_into().expect("failed parsing!")],
);
let counter = Counter::new(
limit,
HashMap::from([("ts".to_string(), "2019-10-12T13:20:50.52Z".to_string())]),
)
.expect("failed creating counter");
assert_eq!(
counter.set_variables.get(var),
Some("13".to_string()).as_ref()
);
Copy link
Member Author

Choose a reason for hiding this comment

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

So I guess this is now new...

Signed-off-by: Alex Snaps <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Ready For Review
Development

Successfully merging this pull request may close these issues.

🔥 limit::conditions and have Conditions be proper CEL Predicates
1 participant