-
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
runtime: Add getDouble functionality to snapshot #8265
Conversation
Signed-off-by: Tony Allen <[email protected]>
Signed-off-by: Tony Allen <[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, this seems useful for non-integer, non-percentage values.
I think we need to think about the interaction between integer and double values, however. It seems to me that the current behavior ignores values like "1.5" (if I understand absl::SimpleAtoi correctly it will treat that as a parsing error). I don't think this PR changes that, as long as code calls Snapshot::getInteger
. However, if some code is using Snapshot::getDouble
and the input is changed from 1.5 to just 1, getDouble will suddenly start returning 0.0 because "1" is parsed as a uint and SnapshotImpl::parseEntryDoubleValue
won't be invoked. Perhaps we should store numeric values as both uint64_t and doubles and allow getDouble and getInteger to be used interchangeably?
Editing this comment since I realized the logic was miguided. I'll see about changing this to store both uint and double values. Great catch, I hadn't considered that scenario. |
Signed-off-by: Tony Allen <[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! There's still a potential weirdness where, say "5.0"
isn't handled if the code uses getInteger. But I don't know the right way to reconcile numbers with fractional parts and getInteger. For example, I'm not sure it would be good for getInteger to return 5 for an input of "5.9" but that might be better than having it flip to default values because these they didn't realize a config point only accepted integers vs. floats.
Curious if @mattklein123 has an opinion.
FWIW I think we should probably just floor it and always store as both a double and an integer. I think it will be less surprising. If we decide not to do this can we clearly document that case? |
Signed-off-by: Tony Allen <[email protected]>
// Valid uint values will always be parseable as doubles, so we assign the value to both the | ||
// uint and double fields. In cases where the value is something like "3.1", we will floor the | ||
// number by casting it to a uint and assigning the uint value. | ||
entry.uint_value_ = entry.double_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.
Let's add a test for negative double values and positive double values >= 2^64. I think we'll want to handle those specially. Probably also need a warning on getInteger that values greater than approximately 2^53 will not be accurately converted to integers.
Signed-off-by: Tony Allen <[email protected]>
/wait |
Signed-off-by: Tony Allen <[email protected]>
Signed-off-by: Tony Allen <[email protected]>
Cool. |
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, looks great. Can you add a release note about the new behavior for doubles/integers in runtime. Also, would it be worth to actually document this behavior somewhere in the runtime docs?
/wait
Signed-off-by: Tony Allen <[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 with small nit. Thank you!
/wait
docs/root/intro/version_history.rst
Outdated
@@ -66,6 +66,7 @@ Version history | |||
* upstream: added new :ref:`failure-percentage based outlier detection<arch_overview_outlier_detection_failure_percentage>` mode. | |||
* upstream: use p2c to select hosts for least-requests load balancers if all host weights are the same, even in cases where weights are not equal to 1. | |||
* upstream: added :ref:`fail_traffic_on_panic <envoy_api_field_Cluster.CommonLbConfig.ZoneAwareLbConfig.fail_traffic_on_panic>` to allow failing all requests to a cluster during panic state. | |||
* runtime: allow for the ability to parse integers as double values and vice-versa. |
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.
nit: alpha order.
Signed-off-by: Tony Allen <[email protected]>
Sorry needs a master merge. /wait |
Signed-off-by: Tony Allen <[email protected]>
/retest |
🔨 rebuilding |
docs/root/intro/version_history.rst
Outdated
@@ -59,6 +59,7 @@ Version history | |||
* router check tool: add comprehensive coverage reporting. | |||
* router check tool: add deprecated field check. | |||
* router check tool: add flag for only printing results of failed tests. | |||
* runtime: allow for the ability to parse integers as double values and vice-versa. |
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 needs another merge fix.
/wait
Signed-off-by: Tony Allen <[email protected]>
/retest |
🐴 hold your horses - no failures detected, yet. |
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!
Signed-off-by: Tony Allen <[email protected]>
This patch adds the
getDouble
function to the runtime snapshot. This allows for parsing of double values in addition to the existing integer and fractions.Risk Level: Low
Testing: New unit tests
Docs Changes: N/A
Release Notes: N/A