Fix: Logs: Pipelines: add nil check for grok parser parseFrom field in generated collector config (#4286)

* chore: add test validating grok parser doesn't spam logs if parse from is missing

* chore: add nil check for grok parser parseFrom
This commit is contained in:
Raj Kamal Singh 2023-12-28 11:03:31 +05:30 committed by GitHub
parent ec27916fa5
commit bcd6ac47f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -101,6 +101,15 @@ func getOperators(ops []PipelineOperator) ([]PipelineOperator, error) {
),
)
} else if operator.Type == "grok_parser" {
parseFromNotNilCheck, err := fieldNotNilCheck(operator.ParseFrom)
if err != nil {
return nil, fmt.Errorf(
"couldn't generate nil check for parseFrom of grok op %s: %w", operator.Name, err,
)
}
operator.If = parseFromNotNilCheck
} else if operator.Type == "json_parser" {
parseFromNotNilCheck, err := fieldNotNilCheck(operator.ParseFrom)
if err != nil {

View File

@ -386,8 +386,19 @@ func TestNoCollectorErrorsFromProcessorsForMismatchedLogs(t *testing.T) {
makeTestLog("mismatching log", map[string]string{
"test_timestamp": "not-an-epoch",
}),
}, {
"grok parser should ignore logs with missing parse from field",
PipelineOperator{
ID: "grok",
Type: "grok_parser",
Enabled: true,
Name: "grok parser",
ParseFrom: "attributes.test",
Pattern: "%{GREEDYDATA}",
ParseTo: "attributes.test_parsed",
},
makeTestLog("test log with missing parse from field", map[string]string{}),
},
// TODO(Raj): see if there is an error scenario for grok parser.
// TODO(Raj): see if there is an error scenario for trace parser.
// TODO(Raj): see if there is an error scenario for Add operator.
}