-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[Filebeat] add support for ndjson results to httpjson input #23428
Conversation
Pinging @elastic/security-external-integrations (Team:Security-External Integrations) |
1c261f1
to
d545c36
Compare
- if response Content-Type is "application/x-ndjson", collect the json objects in an array and assign array to key "ndjson-results" in a new json object - if config response.force_ndjson is set, set response Content-Type header to "application/x-ndjson"
d545c36
to
fe138a3
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.
Really nice improvement!
Beside the couple of comments, would be nice to add some test for ndjson if possible.
[float] | ||
==== `response.force_ndjson` | ||
|
||
If the Content-Type header is set to "application/x-ndjson" then the ndjson results will be available in a new array called "ndjson-results". |
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 would add a comment about supporting ndjson at the top of the docs instead for visibility.
@@ -80,6 +83,10 @@ func (rp *responseProcessor) startProcessing(stdCtx context.Context, trCtx *tran | |||
go func() { | |||
defer close(ch) | |||
|
|||
if rp.forceNdjson { | |||
resp.Header.Set("Content-Type", "application/x-ndjson") |
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 just for testing purposes? If not, maybe there are other use cases for modifying response headers, and enabling writing to them in transform_xxx.go
is a more general approach without adding specific config fields. WDYT?
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.
Unfortunately not just for testing, some endpoints send back ndjson with content types of text/plain or application/json. So we need some way to force ndjson code path. That being said I like the idea of the general approach, let me give that a try.
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.
After reading "if config response.force_ndjson is set, set response Content-Type
header to "application/x-ndjson" in the description, my first thought was that this sounded fairly specific. If we have several builtin handlers for different content types then maybe a generic overwrite header option would work and make future extension easier.
replace ndjson-results with root level array Co-authored-by: Marc Guasch <marc-gr@users.noreply.github.com>
- use json.Decoder instead of json.UnMarshall - if only 1 json object is present it becomes the root - if more than on json object is present a root level array is returned
499955c
to
f203efb
Compare
I opened #23478, if it looks good to you, maybe we can merge it and then you just need to create a new ndjson decoder and use the |
yeah, I like the encode_as & decode_as stuff from #23478 better. Cunnighams Law at work. Closing this one. |
What does this PR do?
adds support for ndjson results to httpjson input.
objects in an array and assign array to key "ndjson-results" in a new
json object
header to "application/x-ndjson"
Why is it important?
Some HTTP API endpoints return results as ndjson not json
Checklist
- [ ] I have commented my code, particularly in hard-to-understand areas- [ ] I have made corresponding change to the default configuration filesCHANGELOG.next.asciidoc
orCHANGELOG-developer.next.asciidoc
.