Hi Logstash Iron Chefs,
I am running Docker Container Logstash 7.4.0 (I know, I need to get the latest version) and my Logstash filter has a lot of code blocks like these:
if [MyData][dataA][dataB] == 0 {
translate {
field => “[MyData][dataA][dataC]”
destination => “[MyData][dataA][newData]”
dictionary_path => “/usr/share/logstash/config/dict1.yaml”
fallback => "default_0"
}
}
else if [MyData][dataA][dataB] == 1 {
translate {
field => “[MyData][dataA][dataC]”
destination => “[MyData][dataA][newData]”
dictionary_path => "/usr/share/logstash/config/dict2.yaml"
fallback => "default_1"
}
}
And when I run my traffic through Logstash, for the most part, this config works great.
…however…
What I’ve noticed is that on rare occasions, my Logstash container crashes. I can’t tell why, but I’ve noticed that the container always crashes whenever I misconfigure my LS config file and then run test data. So I’m guessing that I have a bug in my filter code, a bug which impacts only 0.0001% of data. That’s hard to pinpoint, for I have no idea what the problematic data might look like.
So – this is a wild guess – but I’m guessing that the problem data runs through the filter code, the code doesn’t apply to the data, and that’s why Logstash crashes. If so, no worries, I’m fine with a LG config that simply ignores the problem data.
The question is, how to do this?
If this were a Java program, I would wrap the above code block in a try/catch statement:
try{
if [MyData][dataA][dataB] == 0 {
...entire code block from above...
}
} catch exception >whatever< {
// do nothing...
// or maybe log this...
}
Another possibility is to add an “else” clause to what I have thus far:
if [MyData][dataA][dataB] == 0 {
...same...
}
else if [MyData][dataA][dataB] == 1 {
...same...
}
else {
// do nothing...
// or maybe log this...
}
The second option is clunky, but will work in a pinch, I guess. Does anyone have any suggestions? Thanks