Hi,
I ran across something unexpected yesterday, that doesn't seem to line up with the Logstash documentation, and I was wondering if this was intended behavior (or if I did something wrong.)
TL;DR - if you have multiple filter {}
blocks, and attempt to use json {}
in one of the filters with skip_on_invalid_json
set, it seems to skip all filters rather than just the filter where json{}
was used.
Longer version:
Per the JSON filter documentation on skip_on_invalid_json
(emphasis added):
Allows for skipping the filter on invalid JSON.
Based on this, I assumed that if json {}
hits invalid JSON, it will skip the rest of the parent filter - but still process other filters in the pipeline.
So, I had the following in my pipeline definition:
filter {
json {
skip_on_invalid_json => true
source => "message"
}
mutate {
remove_field => "message"
}
}
filter {
mutate {
# do some other stuff
}
}
What I found was, when [message] didn't contain valid JSON, the second filter didn't seem to run at all. I added a "JSON check" prior to the json {}
block by putting if [message] =~ "^\s*{.*}\s*$" { }
around it, and that seemed to solve the problem - if [message] doesn't look like a JSON object, the json {}
block doesn't run, skip_on_invalid_json
is never encountered, and the second filter runs as expected.
Is this expected behavior?