Skip to content

Commit

Permalink
additonal logic to skipping mandatory field
Browse files Browse the repository at this point in the history
  • Loading branch information
khushijain21 committed Nov 4, 2024
1 parent 7b3bcd4 commit 93ca71f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions libbeat/processors/actions/alterFieldProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ func NewAlterFieldProcessor(c *conf.C, processorName string, alterFunc mapstr.Al
var configFields []string
for _, readOnly := range processors.MandatoryExportedFields {
readOnly = strings.ToLower(readOnly)
for i, field := range config.Fields {
if !strings.HasPrefix(strings.ToLower(field), readOnly) {
configFields = append(configFields, config.Fields[i])
for _, field := range config.Fields {
// Skip fields that match "readOnly" or start with "readOnly."
if strings.HasPrefix(strings.ToLower(field), readOnly+".") || strings.ToLower(field) == readOnly {
continue
}
// Add fields that do not match "readOnly" criteria
configFields = append(configFields, field)
}
}
return &alterFieldProcessor{
Expand Down
4 changes: 2 additions & 2 deletions libbeat/processors/actions/lowercase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
func TestNewLowerCaseProcessor(t *testing.T) {
c := conf.MustNewConfigFrom(
mapstr.M{
"fields": []string{"field1", "type", "field2", "type.value.key"}, // "type" is our mandatory field
"fields": []string{"field1", "type", "field2", "type.value.key", "typeKey"}, // "type" is our mandatory field
"ignore_missing": true,
"fail_on_error": false,
},
Expand All @@ -43,7 +43,7 @@ func TestNewLowerCaseProcessor(t *testing.T) {

processor, ok := procInt.(*alterFieldProcessor)
assert.True(t, ok)
assert.Equal(t, []string{"field1", "field2"}, processor.Fields) // we discard both "type" and "typeInput" as mandatory fields
assert.Equal(t, []string{"field1", "field2", "typeKey"}, processor.Fields) // we discard both "type" and "type.value.key" as mandatory fields
assert.True(t, processor.IgnoreMissing)
assert.False(t, processor.FailOnError)
}
Expand Down

0 comments on commit 93ca71f

Please sign in to comment.