-
Notifications
You must be signed in to change notification settings - Fork 488
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add configurable fields loki source cloudflare (#4765)
* add custom_fields to cloudfare config * refactor custom fields * add tests * update CHANGELOG.md * compare to const instead of string literal * add comment for FindInvalidFields func * update loki source cloudflare doc * fix loki source cloudflare doc * minor refactoring/renaming following review * improve doc and namings * remove validation check for cloudfare additional fields * improve handling of additional fields and original subsets * use slices sort instead of map to remove duplicates * Update component/loki/source/cloudflare/internal/cloudflaretarget/fields.go Co-authored-by: Piotr <[email protected]> * fix slice append --------- Co-authored-by: Piotr <[email protected]>
- Loading branch information
Showing
6 changed files
with
101 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
component/loki/source/cloudflare/internal/cloudflaretarget/fields_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package cloudflaretarget | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestFields(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
fieldsType FieldsType | ||
additionalFields []string | ||
expected []string | ||
}{ | ||
{ | ||
name: "Default fields", | ||
fieldsType: FieldsTypeDefault, | ||
additionalFields: []string{}, | ||
expected: defaultFields, | ||
}, | ||
{ | ||
name: "Custom fields", | ||
fieldsType: FieldsTypeCustom, | ||
additionalFields: []string{"ClientIP", "OriginResponseBytes"}, | ||
expected: []string{"ClientIP", "OriginResponseBytes"}, | ||
}, | ||
{ | ||
name: "Default fields with added custom fields", | ||
fieldsType: FieldsTypeDefault, | ||
additionalFields: []string{"WAFFlags", "WAFMatchedVar"}, | ||
expected: append(defaultFields, "WAFFlags", "WAFMatchedVar"), | ||
}, | ||
{ | ||
name: "Default fields with duplicated custom fields", | ||
fieldsType: FieldsTypeDefault, | ||
additionalFields: []string{"WAFFlags", "WAFFlags", "ClientIP"}, | ||
expected: append(defaultFields, "WAFFlags"), // clientIP is already part of defaultFields | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
result, err := Fields(test.fieldsType, test.additionalFields) | ||
assert.NoError(t, err) | ||
assert.ElementsMatch(t, test.expected, result) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters