Skip to content

Commit 0d4109d

Browse files
authored
[Filebeat] Convert logstash logEvent.action objects to strings (#23944)
To prevent index failures resulting from indexing a mix of strings and nested objects as logstash.log.log_event.action, this converts any objects to a stringified version of the object using painless toString(). Fixes #20709
1 parent 55b1e2a commit 0d4109d

7 files changed

Lines changed: 43 additions & 1 deletion

File tree

CHANGELOG.next.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
380380
- Use rfc6587 framing for fortinet firewall and clientendpoint filesets when transferring over tcp. {pull}23837[23837]
381381
- Fix httpjson input logging so it doesn't conflict with ECS. {pull}23972[23972]
382382
- Fix Okta default date formatting. {issue}24018[24018] {pull}24025[24025]
383+
- Fix Logstash module handling of logstash.log.log_event.action field. {issue}20709[20709]
383384

384385
*Heartbeat*
385386

filebeat/docs/fields.asciidoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86605,6 +86605,13 @@ type: object
8660586605

8660686606
--
8660786607

86608+
*`logstash.log.log_event.action`*::
86609+
+
86610+
--
86611+
type: keyword
86612+
86613+
--
86614+
8660886615
*`logstash.log.pipeline_id`*::
8660986616
+
8661086617
--

filebeat/module/logstash/fields.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

filebeat/module/logstash/log/_meta/fields.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
type: object
2020
description: >
2121
key and value debugging information.
22+
- name: log_event.action
23+
type: keyword
2224
- name: pipeline_id
2325
type: keyword
2426
example: main

filebeat/module/logstash/log/ingest/pipeline-json.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ processors:
3131
- rename:
3232
field: logstash.log.level
3333
target_field: log.level
34+
- script:
35+
description: Convert logstash.log.log_event.action elements to string.
36+
if: ctx?.logstash?.log?.log_event?.action instanceof List
37+
lang: painless
38+
source: |
39+
def items = [];
40+
ctx.logstash.log.log_event.action.forEach(v -> {
41+
items.add(v.toString());
42+
});
43+
ctx.logstash.log.log_event.action = items;
3444
- set:
3545
field: event.kind
3646
value: event
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{"level":"INFO","loggerName":"logstash.agent","timeMillis":1546896321871,"thread":"Ruby-0-Thread-1: /Users/mat/work/elastic/releases/6.5.1/logstash/lib/bootstrap/environment.rb:6","logEvent":{"message":"Pipelines running","count":1,"running_pipelines":[{"metaClass":{"metaClass":{"metaClass":{"running_pipelines":"[:main]","non_running_pipelines":[]}}}}]}}
22
{"level":"INFO","loggerName":"logstash.pipeline","timeMillis":1546896322538,"thread":"[main]>worker7","logEvent":{"message":"Pipeline has terminated","pipeline_id":"main","thread":"#<Thread:0x7d16ffef run>"}}
33
{"level":"INFO","loggerName":"logstash.agent","timeMillis":1546896322594,"thread":"Api Webserver","logEvent":{"message":"Successfully started Logstash API endpoint","port":9600}}
4+
{"level":"WARN","loggerName":"logstash.outputs.elasticsearch","timeMillis":1612827484046,"thread":"[foo]>worker1","logEvent":{"message":"Could not index event to Elasticsearch.","status":400,"action":["update",{"_id":"foo-1234abcd-96c6-4828-bcd4-51d33a156431","_index":"filebeat-foo-2021.02","_type":"_doc","retry_on_conflict":1},{"metaClass":{"metaClass":{"metaClass":{"action":"[\"update\", {:_id=>\"foo-1234abcd-96c6-4828-bcd4-51d33a156431\", :_index=>\"filebeat-foo-2021.02\", :routing=>nil, :_type=>\"_doc\", :retry_on_conflict=>1}, #<LogStash::Event:0x51b7cd8e>]","response":{"update":{"_index":"filebeat-foo-2021.02","_type":"_doc","_id":"foo-1234abcd-96c6-4828-bcd4-51d33a156431","status":400,"error":{"type":"mapper_parsing_exception","reason":"failed to parse field [bar] of type [long] in document with id 'foo-1234abcd-96c6-4828-bcd4-51d33a156431'. Preview of field's value: 'ABCDEFGHIJ'","caused_by":{"type":"illegal_argument_exception","reason":"For input string: \"ABCDEFGHIJ\""}}}}}}}}]}}

filebeat/module/logstash/log/test/logstash-json.log-expected.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,26 @@
5959
"logstash.log.thread": "Api Webserver",
6060
"message": "Successfully started Logstash API endpoint",
6161
"service.type": "logstash"
62+
},
63+
{
64+
"@timestamp": "2021-02-08T23:38:04.046Z",
65+
"event.dataset": "logstash.log",
66+
"event.kind": "event",
67+
"event.module": "logstash",
68+
"event.type": "info",
69+
"fileset.name": "log",
70+
"input.type": "log",
71+
"log.level": "WARN",
72+
"log.offset": 745,
73+
"logstash.log.log_event.action": [
74+
"update",
75+
"{_index=filebeat-foo-2021.02, _type=_doc, _id=foo-1234abcd-96c6-4828-bcd4-51d33a156431, retry_on_conflict=1}",
76+
"{metaClass={metaClass={metaClass={response={update={_index=filebeat-foo-2021.02, _type=_doc, _id=foo-1234abcd-96c6-4828-bcd4-51d33a156431, error={reason=failed to parse field [bar] of type [long] in document with id 'foo-1234abcd-96c6-4828-bcd4-51d33a156431'. Preview of field's value: 'ABCDEFGHIJ', caused_by={reason=For input string: \"ABCDEFGHIJ\", type=illegal_argument_exception}, type=mapper_parsing_exception}, status=400}}, action=[\"update\", {:_id=>\"foo-1234abcd-96c6-4828-bcd4-51d33a156431\", :_index=>\"filebeat-foo-2021.02\", :routing=>nil, :_type=>\"_doc\", :retry_on_conflict=>1}, #<LogStash::Event:0x51b7cd8e>]}}}}"
77+
],
78+
"logstash.log.log_event.status": 400,
79+
"logstash.log.module": "logstash.outputs.elasticsearch",
80+
"logstash.log.thread": "[foo]>worker1",
81+
"message": "Could not index event to Elasticsearch.",
82+
"service.type": "logstash"
6283
}
6384
]

0 commit comments

Comments
 (0)