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

Re-enabled lenient mode #110

Merged
merged 3 commits into from
Sep 1, 2022
Merged

Re-enabled lenient mode #110

merged 3 commits into from
Sep 1, 2022

Conversation

alexsnaps
Copy link
Member

@alexsnaps alexsnaps commented Aug 29, 2022

This re-adds the support for the "deprecated"/old syntax for conditions:

  • as a feature in the crate
  • that the server enables, and checks whether some condition did use the deprecated syntax while parsing the config file, and possibly warns the user (despite being logged at ERROR level, as this is the default level):
[2022-08-29T20:05:17Z ERROR limitador_server] You are using deprecated syntax for your condition! See guide https://kudrant.io/migration/limitador/constraints

The address is:

  • open to suggestion, wrt to its parts as well
  • missing the content that explains what's expected…

Should we add a "non-lenient" parser option, so the user can validate their newer files? Or make a "only validate limit file" option, that will not start the server but only parse the limits file… so that can stay even after this lenient mode gets deprecated, I think @maleck13 proposed something like that actually…

@@ -210,6 +210,9 @@ impl Limiter {
Self::Blocking(limiter) => limiter.configure_with(limits)?,
Self::Async(limiter) => limiter.configure_with(limits).await?,
}
if limitador::limit::check_deprecated_syntax_usages_and_reset() {
error!("You are using deprecated syntax for your condition! See guide https://kudrant.io/migration/limitador/constraints")
Copy link
Member Author

Choose a reason for hiding this comment

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

See guide

See how to migrate with this guide?

@maleck13
Copy link

Or make a "only validate limit file" option, that will not start the server but only parse the limits file

yes my suggestion was allowing it be executed as a CLI tool so that it could be used in build etc pipelines

@@ -4,14 +4,14 @@
max_value: 10
seconds: 60
conditions:
- "req.method == 'GET'"
Copy link
Contributor

Choose a reason for hiding this comment

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

For the examples, I would not use the deprecated syntax

@@ -210,6 +210,9 @@ impl Limiter {
Self::Blocking(limiter) => limiter.configure_with(limits)?,
Self::Async(limiter) => limiter.configure_with(limits).await?,
}
if limitador::limit::check_deprecated_syntax_usages_and_reset() {
Copy link
Contributor

Choose a reason for hiding this comment

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

if the feature is not enabled, this would not compile

Copy link
Member Author

@alexsnaps alexsnaps Aug 31, 2022

Choose a reason for hiding this comment

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

Sure... but the feature is always enabled. The way I've done this is the crate has the feature, and this enables it always as a consumer of the crate.
Are you asking I do make the feature available at the binary's layer too (like I did for infinispan)? Or did you think I had made the lenient_conditions a feature at both layers?

Copy link
Contributor

Choose a reason for hiding this comment

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

ok I see.

The feature belongs to the limitador crate. And the limitador crate compiles regardless of being activated or not. However, limitador-server package needs it activated or it would not compile.

LGTM

@alexsnaps alexsnaps requested a review from eguzki September 1, 2022 11:28
@alexsnaps alexsnaps merged commit 6e6b208 into scanner Sep 1, 2022
Copy link
Contributor

@eguzki eguzki left a comment

Choose a reason for hiding this comment

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

LGTM

Regarding the "ugly" static switch, It is ok as it is, but I would have added one error per condition, possibly flooding the log. IMO it is a fair toll to pay when using deprecated syntax.

Eventually, in the next release or after, when the deprecated syntax is dropped (or entirely changed by a new struct), this "hack" can be removed

@alexsnaps
Copy link
Member Author

Regarding the "ugly" static switch, It is ok as it is, but I would have added one error per condition, possibly flooding the log. IMO it is a fair toll to pay when using deprecated syntax.

So, to stderr from the crate itself directly? Or have a static Vec<String> with all the deprecated style conditions, so the logger can log them all (rather than the current generic message)?

Eventually, in the next release or after, when the deprecated syntax is dropped (or entirely changed by a new struct), this "hack" can be removed

Yes, this goes away in a minor release to come, totally!

@alexsnaps alexsnaps deleted the lenient branch September 1, 2022 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants