Refactor NewValue, add tests#16
Conversation
cmacknz
left a comment
There was a problem hiding this comment.
Looks good, a couple of minor comments. I am curious about the impact of the use of reflection here since it is generally known to be expensive, and I think we could probably avoid it for common cases for primitive types.
We are going to execute this for every event processed by the shipper so the cost of this conversion will definitely show up in our performance tests.
|
Alright, made a few performance changes, which seems to have helped: |
| } | ||
| } | ||
|
|
||
| func TestStructValue(t *testing.T) { |
There was a problem hiding this comment.
We aren't hitting a few cases in this test or the benchmarks looking at the code coverage with:
go test ./pkg/helpers/... -coverprofile=cover.tmp
go tool cover -html cover.tmpWe are missing the map[string]interface{} and reflect.Slice cases which both seem important enough to test. Hitting all the primitive number cases is probably easy to do but also unlikely to matter that much.
I am giving this PR extra scrutiny because any problems here mean the shipper just doesn't work at all, or works unnecessarily slowly :)
There was a problem hiding this comment.
Oh man, I completely forgot about the -coverprofile feature, haven't used that in years.
|
Alright, going over the coverage profile made me realize that the |
cmacknz
left a comment
There was a problem hiding this comment.
Thanks for all the iterations!
I suspect we may eventually want a way to know we are falling back on reflection, but in theory it will show up in the profiles in our performance tests.
|
I would tag a release for this fix before updating Beats + the shipper. |

Closes elastic/beats#34319
There's a few things going on here:
NewValueto make it a little more hardy, and to better handle the[]stringvalues that were causing the failures seen in the above issue.go-versionmanually, since it was a tad out of date