Skip to content

Commit 1f4ed43

Browse files
authored
Add k8sevent transform (#1691)
* add k8sevents transform processor * update chlog * add processor pod.uid * resolve conflicts * fix test
1 parent 1f50d4d commit 1f4ed43

File tree

10 files changed

+431
-57
lines changed

10 files changed

+431
-57
lines changed

.chloggen/k8sevent_transform.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: 'enhancement'
3+
# The name of the component, or a single word describing the area of concern, (e.g. agent, clusterReceiver, gateway, operator, chart, other)
4+
component: clusterReceiver
5+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
6+
note: For the option, `clusterReceiver.eventsEnabled`, the logs pipeline for k8s_events now adds attributes of the type `k8s.<objectkind>.name` and `k8s.<objectkind>.uid`.
7+
# One or more tracking issues related to the change
8+
issues: [1691]
9+
# (Optional) One or more lines of additional information to render under the primary note.
10+
# These lines will be padded with 2 spaces and then inserted directly into the document.
11+
# Use pipe (|) for multiline entries.
12+
subtext: |
13+
For example, if the log k8s event is about object type `StatefulSet`, the exported log to Splunk will have these 2 additional attributes:
14+
```
15+
k8s.statefulset.name: value(k8s.object.name)
16+
k8s.statefulset.uid: value(k8s.object.uid)
17+
```
18+
The existing attributes `k8s.object.kind`, `k8s.object.name` and `k8s.object.uid` are still present.
19+
In addition to these, if the event is for kind Pod, and the k8s.object.fieldPath has a specific container spec, the log will have an additional attribute `k8s.container.name` with the value of the container name.

examples/collector-cluster-receiver-only/rendered_manifests/configmap-cluster-receiver.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ data:
4747
- container.image.name
4848
- container.image.tag
4949
pod_association:
50+
- sources:
51+
- from: resource_attribute
52+
name: k8s.pod.uid
5053
- sources:
5154
- from: resource_attribute
5255
name: k8s.namespace.name

examples/collector-cluster-receiver-only/rendered_manifests/deployment-cluster-receiver.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ spec:
3131
component: otel-k8s-cluster-receiver
3232
release: default
3333
annotations:
34-
checksum/config: c1519af3592effec9d730342c24b83201af65992aa06d5dee3b88f7556369316
34+
checksum/config: b805f026a08cbab958512e0705b339006fb1825dc843c8e1be17737805602151
3535
spec:
3636
serviceAccountName: default-splunk-otel-collector
3737
nodeSelector:

functional_tests/internal/common.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,14 @@ func LoadCollectorChart(t *testing.T) *chart.Chart {
174174
require.NoError(t, err)
175175
return c
176176
}
177+
178+
func AnnotateNamespace(t *testing.T, clientset *kubernetes.Clientset, name, key, value string) {
179+
ns, err := clientset.CoreV1().Namespaces().Get(context.TODO(), name, metav1.GetOptions{})
180+
require.NoError(t, err)
181+
if ns.Annotations == nil {
182+
ns.Annotations = make(map[string]string)
183+
}
184+
ns.Annotations[key] = value
185+
_, err = clientset.CoreV1().Namespaces().Update(context.TODO(), ns, metav1.UpdateOptions{})
186+
require.NoError(t, err)
187+
}

functional_tests/k8sevents/k8sevents_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ func Test_K8SEvents(t *testing.T) {
5858
t.Run("CheckK8SEventsLogs", func(t *testing.T) {
5959
actualLogs := selectResLogs("com.splunk.sourcetype", "kube:events", eventsLogsConsumer)
6060
k8sEventsLogs := selectLogs(t, "k8s.namespace.name", "k8sevents-test", &actualLogs, func(body string) string {
61-
re := regexp.MustCompile(`Successfully pulled image "busybox:latest" in .* \(.* including waiting\).*`)
62-
return re.ReplaceAllString(body, `Successfully pulled image "busybox:latest" in <time> (<time> including waiting)`)
61+
re := regexp.MustCompile(`Successfully pulled image "(busybox|alpine):latest" in .* \(.* including waiting\).*`)
62+
return re.ReplaceAllString(body, `Successfully pulled image "$1:latest" in <time> (<time> including waiting)`)
6363
})
6464

6565
// These container attributes may not get added by the k8sattributesprocessor on the events about container image pull/start
@@ -76,6 +76,7 @@ func Test_K8SEvents(t *testing.T) {
7676
plogtest.IgnoreObservedTimestamp(),
7777
plogtest.IgnoreResourceAttributeValue("host.name"),
7878
plogtest.IgnoreLogRecordAttributeValue("k8s.object.uid"),
79+
plogtest.IgnoreLogRecordAttributeValue("k8s.statefulset.uid"),
7980
plogtest.IgnoreLogRecordAttributeValue("k8s.pod.uid"),
8081
plogtest.IgnoreLogRecordAttributeValue("k8s.object.resource_version"),
8182
plogtest.IgnoreResourceLogsOrder(),
@@ -205,6 +206,7 @@ func deployWorkloadAndCollector(t *testing.T) {
205206

206207
// Deploy the workload
207208
internal.CreateNamespace(t, clientset, "k8sevents-test")
209+
internal.AnnotateNamespace(t, clientset, "k8sevents-test", "com.splunk.index", "index_from_namespace")
208210
createdObjs, err := k8stest.CreateObjects(k8sClient, "testdata/testobjects")
209211
require.NoError(t, err)
210212
require.NotEmpty(t, createdObjs)

0 commit comments

Comments
 (0)