From 93ca71f700cfd1d42eb5ea7fb47ba8b70d31be8c Mon Sep 17 00:00:00 2001 From: Khushi Jain Date: Mon, 4 Nov 2024 21:39:00 +0530 Subject: [PATCH] additonal logic to skipping mandatory field --- libbeat/processors/actions/alterFieldProcessor.go | 9 ++++++--- libbeat/processors/actions/lowercase_test.go | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/libbeat/processors/actions/alterFieldProcessor.go b/libbeat/processors/actions/alterFieldProcessor.go index e3d6919c538..9413852a8fb 100644 --- a/libbeat/processors/actions/alterFieldProcessor.go +++ b/libbeat/processors/actions/alterFieldProcessor.go @@ -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{ diff --git a/libbeat/processors/actions/lowercase_test.go b/libbeat/processors/actions/lowercase_test.go index 19ce376714a..4723cff27f3 100644 --- a/libbeat/processors/actions/lowercase_test.go +++ b/libbeat/processors/actions/lowercase_test.go @@ -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, }, @@ -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) }