Commit abeb91b
committed
Fix double newline in NDJSON bulk body when using RawEncoding
When events are pre-encoded in the queue (via event_encoder.go), the
encoded bytes include a trailing newline from the Marshal/AddRaw call.
When the bulk body assembler later writes these bytes via
AddRaw(RawEncoding{...}), it unconditionally appends another newline,
producing an empty line (\n\n) in the NDJSON bulk body.
While Elasticsearch tolerates empty lines in bulk requests,
ES-compatible endpoints like Axiom and OpenSearch reject them with:
400 Bad Request: invalid event at index 1: ReadObject: expect { or ,
or } or n, but found \u0000
The fix checks whether RawEncoding bytes already end with a newline
and skips the additional one if so. This preserves backward
compatibility: RawEncoding bytes without a trailing newline (e.g. from
json.Marshal) still get the newline appended as before.
Applied to both jsonEncoder and gzipEncoder paths.1 parent 1c08869 commit abeb91b
File tree
3 files changed
+14
-43
lines changed- changelog/fragments
- libbeat/esleg/eslegclient
3 files changed
+14
-43
lines changedLines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
| 161 | + | |
166 | 162 | | |
167 | 163 | | |
168 | 164 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
| |||
67 | 66 | | |
68 | 67 | | |
69 | 68 | | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | 69 | | |
75 | | - | |
76 | 70 | | |
77 | 71 | | |
78 | 72 | | |
| |||
82 | 76 | | |
83 | 77 | | |
84 | 78 | | |
| 79 | + | |
85 | 80 | | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
| 81 | + | |
91 | 82 | | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
99 | 86 | | |
100 | 87 | | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
| 88 | + | |
121 | 89 | | |
122 | 90 | | |
123 | 91 | | |
| |||
0 commit comments