-
Notifications
You must be signed in to change notification settings - Fork 5.5k
add a helper class for runtime-derived uint32 #16398
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
Changes from 4 commits
0a34c9b
f553f65
eed421c
682f4c1
a1cffc4
0d86df8
9f39b77
9fd4ead
0610dcf
4e22777
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,27 @@ | |
| namespace Envoy { | ||
| namespace Runtime { | ||
|
|
||
| // Helper class for runtime-derived uint32. | ||
| class UInt32 { | ||
| public: | ||
| UInt32(const envoy::config::core::v3::RuntimeUInt32& uint32_proto, Runtime::Loader& runtime) | ||
| : runtime_key_(uint32_proto.runtime_key()), default_value_(uint32_proto.default_value()), | ||
| runtime_(runtime) {} | ||
|
|
||
| const std::string& runtimeKey() const { return runtime_key_; } | ||
|
|
||
| uint32_t value() const { | ||
| uint64_t raw_value = runtime_.snapshot().getInteger(runtime_key_, default_value_); | ||
| return raw_value > std::numeric_limits<uint32_t>::max() ? default_value_ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please add an error or warning log (every ~1000 times or something along those lines) for when there is an invalid value parsed that causes a revert to the default value?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may introduce additional complexity. If we introduce additional variables to record the number of invalid parsing, this class will become thread-unsafe, making it either complicated or poor in performance.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean just put ENVOY_LOG_EVERY_POW_2() or ENVOY_LOG_EVERY_N() in a conditional instead of using that ternary operator. You don't need to get too clever here. I would be genuinely surprised if that caused an appreciable decline in performance.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I misunderstood what you meant before (embarrassing >_<). Now I understand your suggestion and submit a new commit. |
||
| : static_cast<uint32_t>(raw_value); | ||
| } | ||
|
|
||
| private: | ||
| const std::string runtime_key_; | ||
| const uint32_t default_value_; | ||
| Runtime::Loader& runtime_; | ||
| }; | ||
|
|
||
| // Helper class for runtime-derived boolean feature flags. | ||
| class FeatureFlag { | ||
| public: | ||
|
|
||
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.
Mind adding a unit test for this?
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.
done.