-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fix float64 comparison test failure on archs using FMA #1133
Conversation
e8353d9
to
912193e
Compare
Architectures using FMA optimization yield slightly different results so we cannot assume floating point values will be precisely the same across different architectures. The solution in this change is to check "abs(a-b) < tolerance" instead of comparing the exact values. This will give us confidence that the histogram buckets are near identical. Signed-off-by: Seth Bunce <[email protected]>
912193e
to
4691831
Compare
Co-authored-by: Daniel Swarbrick <[email protected]> Signed-off-by: Seth Bunce <[email protected]>
There are better ways of a tolerant comparison. We already have https://github.com/prometheus/prometheus/blob/main/promql/test.go#L637 in the Prometheus code base. Perhaps that's easy enough to just copy over here. |
Or depend on https://github.com/beorn7/floats :o) |
I would prefer not to have to package yet another tiny dependency to make this build on Debian (and derivatives), so I would advocate just copying that function. Or use something like https://pkg.go.dev/github.com/stretchr/testify/assert?utm_source=godoc#InDeltaSlice |
Yeah, the dependency was meant as a joke. I think the technique implemented in https://github.com/prometheus/prometheus/blob/main/promql/test.go#L637 (or in a slightly more general form in https://github.com/beorn7/floats ) works better that the approach in testify. And yes, I would propose to just copy that piece of code, maybe to the already existing |
b481d09
to
a092c38
Compare
Per discussion in the pull request, we'd like to avoid having an extra dependency on a float comparison package. Instead, we copy the float compare functions from the float comparison package. The float comparison package we're choosing is this. The author of this package has commented in the pull request and it looks like we have consensus that this is the best option. github.com/beorn7/floats Signed-off-by: Seth Bunce <[email protected]>
a092c38
to
e672c58
Compare
Sounds like there's consensus on avoiding the extra dependency. Reminds me of that go proverb, "a little copying is better than a little dependency". I copied the contents of https://github.com/beorn7/floats to the prometheus/internal package. I made a few small changes.
Couple points I anticipate there may be disagreement about. Calling these out.
|
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.
I love the ε, but I am well aware that I'm a small minority here. (Insert lament about decline of classical education…) |
I think it is overwhelmingly likely that we'll never use the float32 here. I would prefer to remove this variant. It's easy to add later should we really need it, thanks to the reference back to the source repo. All other points you made seem fine to me. Thanks for your contribution and your patience. |
You're welcome. I appreciate your feedback.
|
97a1784
to
46827a2
Compare
This change removes the float32 variant of the AlmostEqual funcs, that we will likely never use. This change also relocates the function into a separate file to avoid modifying a file that's a fork of another vendored package. Signed-off-by: Seth Bunce <[email protected]>
46827a2
to
fa56c9b
Compare
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.
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 :) Thanks for review @beorn7
Background
Architectures using FMA optimization yield slightly different results so we cannot assume floating point values will be precisely the same across different architectures.
#899 (comment)
Change
The solution in this change is to check "abs(a-b) < tolerance" instead of comparing the exact values. This will give us confidence that the histogram buckets are near identical.
Testing
I have not tested this change on one of the previously failing architectures. Help from someone with access to one of these architectures would be appreciated.