Fix ambiguous duration units and add format check#12225
Fix ambiguous duration units and add format check#12225lizan merged 17 commits intoenvoyproxy:masterfrom greenhouse-org:fix-ambiguous-std-chrono-duration
Conversation
- ambiguous value-based std::chrono::{clock_type}::duration(value) constructors
result in stdlib implementation specific default time units which are
hard to read
- this change removes any instances of these ambiguous constructions and adds
a format check to prevent them; developers should specify an explicit unit of time
- we explicitly saw this issue in #11915
Co-authored-by: William A Rowe Jr <wrowe@vmware.com>
Signed-off-by: William A Rowe Jr <wrowe@vmware.com>
Co-authored-by: Sunjay Bhatia <sunjayb@vmware.com>
Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
rebello95
left a comment
There was a problem hiding this comment.
I think this lint rule would be good to add 👍
test/extensions/filters/network/kafka/broker/filter_unit_test.cc
Outdated
Show resolved
Hide resolved
Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
Signed-off-by: William A Rowe Jr <wrowe@vmware.com>
|
There's also this: https://github.com/envoyproxy/envoy/blob/master/include/envoy/event/timer.h#L83 It doesn't look like TimeSystem::Duration is used anywhere, but it seems like it would have the same problems. |
|
@jmarantz you may have input on this as well. |
- Ensure [Dd]uration is the complete method name - Allow for unambiguous values 0 or 0.0 Signed-off-by: William A Rowe Jr <wrowe@vmware.com>
…hrono-duration Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
…hrono-duration Signed-off-by: William A Rowe Jr <wrowe@vmware.com>
|
Seems like the ARM job is generally unhealthy on master as well, otherwise i think this is ready? |
zuercher
left a comment
There was a problem hiding this comment.
Looks good. I'll circle around and look at the build failures in a bit, but we'll probably need to merge master to pick up some fix before we can merge this.
…hrono-duration Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
|
I think Josh is away, @lizan can you have a quick look at this? |
lizan
left a comment
There was a problem hiding this comment.
This change looks good by itself. Though aren't we on a long term path toward absl::Time for all durations/time? Let's define a common duration in TimeSystem (there is already one there but ambiguous) without ambiguity and use them?
…hrono-duration Signed-off-by: wrowe@vmware.com
The issue doesn't change, though. an absl::Duration(1000) construction would be equally ambiguous as the std::chrono classes currently in use, because absl also doesn't define the unit of measure, it instead provides explicit constructors based on the time precision desired (including expressing a duration as a ratio); It appears that the absl::Duration class doesn't even have a constructor to accept a plain int, so we wouldn't have needed to address that ambiguity, although our code check does note this occurrence whether the author notes the compilation error, or not. It seems that the effort to convert this MonotonicTime Duration storage falls in the scope of a completely different PR. But as long as we are dealing with so many third party libraries, some of which use std::chrono classes, this particular PR seems like the right immediate approach and a long-term win. |
What I'm saying is define a type alias in timesystem for further replacement. That was one of the point using |
Do you want to replace Replacing sounds like it would break things like envoy/test/test_common/test_time_system.h Lines 18 to 48 in efd8ba9 e.g. e.g. https://godbolt.org/z/nKsq7s
It feels ok to have a generic |
|
I'm OK with either, replacing TimeSystem::Duration sounds good too. What I want to prevent is leaking |
…hrono-duration Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
- Makes it more trivial to switch to absl::Duration at some point Co-authored-by: Sunjay Bhatia <sunjayb@vmware.com> Co-authored-by: William A Rowe Jr <wrowe@vmware.com> Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com> Signed-off-by: William A Rowe Jr <wrowe@vmware.com> Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
Let us know if the proposed change works for you? |
It would slow this patch down to do all the replacement of (here's the issue: #12384) |
SGTM. We don't have to do all replacement in this PR. |
|
force pushed just to fix DCO |
Signed-off-by: William A Rowe Jr <wrowe@vmware.com>
…hrono-duration Signed-off-by: William A Rowe Jr <wrowe@vmware.com>
Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
Signed-off-by: William A Rowe Jr <wrowe@vmware.com>
…hrono-duration Signed-off-by: William A Rowe Jr <wrowe@vmware.com>
…hrono-duration Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com> Signed-off-by: William A Rowe Jr <wrowe@vmware.com>
|
@lizan please review, this seems stalled out for your approval, and now for some new clang-tidy chaos on master? |
- ambiguous value-based std::chrono::{clock_type}::duration(value) constructors
result in stdlib implementation specific default time units which are
hard to read and potentially different on different platforms
- this change removes any instances of these ambiguous constructions and adds
a format check to prevent them; developers should specify an explicit unit of time
- we explicitly saw this issue in envoyproxy#11915 where
the assumed duration unit was different on Windows, causing test failures
Additional Description:
Risk Level: Low
Testing: Adds format check test and adjust existing unit tests
Docs Changes: N/A
Release Notes: N/A
Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
Co-authored-by: William A Rowe Jr <wrowe@vmware.com>
- ambiguous value-based std::chrono::{clock_type}::duration(value) constructors
result in stdlib implementation specific default time units which are
hard to read and potentially different on different platforms
- this change removes any instances of these ambiguous constructions and adds
a format check to prevent them; developers should specify an explicit unit of time
- we explicitly saw this issue in envoyproxy#11915 where
the assumed duration unit was different on Windows, causing test failures
Additional Description:
Risk Level: Low
Testing: Adds format check test and adjust existing unit tests
Docs Changes: N/A
Release Notes: N/A
Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
Co-authored-by: William A Rowe Jr <wrowe@vmware.com>
Signed-off-by: chaoqinli <chaoqinli@google.com>
Commit Message:
Fix ambiguous duration units and add format check
result in stdlib implementation specific default time units which are
hard to read and potentially different on different platforms
a format check to prevent them; developers should specify an explicit unit of time
dateheader with requests #11915 wherethe assumed duration unit was different on Windows, causing test failures
Additional Description:
Risk Level: Low
Testing: Adds format check test and adjust existing unit tests
Docs Changes: N/A
Release Notes: N/A