Skip to content

Commit

Permalink
feat: add support for namespace annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
kkujawa-sumo committed May 9, 2024
1 parent 129e1ce commit 7742c04
Show file tree
Hide file tree
Showing 12 changed files with 170 additions and 12 deletions.
1 change: 1 addition & 0 deletions .changelog/3684.added.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
feat: add support for namespace annotations to set sourceCategory, sourceCategoryPrefix, sourceCategoryReplaceDash, sourceHost, sourceName
6 changes: 6 additions & 0 deletions deploy/helm/sumologic/conf/logs/otelcol/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ processors:
annotations:
- key: "*"
tag_name: "pod_annotations_%s"
namespace_annotations:
- key: "*"
tag_name: namespace_annotations_%s
delimiter: "_"
labels:
- key: "*"
Expand Down Expand Up @@ -342,6 +345,8 @@ processors:
attributes:
- action: delete
pattern: ^pod_annotations_.*
- action: delete
pattern: ^namespace_annotations_.*
{{ end }}

{{ if .Values.sumologic.logs.container.enabled }}
Expand Down Expand Up @@ -370,6 +375,7 @@ processors:
{{ if .Values.sumologic.logs.container.enabled }}
source/containers:
annotation_prefix: "pod_annotations_"
namespace_annotation_prefix: "namespace_annotations_"
collector: {{ .Values.sumologic.collectorName | default .Values.sumologic.clusterName | quote }}
container_annotations:
enabled: {{ .Values.sumologic.logs.container.perContainerAnnotationsEnabled }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ data:
- podName
- serviceName
- statefulSetName
namespace_annotations:
- key: '*'
tag_name: namespace_annotations_%s
namespace_labels:
- key: '*'
tag_name: namespace_labels_%s
Expand All @@ -196,6 +199,8 @@ data:
attributes:
- action: delete
pattern: ^pod_annotations_.*
- action: delete
pattern: ^namespace_annotations_.*
resource/remove_pod_name:
attributes:
- action: delete
Expand Down Expand Up @@ -223,6 +228,7 @@ data:
namespace: ""
node: ""
pod: ""
namespace_annotation_prefix: namespace_annotations_
pod_key: pod
pod_name_key: pod_name
pod_template_hash_key: pod_labels_pod-template-hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ data:
- podName
- serviceName
- statefulSetName
namespace_annotations:
- key: '*'
tag_name: namespace_annotations_%s
namespace_labels:
- key: '*'
tag_name: namespace_labels_%s
Expand All @@ -205,6 +208,8 @@ data:
attributes:
- action: delete
pattern: ^pod_annotations_.*
- action: delete
pattern: ^namespace_annotations_.*
resource/remove_pod_name:
attributes:
- action: delete
Expand Down Expand Up @@ -232,6 +237,7 @@ data:
namespace: ""
node: ""
pod: ""
namespace_annotation_prefix: namespace_annotations_
pod_key: pod
pod_name_key: pod_name
pod_template_hash_key: pod_labels_pod-template-hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ data:
- podName
- serviceName
- statefulSetName
namespace_annotations:
- key: '*'
tag_name: namespace_annotations_%s
namespace_labels:
- key: '*'
tag_name: namespace_labels_%s
Expand All @@ -219,6 +222,8 @@ data:
attributes:
- action: delete
pattern: ^pod_annotations_.*
- action: delete
pattern: ^namespace_annotations_.*
resource/remove_pod_name:
attributes:
- action: delete
Expand Down Expand Up @@ -246,6 +251,7 @@ data:
namespace: ""
node: ""
pod: ""
namespace_annotation_prefix: namespace_annotations_
pod_key: pod
pod_name_key: pod_name
pod_template_hash_key: pod_labels_pod-template-hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ data:
- podName
- serviceName
- statefulSetName
namespace_annotations:
- key: '*'
tag_name: namespace_annotations_%s
namespace_labels:
- key: '*'
tag_name: namespace_labels_%s
Expand All @@ -194,6 +197,8 @@ data:
attributes:
- action: delete
pattern: ^pod_annotations_.*
- action: delete
pattern: ^namespace_annotations_.*
resource/remove_pod_name:
attributes:
- action: delete
Expand Down Expand Up @@ -221,6 +226,7 @@ data:
namespace: ""
node: ""
pod: ""
namespace_annotation_prefix: namespace_annotations_
pod_key: pod
pod_name_key: pod_name
pod_template_hash_key: pod_labels_pod-template-hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ data:
- podName
- serviceName
- statefulSetName
namespace_annotations:
- key: '*'
tag_name: namespace_annotations_%s
namespace_labels:
- key: '*'
tag_name: namespace_labels_%s
Expand Down Expand Up @@ -209,6 +212,8 @@ data:
attributes:
- action: delete
pattern: ^pod_annotations_.*
- action: delete
pattern: ^namespace_annotations_.*
resource/remove-container:
attributes:
- action: delete
Expand Down Expand Up @@ -248,6 +253,7 @@ data:
namespace: my_containers_excludeNamespaceRegex
node: my_containers_excludeHostRegex
pod: my_containers_excludePodRegex
namespace_annotation_prefix: namespace_annotations_
pod_key: pod
pod_name_key: pod_name
pod_template_hash_key: pod_labels_pod-template-hash
Expand Down
54 changes: 42 additions & 12 deletions tests/integration/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,19 @@ const (
// number of log records in single loop with default multiline support only, see: tests/integration/yamls/pod_multiline_long_lines.yaml
logRecords = 4 + 10
// number of log records in single loop with multiple multilines support, see: tests/integration/yamls/pod_multiline_long_lines.yaml
multipleLogRecords = 4 + 4
logLoops = 500 // number of loops in which logs are generated, see: tests/integration/yamls/pod_multiline_long_lines.yaml
multilineLogCount uint = logRecords * logLoops
multipleMultilineLogCount uint = multipleLogRecords * logLoops
tracesPerExporter uint = 5 // number of traces generated per exporter
spansPerTrace uint = 2
Prometheus MetricsCollector = "prometheus"
Otelcol MetricsCollector = "otelcol"
TailingSidecarCount uint = 150 // number of logs generated by tailing sidecar test (50 * 3), see: tests/inegration/yamls/tailing-sidecar-test.yaml
AnnotationsLogsCount uint = 150 // number of logs generated by containers used in annotations test (50 * 3), see: tests/inegration/yamls/annotations-test.yaml
curlAppMaxWaitTime uint = 180
curlAppSleepInterval uint = 5
multipleLogRecords = 4 + 4
logLoops = 500 // number of loops in which logs are generated, see: tests/integration/yamls/pod_multiline_long_lines.yaml
multilineLogCount uint = logRecords * logLoops
multipleMultilineLogCount uint = multipleLogRecords * logLoops
tracesPerExporter uint = 5 // number of traces generated per exporter
spansPerTrace uint = 2
Prometheus MetricsCollector = "prometheus"
Otelcol MetricsCollector = "otelcol"
TailingSidecarCount uint = 150 // number of logs generated by tailing sidecar test (50 * 3), see: tests/inegration/yamls/tailing-sidecar-test.yaml
AnnotationsLogsCount uint = 150 // number of logs generated by containers used in annotations test (50 * 3), see: tests/inegration/yamls/annotations-test.yaml
NamespaceAnnotationsLogsCount uint = 150 // number of logs generated by containers used in annotations test (50 * 3), see: tests/inegration/yamls/namespace-annotations-test.yaml
curlAppMaxWaitTime uint = 180
curlAppSleepInterval uint = 5
)

func GetMetricsFeature(expectedMetrics []string, metricsCollector MetricsCollector) features.Feature {
Expand Down Expand Up @@ -810,6 +811,35 @@ func GetAnnotationsFeature() features.Feature {
Feature()
}

func GetNamespaceAnnotationsFeature() features.Feature {
return features.New("namespace annotations test").
Setup(stepfuncs.KubectlApplyFOpt(internal.NamespaceAnnotationsTest, internal.NamespaceAnnotationsTestNamespace)).
Assess("pod annotations are applied", stepfuncs.WaitUntilExpectedLogsPresent(
AnnotationsLogsCount,
map[string]string{
"namespace": internal.NamespaceAnnotationsTestNamespace,
"_sourceCategory": "namespace#Source#Category#PrefixnamespaceSourceCategory",
"_sourceHost": "namespaceSourceHost",
"_sourceName": "namespaceSourceName",
},
waitDuration,
tickDuration,
)).
Assess("container annotation is applied", stepfuncs.WaitUntilExpectedLogsPresent(
AnnotationsLogsCount,
map[string]string{
"namespace": internal.NamespaceAnnotationsTestNamespace,
"_sourceCategory": "podSource!Category!PrefixpodSourceCategory",
"_sourceHost": "podSourceHost",
"_sourceName": "podSourceName",
},
waitDuration,
tickDuration,
)).
Teardown(stepfuncs.KubectlDeleteFOpt(internal.NamespaceAnnotationsTest, internal.NamespaceAnnotationsTestNamespace)).
Feature()
}

type featureCheck func(*features.FeatureBuilder) *features.FeatureBuilder

func GetInstallFeature(installChecks []featureCheck) features.Feature {
Expand Down
20 changes: 20 additions & 0 deletions tests/integration/helm_namespace_annotations_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//go:build onlylatest
// +build onlylatest

package integration

import (
"testing"
)

func Test_Helm_Namespace_Annotations(t *testing.T) {
installChecks := []featureCheck{
CheckOtelcolMetadataLogsInstall,
}

featInstall := GetInstallFeature(installChecks)

featAnnotationsTest := GetNamespaceAnnotationsFeature()

testenv.Test(t, featInstall, featAnnotationsTest)
}
3 changes: 3 additions & 0 deletions tests/integration/internal/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ const (
AnnotationsTestNamespace = "annotations-test"
AnnotationsTest = "yamls/annotations-test.yaml"

NamespaceAnnotationsTestNamespace = "namespace-annotations-test"
NamespaceAnnotationsTest = "yamls/namespace-annotations-test.yaml"

NginxTelegrafMetricsTest = "yamls/nginx.yaml"
NginxTelegrafNamespace = "nginx"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
sumologic:
events:
enabled: false
metrics:
enabled: false
traces:
enabled: false
61 changes: 61 additions & 0 deletions tests/integration/yamls/namespace-annotations-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
apiVersion: v1
kind: Namespace
metadata:
annotations:
sumologic.com/include: "true"
sumologic.com/sourceCategory: "namespaceSourceCategory"
sumologic.com/sourceCategoryPrefix: "namespace-Source-Category-Prefix"
sumologic.com/sourceCategoryReplaceDash: "#"
sumologic.com/sourceHost: "namespaceSourceHost"
sumologic.com/sourceName: "namespaceSourceName"
name: namespace-annotations-test
---
apiVersion: v1
kind: Pod
metadata:
name: pod-a
namespace: namespace-annotations-test
spec:
containers:
- name: container1
image: bash
args:
- /usr/local/bin/bash
- -c
- >
i=0; for i in {1..50}; do
echo "example0: $i $(date)"
echo "example1: $i $(date)"
echo "example2: $i $(date)"
sleep 1;
done; while true; do
sleep 1;
done;
---
apiVersion: v1
kind: Pod
metadata:
name: pod-b
namespace: namespace-annotations-test
annotations:
sumologic.com/sourceCategory: "podSourceCategory"
sumologic.com/sourceCategoryPrefix: "podSource-Category-Prefix"
sumologic.com/sourceCategoryReplaceDash: "!"
sumologic.com/sourceHost: "podSourceHost"
sumologic.com/sourceName: "podSourceName"
spec:
containers:
- name: container1
image: bash
args:
- /usr/local/bin/bash
- -c
- >
i=0; for i in {1..50}; do
echo "example0: $i $(date)"
echo "example1: $i $(date)"
echo "example2: $i $(date)"
sleep 1;
done; while true; do
sleep 1;
done;

0 comments on commit 7742c04

Please sign in to comment.