Skip to content

runtime: Add getDouble functionality to snapshot#8265

Merged
mattklein123 merged 11 commits intoenvoyproxy:masterfrom
tonya11en:get_double
Sep 24, 2019
Merged

runtime: Add getDouble functionality to snapshot#8265
mattklein123 merged 11 commits intoenvoyproxy:masterfrom
tonya11en:get_double

Conversation

@tonya11en
Copy link
Copy Markdown
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

Signed-off-by: Tony Allen <tony@allen.gg>
Signed-off-by: Tony Allen <tony@allen.gg>
Copy link
Copy Markdown
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
Copy Markdown
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 <tallen@lyft.com>
zuercher
zuercher previously approved these changes Sep 18, 2019
Copy link
Copy Markdown
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
Copy Markdown
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.

Signed-off-by: Tony Allen <tony@allen.gg>
// 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
Copy Markdown
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.

Signed-off-by: Tony Allen <tallen@lyft.com>
@tonya11en
Copy link
Copy Markdown
Member Author

/wait

Tony Allen added 2 commits September 20, 2019 15:09
Signed-off-by: Tony Allen <tallen@lyft.com>
Signed-off-by: Tony Allen <tallen@lyft.com>
@zuercher
Copy link
Copy Markdown
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
Copy Markdown
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 <tallen@lyft.com>
zuercher
zuercher previously approved these changes Sep 23, 2019
Copy link
Copy Markdown
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

* 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
Copy Markdown
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 <tallen@lyft.com>
@mattklein123
Copy link
Copy Markdown
Member

Sorry needs a master merge.

/wait

Signed-off-by: Tony Allen <tallen@lyft.com>
@mattklein123
Copy link
Copy Markdown
Member

/retest

@repokitteh-read-only
Copy link
Copy Markdown

🔨 rebuilding ci/circleci: asan (failed build)

🐱

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

see: more, trace.

Copy link
Copy Markdown
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 <tallen@lyft.com>
@tonya11en
Copy link
Copy Markdown
Member Author

/retest

@repokitteh-read-only
Copy link
Copy Markdown

🐴 hold your horses - no failures detected, yet.

🐱

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

see: more, trace.

Copy link
Copy Markdown
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
Signed-off-by: Tony Allen <tallen@lyft.com>
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