-
Notifications
You must be signed in to change notification settings - Fork 845
Unit parser #9485
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
Unit parser #9485
Conversation
|
Having this parser is fine. It'd make sense for file/memory size, but I'm skeptical to use it for amount of time such as timeout.
We currently use second for settings that receive amount of time in most of cases. And if a setting expects millisecond, the setting name has It's not only about percision. The suffix roughly suggests reasonable amount of time. Setting 100000 to a setting that has _ms suffix looks odd. Of course we could describe things on the documentation and say RTFM, but I don't think providing super detailed 1000 pages of documentation is user friendly. |
| {nanoseconds{hours{24}}.count(), {"d", "day", "days"}}, | ||
| {nanoseconds{hours{168}}.count(), {"w", "week", "weeks"}}}}}; | ||
|
|
||
| } // namespace ts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, is all of this constexpr resolved to data at compile time or is there static initializer setup here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, there's still computation that occurs to initialize the parser data structure. I'm not sure what you mean by "static initializer" other than the parser being a static data structure which is constructed at process start time. That is,
UnitParser const time_parser{ ... };
which declares a static instance of UnitParser.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I mean the static setup at process start time. It's not called "static initializing"?
I'd rather see time_parser be a function and just return a UnitParser and if a program wants one call. Then the programmer can decide its lifetime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? It seems more performant to construct a single instance at process start and use that everywhere. Then there is no runtime construction / destruction cost. What's the benefit of multiple instances?
|
Not having units specified could end up in being a real mess, I like this. |
|
It's certainly caused many problems in the past. One of my goals for the YAML conversion was to require explicit units for all time periods to avoid any possible confusion, and "random" numbers like "86400" instead of "1 day". |
|
What were the problems? |
|
People used wildly inappropriate values because they didn't realize the implied units. It's a bit less bad because one place this came up was where the default unit was minutes, not seconds. There was another case where the user assumed ms but it was really seconds. |
|
Sounds like this fixes a problem, but those problems support my concern. People don't read the documentation. And, more characters, more typos. A: Hey, I set xyz to 12h but it doesn't work! A: Hey, I set the timeout to 100ms but it doesn't work! A: Hey, I set another timeout to 800ms, and it doesn't work. I'm sure I set it to 800 millisecond this time. Nothing is going to be perfect. I wonder which is better. |
bneradt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Should be straightforward to add some unit tests?
a67590b to
56d8df4
Compare
|
Based on comments, I moved the actual unit parser instance to a nested namespace and wrapped it with a function to do the conversion to |
56d8df4 to
030ea06
Compare
brbzull0
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good Alan! Thanks.
* commit 'c54a2e2b77151869ff014fbdc4c82cec0afcbb8c': (37 commits) Slight performance improvements before calling APIHooks::clear (apache#9480) libswoc: Update to 1.4.5 (apache#9522) CryptoContext: Clean up to avoid compiler problem. (apache#9521) Add TLSCertSwitchSupport (apache#9322) Add clang-format-tests to clang-format target (apache#9456) Adds the AR env variable to config.nice (apache#9515) Fix .asf.yaml (apache#9519) Hugepage config cleanup (apache#9479) Separate io_uring into a separate library. AIO in io_uring mode uses new io_uring lib. (apache#9462) Avoid memory allocation in CryptoHash (apache#9474) UnitParser: add unit parser support. (apache#9485) autest - Minor fix on the verifier_client test ext to allow setting only the http3 ports. (apache#9517) Remove support for port event polling (apache#9476) QUIC: Add support to configure UDP max payload limit. (apache#9486) Reduce the size of the APIHooks, eliminating enum gap (apache#9509) Add support for CMCD-Request header nor field to prefetch plugin (apache#9232) Eliminates padding from some common structs (apache#9481) Enable external file loading for sni.yaml. (apache#9501) Remove inactive include of IpMapConf.h (apache#9512) Cleanup: Remove RecModeT from the code. (apache#9487) ...
This brings the unit parser logic into ATS. It provides generic support for parsing strings that have embedded units. Updating the set of units requires only changing the initialization data, making it very easy to add or remove additional units. This commit adds a concrete instantiation that supports time string parsing, so strings such as "1 day 12 hours 30 minutes" is correctly parsed. A primary goal is to stop using default / implied units for time values in configuration, but instead always require units while providing an easy way to specify convenient units.
See this fle for examples of use.
Related to #9477
Usage would be something like