Skip to content

Commit

Permalink
Add LogEntry severity and sourceLocation mappings in systemd_journald…
Browse files Browse the repository at this point in the history
… receiver. (#502)

* Journald receiver now transform keys from JSON to Cloud Logging JSON

Transform keys from journald JSON to Cloud Logging JSON. This adds
severity, message, and sourceLocation to the logging JSON.

* Removing message change since it can break old pipelines
  • Loading branch information
rafaelwestphal committed Apr 1, 2022
1 parent 326b5d6 commit de62282
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 1 deletion.
53 changes: 52 additions & 1 deletion confgenerator/logging_receivers.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func (r LoggingReceiverSystemd) Type() string {
}

func (r LoggingReceiverSystemd) Components(tag string) []fluentbit.Component {
return []fluentbit.Component{{
input := []fluentbit.Component{{
Kind: "INPUT",
Config: map[string]string{
// https://docs.fluentbit.io/manual/pipeline/inputs/systemd
Expand All @@ -353,6 +353,57 @@ func (r LoggingReceiverSystemd) Components(tag string) []fluentbit.Component {
"DB": DBPath(tag),
},
}}
filters := fluentbit.TranslationComponents(tag, "PRIORITY", "logging.googleapis.com/severity", false,
[]struct{ SrcVal, DestVal string }{
{"7", "DEBUG"},
{"6", "INFO"},
{"5", "NOTICE"},
{"4", "WARNING"},
{"3", "ERROR"},
{"2", "CRITICAL"},
{"1", "ALERT"},
{"0", "EMERGENCY"},
})
input = append(input, filters...)
input = append(input, fluentbit.Component{
Kind: "FILTER",
Config: map[string]string{
"Name": "modify",
"Match": tag,
"Condition": fmt.Sprintf("Key_exists %s", "CODE_FILE"),
"Copy": fmt.Sprintf("CODE_FILE %s", "logging.googleapis.com/sourceLocation/file"),
},
})
input = append(input, fluentbit.Component{
Kind: "FILTER",
Config: map[string]string{
"Name": "modify",
"Match": tag,
"Condition": fmt.Sprintf("Key_exists %s", "CODE_FUNC"),
"Copy": fmt.Sprintf("CODE_FUNC %s", "logging.googleapis.com/sourceLocation/function"),
},
})
input = append(input, fluentbit.Component{
Kind: "FILTER",
Config: map[string]string{
"Name": "modify",
"Match": tag,
"Condition": fmt.Sprintf("Key_exists %s", "CODE_LINE"),
"Copy": fmt.Sprintf("CODE_LINE %s", "logging.googleapis.com/sourceLocation/line"),
},
})
input = append(input, fluentbit.Component{
Kind: "FILTER",
Config: map[string]string{
"Name": "nest",
"Match": tag,
"Operation": "nest",
"Wildcard": "logging.googleapis.com/sourceLocation/*",
"Nest_under": "logging.googleapis.com/sourceLocation",
"Remove_prefix": "logging.googleapis.com/sourceLocation/",
},
})
return input
}

func init() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,80 @@
Match default_pipeline.syslog
Name modify

[FILTER]
Add logging.googleapis.com/severity DEBUG
Condition Key_Value_Equals PRIORITY 7
Match systemd_pipeline.systemd_logs
Name modify

[FILTER]
Add logging.googleapis.com/severity INFO
Condition Key_Value_Equals PRIORITY 6
Match systemd_pipeline.systemd_logs
Name modify

[FILTER]
Add logging.googleapis.com/severity NOTICE
Condition Key_Value_Equals PRIORITY 5
Match systemd_pipeline.systemd_logs
Name modify

[FILTER]
Add logging.googleapis.com/severity WARNING
Condition Key_Value_Equals PRIORITY 4
Match systemd_pipeline.systemd_logs
Name modify

[FILTER]
Add logging.googleapis.com/severity ERROR
Condition Key_Value_Equals PRIORITY 3
Match systemd_pipeline.systemd_logs
Name modify

[FILTER]
Add logging.googleapis.com/severity CRITICAL
Condition Key_Value_Equals PRIORITY 2
Match systemd_pipeline.systemd_logs
Name modify

[FILTER]
Add logging.googleapis.com/severity ALERT
Condition Key_Value_Equals PRIORITY 1
Match systemd_pipeline.systemd_logs
Name modify

[FILTER]
Add logging.googleapis.com/severity EMERGENCY
Condition Key_Value_Equals PRIORITY 0
Match systemd_pipeline.systemd_logs
Name modify

[FILTER]
Condition Key_exists CODE_FILE
Copy CODE_FILE logging.googleapis.com/sourceLocation/file
Match systemd_pipeline.systemd_logs
Name modify

[FILTER]
Condition Key_exists CODE_FUNC
Copy CODE_FUNC logging.googleapis.com/sourceLocation/function
Match systemd_pipeline.systemd_logs
Name modify

[FILTER]
Condition Key_exists CODE_LINE
Copy CODE_LINE logging.googleapis.com/sourceLocation/line
Match systemd_pipeline.systemd_logs
Name modify

[FILTER]
Match systemd_pipeline.systemd_logs
Name nest
Nest_under logging.googleapis.com/sourceLocation
Operation nest
Remove_prefix logging.googleapis.com/sourceLocation/
Wildcard logging.googleapis.com/sourceLocation/*

[FILTER]
Add logging.googleapis.com/logName systemd_logs
Match systemd_pipeline.systemd_logs
Expand Down

0 comments on commit de62282

Please sign in to comment.