-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Consider replacing reflect.DeepEqual #8186
Comments
Along the same lines, In our tests I would recommend switching to
|
Good point, we have a separate issue for that one: #8095 |
/triage accepted |
/assign |
Took a closer look at go-cmp. For me it seems like a good option:
If someone wants to consider other alternatives, now would be the time to bring them up :) |
I'm +1 for replacing it in tests, but I'm not sure about doing so in non-test code. From the go-doc:
That means that possibly we should wrap our equality checks in a util package and maybe use go-cmp underneath. If we do this we can catch panics and return them as errors. WDYT? |
Sounds reasonable. gomega also catches panics from go-cmp in BeComparableTo. I don't think performance will be an issue with the things we compare (but I don't have data) |
Yeah - I'm not very worried about performance. I also think we shouldn't have things that can't be compared, given we're almost always going to be comparing the same types, but catching the panics and turning them into errors is still a useful backstop. |
/reopen This issue covers replacing the reflect DeepEqual in more places across the codebase than #8266 |
@killianmuldoon: Reopened this issue. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
This is probably something that we keep an eye one when moving to |
Definitely more an issue for tests, in prod code we should keep it in mind but I would expect it not be an issue as you said. |
This issue has not been updated in over 1 year, and should be re-triaged. You can:
For more details on the triage process, see https://www.kubernetes.dev/docs/guide/issue-triage/ /remove-triage accepted |
/priority important-longterm |
/assign @sbueringer |
I think we should consider replacing reflect.DeepEqual. Whilte it works well to diff two structs, it's very very had to debug what exactly is not equal. This makes it very hard to produce good logs to tell users why something was considered not equal.
I think go-cmp might be a good alternative. For more details, see: https://github.com/google/go-cmp
We already use go-cmp today to produce a diff in test code after reflect.DeepEqual only told us that something is not equal. The comparision algorithm of go-cmp seems to be better and additionally we get the beneift of getting a result which tells us where the difference is. This would be super valuable for our prod code to tell folks why we are doing things.
Using cmp.Diff for logs while we use reflect.DeepEqual for the actual comparison is not great as there are small differences, e.g. unexported fields.
One example where I think this is super valuable is in the KCP controller where we could tell folks why exactly we are triggering a MachineRollout and not just: well reflect.DeepEqual told us that there is a difference.
There are a few more places like e.g. the ClusterClass controller where we compare variable definitions where we could have a log message (with high v) that could log exactly why the definitions are different.
(xref: #8107 (comment))
/kind feature
The text was updated successfully, but these errors were encountered: