add a helper class for runtime-derived uint32#16398
add a helper class for runtime-derived uint32#16398alyssawilk merged 10 commits intoenvoyproxy:mainfrom
Conversation
Signed-off-by: gaoweiwen <whereisgww@outlook.com>
Signed-off-by: gaoweiwen <whereisgww@outlook.com>
|
ready to be reviewed. |
antoniovicente
left a comment
There was a problem hiding this comment.
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.
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.
There was a problem hiding this comment.
The default value is indeed more reasonable, I'll submit a commit to fix it.
There was a problem hiding this comment.
Fixed in the latest commit. @antoniovicente
Signed-off-by: gaoweiwen <whereisgww@outlook.com>
Signed-off-by: gaoweiwen <whereisgww@outlook.com>
tonya11en
left a comment
There was a problem hiding this comment.
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.
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.
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.
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.
I misunderstood what you meant before (embarrassing >_<). Now I understand your suggestion and submit a new commit.
Signed-off-by: gaoweiwen <whereisgww@outlook.com>
| 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.
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.
Signed-off-by: gaoweiwen <whereisgww@outlook.com>
|
Could you please take a look since you had implemented a similar wrapper class and also have write access to merge. @alyssawilk |
alyssawilk
left a comment
There was a problem hiding this comment.
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 |
| : 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.
Mind adding a unit test for this?
Signed-off-by: gaoweiwen <whereisgww@outlook.com>
Signed-off-by: gaoweiwen <whereisgww@outlook.com>
alyssawilk
left a comment
There was a problem hiding this comment.
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 <whereisgww@outlook.com>
Signed-off-by: gaoweiwen <whereisgww@outlook.com>
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 <whereisgww@outlook.com>
Signed-off-by: gaoweiwen whereisgww@outlook.com
Envoy already has several runtime protobuf messages, such as
RuntimeUInt32,RuntimePercentandRuntimeDouble. 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
RuntimeUInt32Additional 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:]