-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
add a helper class for runtime-derived uint32 #16398
Conversation
Signed-off-by: gaoweiwen <[email protected]>
Signed-off-by: gaoweiwen <[email protected]>
ready to be reviewed. |
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.
cc @tonya11en
Hey Tony, could you do a review pass on this code since you were involved in the implementation of the wrapper for doubles?
EXPECT_EQ(1024, test_uint32.value()); | ||
|
||
EXPECT_CALL(runtime_.snapshot_, getInteger("foo.bar", 99)).WillOnce(Return(1ull << 33)); | ||
EXPECT_EQ(0, test_uint32.value()); |
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.
In cases where getInteger returns a value larger than uint32 max, should this mask the returned value down to 32 bits or return the default value? Consistency between the behavior of getDouble and getInteger for values larger than uint64 max suggest that we should return the default in this case.
https://github.com/envoyproxy/envoy/blob/main/source/common/runtime/runtime_impl.h#L104
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.
The default value is indeed more reasonable, I'll submit a commit to fix it.
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.
Fixed in the latest commit. @antoniovicente
Signed-off-by: gaoweiwen <[email protected]>
Signed-off-by: gaoweiwen <[email protected]>
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 a minor comment, LG otherwise. Thanks!
|
||
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_ |
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.
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?
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.
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.
I'm not sure if there are other solutions, I look forward to your suggestions.
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.
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.
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.
I misunderstood what you meant before (embarrassing >_<). Now I understand your suggestion and submit a new commit.
Signed-off-by: gaoweiwen <[email protected]>
uint64_t raw_value = runtime_.snapshot().getInteger(runtime_key_, default_value_); | ||
if (raw_value > std::numeric_limits<uint32_t>::max()) { | ||
ENVOY_LOG_EVERY_POW_2(warn, | ||
"value:{} of {} is larger than uint32 max, return default instead", |
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.
Sorry one more-- can you mention in the message that it's a parsed runtime value and swap "return" for "returning".
It'll be good to go after that.
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.
Sure.
Signed-off-by: gaoweiwen <[email protected]>
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.
Thanks!
Could you please take a look since you had implemented a similar wrapper class and also have write access to merge. @alyssawilk |
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.
I'm happy to take a look, but I'm unclear on why we're landing this upstream if it's not being used. Maybe if you filled out the Pr description fields it would explain? I think largely if its not used in Envoy it's going to end up being cleaned up at some point.
When I tried to implement another feature (see #16392 ), I found that I need a |
@WeavingGao can you please update the description to include those details. This way other's don't have to fish through the comments to gather context. |
I added some details in the PR description. @alyssawilk @tonya11en |
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.
: runtime_key_(uint32_proto.runtime_key()), default_value_(uint32_proto.default_value()), | ||
runtime_(runtime) {} | ||
|
||
const std::string& runtimeKey() const { return runtime_key_; } |
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.
Signed-off-by: gaoweiwen <[email protected]>
Signed-off-by: gaoweiwen <[email protected]>
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.
lgtm modulo one nit - could you put the TODO in the code, rather than the PR description? Sorry that wasn't clear!
Signed-off-by: gaoweiwen <[email protected]>
Signed-off-by: gaoweiwen <[email protected]>
Adding runtime helper protobuf messages for RuntimeUInt32. TODO(WeavingGao): use for Risk Level: Low Testing: Unit Test Docs Changes: N/A Release Notes: N/A part of envoyproxy#16392 Signed-off-by: gaoweiwen <[email protected]>
Signed-off-by: gaoweiwen [email protected]
Envoy already has several runtime protobuf messages, such as
RuntimeUInt32
,RuntimePercent
andRuntimeDouble
. Each protobuf message has a corresponding C++ helper class to easily and safely obtain the runtime value, except forRuntimeUInt32
. So this PR tries to add the missing helper class.TODO(WeavingGao): use for #16392
Commit Message: helper class for
RuntimeUInt32
Additional Description:
Risk Level: Low
Testing: Unit Test
Docs Changes: N/A
Release Notes: N/A
Platform Specific Features: N/A
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Deprecated:]
[Optional API Considerations:]