Skip to content
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

Merged
merged 11 commits into from
Sep 24, 2019

Conversation

tonya11en
Copy link
Member

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

Copy link
Member

@zuercher zuercher left a 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?

@zuercher zuercher self-assigned this Sep 17, 2019
@tonya11en
Copy link
Member Author

tonya11en commented Sep 18, 2019

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]>
zuercher
zuercher previously approved these changes Sep 18, 2019
Copy link
Member

@zuercher zuercher left a 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.

@mattklein123
Copy link
Member

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.

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?

@zuercher zuercher dismissed their stale review September 19, 2019 17:38

Let's do what Matt suggested.

// 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_;
Copy link
Member

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.

source/common/runtime/runtime_impl.h Outdated Show resolved Hide resolved
Signed-off-by: Tony Allen <[email protected]>
@tonya11en
Copy link
Member Author

/wait

Tony Allen added 2 commits September 20, 2019 15:09
Signed-off-by: Tony Allen <[email protected]>
Signed-off-by: Tony Allen <[email protected]>
@zuercher
Copy link
Member

zuercher commented Sep 23, 2019

Cool. Let's add a comment on getInteger for values > 2^53 and then I think this is good to go.

zuercher
zuercher previously approved these changes Sep 23, 2019
Copy link
Member

@mattklein123 mattklein123 left a 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]>
zuercher
zuercher previously approved these changes Sep 23, 2019
Copy link
Member

@mattklein123 mattklein123 left a 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

@@ -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.
Copy link
Member

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]>
@mattklein123
Copy link
Member

Sorry needs a master merge.

/wait

@mattklein123
Copy link
Member

/retest

@repokitteh-read-only
Copy link

🔨 rebuilding ci/circleci: asan (failed build)

🐱

Caused by: a #8265 (comment) was created by @mattklein123.

see: more, trace.

@@ -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.
Copy link
Member

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]>
@tonya11en
Copy link
Member Author

/retest

@repokitteh-read-only
Copy link

🐴 hold your horses - no failures detected, yet.

🐱

Caused by: a #8265 (comment) was created by @tonya11en.

see: more, trace.

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@mattklein123 mattklein123 merged commit 7bd7c46 into envoyproxy:master Sep 24, 2019
@tonya11en tonya11en deleted the get_double branch September 24, 2019 18:15
danzh2010 pushed a commit to danzh2010/envoy that referenced this pull request Oct 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants