Skip to content

Commit

Permalink
fix(sourceprocessor): add templating to sourceCategoryPrefix
Browse files Browse the repository at this point in the history
  • Loading branch information
aboguszewski-sumo committed Nov 17, 2023
1 parent f9a2a3b commit 3560fbb
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions .changelog/1339.fixed.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix(sourceprocessor): add templating to sourceCategoryPrefix
2 changes: 1 addition & 1 deletion pkg/processor/sourceprocessor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ processors:
# Template for source category, put in `_sourceCategory` tag.
# default: "%{k8s.namespace.name}/%{k8s.pod.pod_name}"
source_category: <source_category>
# Prefix added before each `_sourceCategory` value.
# Template added before each `_sourceCategory` value.
# default: "kubernetes/"
source_category_prefix: <source_category_prefix>
# Character which all dashes ("-") in source category value are being replaced to.
Expand Down
5 changes: 3 additions & 2 deletions pkg/processor/sourceprocessor/source_category_filler.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,14 @@ func (f *sourceCategoryFiller) fill(attributes *pcommon.Map) {
valueTemplate = f.valueTemplate
templateAttributes = f.templateAttributes
}
sourceCategoryValue := f.replaceTemplateAttributes(valueTemplate, templateAttributes, attributes)

prefix := getAnnotationAttributeValue(f.annotationPrefix, sourceCategoryPrefixAnnotation, attributes)
if prefix == "" {
prefix = f.prefix
}
sourceCategoryValue = prefix + sourceCategoryValue
valueTemplate = prefix + valueTemplate

sourceCategoryValue := f.replaceTemplateAttributes(valueTemplate, templateAttributes, attributes)

dashReplacement := getAnnotationAttributeValue(f.annotationPrefix, sourceCategoryReplaceDashAnnotation, attributes)
if dashReplacement == "" {
Expand Down
4 changes: 2 additions & 2 deletions pkg/processor/sourceprocessor/source_category_filler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ func TestFillWithAnnotations(t *testing.T) {
attrs.PutStr("k8s.namespace.name", "ns-1")
attrs.PutStr("k8s.pod.uid", "123asd")
attrs.PutStr("k8s.pod.annotation.sumologic.com/sourceCategory", "sc-from-annot-%{k8s.namespace.name}-%{k8s.pod.uid}")
attrs.PutStr("k8s.pod.annotation.sumologic.com/sourceCategoryPrefix", "annoPrefix:")
attrs.PutStr("k8s.pod.annotation.sumologic.com/sourceCategoryPrefix", "%{k8s.pod.uid}-Prefix:")
attrs.PutStr("k8s.pod.annotation.sumologic.com/sourceCategoryReplaceDash", "#")

filler := newSourceCategoryFiller(cfg, zap.NewNop())
filler.fill(&attrs)

assertAttribute(t, attrs, "_sourceCategory", "annoPrefix:sc#from#annot#ns#1#123asd")
assertAttribute(t, attrs, "_sourceCategory", "123asd#Prefix:sc#from#annot#ns#1#123asd")
}

func TestFillWithContainerAnnotations(t *testing.T) {
Expand Down

0 comments on commit 3560fbb

Please sign in to comment.