-
Notifications
You must be signed in to change notification settings - Fork 8
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
[approvaltest] Ignore dynamic fields from sort fields #61
Conversation
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.
Could this PR be simplified by pulling the rewrite loops out of approveEventDocs and approveFields? i.e. change ApproveEvents and ApproveFields to first rewrite, then sort, and finally approve.
@axw This was my first thought and I spent some time into trying to refactor code as per this but the code I came up with was not optimum and required copying the raw fields and the raw source both in-memory. My previous effort was based on not decoding the data first but I think we might be able to do this if we decode to JSON first and then parse dynamic fields. I will give this a shot. |
3deb5ed
to
d8f85a6
Compare
@axw Fixed the logic to rewrite before sort. PTAL. |
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.
Looks good, just one query
pkg/approvaltest/approvals.go
Outdated
for _, field := range dynamic { | ||
existing := gjson.GetBytes(doc, field) | ||
field = strings.ReplaceAll(field, ".", "\\.") |
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.
Is this going to work for _source
as well as fields
? We might need to switch based on whether it's ApproveEvents vs. ApproveFields
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.
@axw You are right, it wouldn't have worked with ApproveEvents
, I have fixed it now. Thanks for catching this.
The approval tests doesn't handle dynamic fields correctly, the fields are sorted before
dynamic
is handled. Due to this, 2 issues could happen:dynamic
but it is also in the sort fields then the resulting sort would be indeterministic.bytes.Compare
this will again result in indeterministic sorts if the dynamic fields are randomly generated.Both these issues are fixed in this PR by rewriting the dynamic fields before sorting and comparing for approvals.
Required to fix the failures in elastic/apm-server#13196