Skip to content
Snippets Groups Projects
Commit 0947750c authored by ale's avatar ale
Browse files

Recurse JSON decoding into multiple levels of 'message' attributes

Ignore case, to cover 'message.MESSAGE', which we encounter with the
logging-operator host-tailer.
parent 311b9a9b
No related branches found
No related tags found
No related merge requests found
Pipeline #66538 passed
......@@ -83,13 +83,22 @@ func unmarshalRecordRecursively(record []byte) (map[string]any, error) {
return nil, err
}
// Try to unmarshal 'message' if it looks like JSON (with optional @cee prefix).
// Try to unmarshal 'message' (or 'MESSAGE') if it looks like
// JSON (possibly with an optional '@cee:' prefix).
var message, fieldName string
if s, ok := m["message"].(string); ok {
s = strings.TrimPrefix(s, "@cee:")
if strings.HasPrefix(s, "{") {
var m2 map[string]any
if err := json.NewDecoder(strings.NewReader(s)).Decode(&m2); err == nil {
m["message"] = m2
fieldName = "message"
message = s
} else if s, ok := m["MESSAGE"].(string); ok {
fieldName = "MESSAGE"
message = s
}
if message != "" {
message = strings.TrimPrefix(message, "@cee:")
if strings.HasPrefix(message, "{") {
if m2, err := unmarshalRecordRecursively([]byte(message)); err == nil {
m[fieldName] = m2
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment