Hi
(new here)
I've successfully managed to send all of our mongodb 5 instances (JSON-based) logs, via filebeat, on a Logstash instance.
MongoDB 5+ are JSON-based logs (https://www.mongodb.com/docs/manual/reference/log-messages/). The "attr" object is the one containing all the log details, and can be extremely versatile (can handle simple context as client name, IP etc...or much more complex logs like full pipeline outputs).
I'm using a simple JSON filter in my logstash pipeline config :, with a couple of simple rename for the sake of readability.
filter {
json {
source => "message"
}
mutate {
rename => {"[t][$date]" => "timestamp"}
rename => {"s" => "log_level"}
rename => {"c" => "component"}
rename => {"ctx" => "context"}
rename => {"attr" => "log_data"}
}
}
The JSON is properly parsed, and I can create my Index Patterns (they can contain up to 700 fields, due to the versatile nature of attr objetcs.
Here is an example :
attr.originatingCommand.$clusterTime.clusterTime.$timestamp.i 37
attr.originatingCommand.$clusterTime.clusterTime.$timestamp.t 1,660,896,607
attr.originatingCommand.$clusterTime.signature.hash.$binary.base64 kIB/B5Yt6HBDKu3aZQmYS4EoiFY=
attr.originatingCommand.$clusterTime.signature.hash.$binary.subType 0
Problem is that some "nested" json objet properties can have different types over time, depending of the log. I have seen this for nearly 10 fields.
Mostly, for properties that have string or number or boolean values, they are getting a JSON object.
In this case we have these kinds of errors :
failed to parse field [attr.XXX.YYYY] of type [text]...Preview of field's value : <<mostly a JSON object>>
here is a clear example, for key attr.error, which is a string in 99% of events:
"failed to parse field [attr.error] of type [text] in document with id 'oUZLsIIBg454KxwnKxz4'. Preview of field's value: '{keyPattern={_id=1}, code=11000, keyValue={_id=xxxxx}, codeName=DuplicateKey, errmsg=E11000 duplicate key error collection: yyyyyyy index: _id_ dup key: { _id: \"xxxxxx\" }}'"
First, I could differentiate with the component and send to different indexes, but I won't be able to go further with that approach (and it's not desirable anyway).
I tried a lot of things, trying to force to convert to string (clearing the index each time) these fields, trying to test them.
The only way I found to avoid the errors is to force a replacement by null for each of the identified fields. This is OK maybe for some, but for "error" this is not.
I maybe missing something , maybe there is a better approach ?
Thanks for your hints