Repository navigation
fix(splunk-hec-logging): safely handle non-200 responses without text field - #14012
Conversation
| if not body then | ||
| return false, "failed to send splunk, http status code: " .. res.status | ||
| local err_msg | ||
| if type(body) == "table" and (body.text or body.message) then |
There was a problem hiding this comment.
CI error: ERROR: apisix/plugins/splunk-hec-logging.lua: line 175: getting the Lua global "type". The local type should be replaced with a cached global, local type = type, so that lj-releng no longer reports this error.
There was a problem hiding this comment.
Updated, thanks!
… field In `apisix/plugins/splunk-hec-logging.lua`, `send_to_splunk` expects error responses to contain `body.text`. When Splunk HEC or an intermediate proxy returns an error response with JSON lacking a `text` attribute, attempting to concatenate `body.text` causes an unhandled runtime error: `attempt to concatenate field 'text' (a nil value)`. This commit falls back to `body.message`, `res.body`, or the HTTP status code when `body.text` is not present, avoiding the crash. Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
Fixes lj-releng lint error by caching global `type`. Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
47f0379 to
806344e
Compare
|
Thanks for the fix — the nil concat is real, and it's worse than a log line: since the batch processor doesn't pcall the callback, a throw skips both retry and the Two remaining cases still throw with this patch: This keeps the existing |
…/body fallback
Check `type(body.text) == "string"` so `{"text": null}` (cjson.null
userdata) does not throw on string concatenation, and include both HTTP
status code and raw response body in the fallback error message. Add
regression test coverage for `{"text": null}`.
Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
|
Updated as suggested and added a test case for |
Description
In
apisix/plugins/splunk-hec-logging.lua,send_to_splunkhandles non-200 responses by decoding JSON and concatenatingbody.text. When Splunk HEC or an intermediate reverse proxy returns an error response where JSON decodes to a table without a stringtextfield (such as{"message": "Unauthorized"},{"text": null}wherecjson.nullis userdata, or non-table/nested values), concatenatingbody.texttriggers a Lua runtime error (attempt to concatenate field 'text'), skipping batch processor retry andprocessed_entriesaccounting.This PR updates
send_to_splunkto checktype(body) == "table" and type(body.text) == "string"before formatting"failed to send splunk, " .. body.text, and otherwise returns"failed to send splunk, http status code: " .. res.status .. ", body: " .. (res.body or ""), preserving both the HTTP status code and response body while keeping the existingInvalid authorizationerror format unchanged.Which issue(s) this PR fixes:
Fixes #14011
Checklist