Skip to content

Commit 8890821

Browse files
Fix metrics sourcetype annotation (#1375)
* Fix sourcetype annotation for metrics * Update .chloggen, examples and tests * Update fixmetricssourcetypeannotation.yaml * Remove metricsSourceType for sourcetype * Remove metricsSourceType for sourcetype * Remove metricsSourceType for sourcetype * Implement code review suggestions * re-render examples * Remove unnecessary if clause
1 parent 1c0c05a commit 8890821

24 files changed

+126
-12
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: bug_fix
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: other
5+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
6+
note: Fixed updating metrics' sourcetype with annotations
7+
# One or more tracking issues related to the change
8+
issues: [1375]
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:

docs/advanced-configuration.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,8 @@ Manage Splunk OTel Collector Logging with these supported annotations.
564564
* Filter logs using pod and/or namespace annotation
565565
* If `logsCollection.containers.useSplunkIncludeAnnotation` is `false` (default: false), set `splunk.com/exclude` annotation to `true` on pod and/or namespace to exclude its logs from ingested.
566566
* If `logsCollection.containers.useSplunkIncludeAnnotation` is `true` (default: false), set `splunk.com/include` annotation to `true` on pod and/or namespace to only include its logs from ingested. All other logs will be ignored.
567-
* Use `splunk.com/sourcetype` annotation on pod to overwrite `sourcetype` field. If not set, it is dynamically generated to be `kube:container:CONTAINER_NAME`.
567+
* For logs, use `splunk.com/sourcetype` annotation on pod to overwrite `sourcetype` field. If not set, it is dynamically generated to be `kube:container:CONTAINER_NAME`.
568+
* For metrics, use the `splunk.com/sourcetype` annotation on the namespace to override the sourcetype field. If not set, it defaults to `httpevent`.
568569

569570
### Performance of native OpenTelemetry logs collection
570571

examples/disable-persistence-queue-traces/rendered_manifests/configmap-agent.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,12 @@ data:
161161
k8sattributes/metrics:
162162
extract:
163163
annotations:
164+
- from: namespace
165+
key: splunk.com/sourcetype
166+
tag_name: com.splunk.sourcetype
164167
- from: pod
165168
key: splunk.com/sourcetype
169+
tag_name: com.splunk.sourcetype
166170
- from: namespace
167171
key: splunk.com/metricsIndex
168172
tag_name: com.splunk.index

examples/disable-persistence-queue-traces/rendered_manifests/configmap-cluster-receiver.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@ data:
5050
k8sattributes/metrics:
5151
extract:
5252
annotations:
53+
- from: namespace
54+
key: splunk.com/sourcetype
55+
tag_name: com.splunk.sourcetype
5356
- from: pod
5457
key: splunk.com/sourcetype
58+
tag_name: com.splunk.sourcetype
5559
- from: namespace
5660
key: splunk.com/metricsIndex
5761
tag_name: com.splunk.index

examples/disable-persistence-queue-traces/rendered_manifests/daemonset.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ spec:
3232
component: otel-collector-agent
3333
release: default
3434
annotations:
35-
checksum/config: 2ec1c7329487d2d512b428c60b4250ab94617daac606d6743bf55d1d12ba4612
35+
checksum/config: e2dd00b071f073e9a34cf91692e448859d2411b6cc37c8aef56e01ec66a7f241
3636
kubectl.kubernetes.io/default-container: otel-collector
3737
spec:
3838
hostNetwork: true

examples/disable-persistence-queue-traces/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: bc14c64fe9c32c4096cd0e0df15b75d79d168de86101cd6805367a5acc1333c3
34+
checksum/config: 28e46c5046b15065a3b498e52faef708337d402885225a0de09f290a9e1da1e9
3535
spec:
3636
serviceAccountName: default-splunk-otel-collector
3737
nodeSelector:

examples/enable-persistence-queue/rendered_manifests/configmap-agent.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,12 @@ data:
161161
k8sattributes/metrics:
162162
extract:
163163
annotations:
164+
- from: namespace
165+
key: splunk.com/sourcetype
166+
tag_name: com.splunk.sourcetype
164167
- from: pod
165168
key: splunk.com/sourcetype
169+
tag_name: com.splunk.sourcetype
166170
- from: namespace
167171
key: splunk.com/metricsIndex
168172
tag_name: com.splunk.index

examples/enable-persistence-queue/rendered_manifests/configmap-cluster-receiver.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@ data:
5050
k8sattributes/metrics:
5151
extract:
5252
annotations:
53+
- from: namespace
54+
key: splunk.com/sourcetype
55+
tag_name: com.splunk.sourcetype
5356
- from: pod
5457
key: splunk.com/sourcetype
58+
tag_name: com.splunk.sourcetype
5559
- from: namespace
5660
key: splunk.com/metricsIndex
5761
tag_name: com.splunk.index

examples/enable-persistence-queue/rendered_manifests/daemonset.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ spec:
3232
component: otel-collector-agent
3333
release: default
3434
annotations:
35-
checksum/config: f9c882714a6a5086b2f406ad5bd7bc97e6e101d22dc24632acbcbd3985d32e0f
35+
checksum/config: 65e1add475e3e56be5f06e7396676f3488a53f49569179de7e8c56f300eaa2a7
3636
kubectl.kubernetes.io/default-container: otel-collector
3737
spec:
3838
hostNetwork: true

examples/enable-persistence-queue/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: bc14c64fe9c32c4096cd0e0df15b75d79d168de86101cd6805367a5acc1333c3
34+
checksum/config: 28e46c5046b15065a3b498e52faef708337d402885225a0de09f290a9e1da1e9
3535
spec:
3636
serviceAccountName: default-splunk-otel-collector
3737
nodeSelector:

examples/multi-metrics/rendered_manifests/configmap-agent.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,12 @@ data:
133133
k8sattributes/metrics:
134134
extract:
135135
annotations:
136+
- from: namespace
137+
key: splunk.com/sourcetype
138+
tag_name: com.splunk.sourcetype
136139
- from: pod
137140
key: splunk.com/sourcetype
141+
tag_name: com.splunk.sourcetype
138142
- from: namespace
139143
key: splunk.com/metricsIndex
140144
tag_name: com.splunk.index

examples/multi-metrics/rendered_manifests/configmap-cluster-receiver.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@ data:
5050
k8sattributes/metrics:
5151
extract:
5252
annotations:
53+
- from: namespace
54+
key: splunk.com/sourcetype
55+
tag_name: com.splunk.sourcetype
5356
- from: pod
5457
key: splunk.com/sourcetype
58+
tag_name: com.splunk.sourcetype
5559
- from: namespace
5660
key: splunk.com/metricsIndex
5761
tag_name: com.splunk.index

examples/multi-metrics/rendered_manifests/daemonset.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ spec:
3232
component: otel-collector-agent
3333
release: default
3434
annotations:
35-
checksum/config: 30b7626f53600444b8fd92d896123901004a4070e673276e68046fbf33149280
35+
checksum/config: 8745d73647576685177b6fbd0d78c980ad9113d44a008f9414cc8ab4adddff3d
3636
kubectl.kubernetes.io/default-container: otel-collector
3737
spec:
3838
hostNetwork: true

examples/multi-metrics/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: bc14c64fe9c32c4096cd0e0df15b75d79d168de86101cd6805367a5acc1333c3
34+
checksum/config: 28e46c5046b15065a3b498e52faef708337d402885225a0de09f290a9e1da1e9
3535
spec:
3636
serviceAccountName: default-splunk-otel-collector
3737
nodeSelector:

examples/only-metrics-platform/rendered_manifests/configmap-agent.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,12 @@ data:
106106
k8sattributes/metrics:
107107
extract:
108108
annotations:
109+
- from: namespace
110+
key: splunk.com/sourcetype
111+
tag_name: com.splunk.sourcetype
109112
- from: pod
110113
key: splunk.com/sourcetype
114+
tag_name: com.splunk.sourcetype
111115
- from: namespace
112116
key: splunk.com/metricsIndex
113117
tag_name: com.splunk.index

examples/only-metrics-platform/rendered_manifests/configmap-cluster-receiver.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@ data:
5050
k8sattributes/metrics:
5151
extract:
5252
annotations:
53+
- from: namespace
54+
key: splunk.com/sourcetype
55+
tag_name: com.splunk.sourcetype
5356
- from: pod
5457
key: splunk.com/sourcetype
58+
tag_name: com.splunk.sourcetype
5559
- from: namespace
5660
key: splunk.com/metricsIndex
5761
tag_name: com.splunk.index

examples/only-metrics-platform/rendered_manifests/daemonset.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ spec:
3232
component: otel-collector-agent
3333
release: default
3434
annotations:
35-
checksum/config: d54094aac0f8b04d578e2d8ba3b5a5dcda52b09208458de4e9ea58a942dc6355
35+
checksum/config: c977b9304cb278d5df51904fe83364224322d0b2a033bf0b718f86ccb45b6d3e
3636
kubectl.kubernetes.io/default-container: otel-collector
3737
spec:
3838
hostNetwork: true

examples/only-metrics-platform/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: bc14c64fe9c32c4096cd0e0df15b75d79d168de86101cd6805367a5acc1333c3
34+
checksum/config: 28e46c5046b15065a3b498e52faef708337d402885225a0de09f290a9e1da1e9
3535
spec:
3636
serviceAccountName: default-splunk-otel-collector
3737
nodeSelector:

helm-charts/splunk-otel-collector/templates/config/_common.tpl

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ k8sattributes/clusterReceiver:
235235
{{- if eq (include "splunk-otel-collector.splunkPlatformEnabled" .) "true"}}
236236
annotations:
237237
- key: splunk.com/sourcetype
238+
tag_name: com.splunk.sourcetype
239+
from: namespace
240+
- key: splunk.com/sourcetype
241+
tag_name: com.splunk.sourcetype
238242
from: pod
239243
- key: splunk.com/index
240244
tag_name: com.splunk.index
@@ -269,6 +273,10 @@ k8sattributes/metrics:
269273
metadata: []
270274
annotations:
271275
- key: splunk.com/sourcetype
276+
tag_name: com.splunk.sourcetype
277+
from: namespace
278+
- key: splunk.com/sourcetype
279+
tag_name: com.splunk.sourcetype
272280
from: pod
273281
- key: splunk.com/metricsIndex
274282
tag_name: com.splunk.index
@@ -341,6 +349,18 @@ resource/logs:
341349
{{- end }}
342350
{{- end }}
343351

352+
{{/*
353+
Resource processor for metrics manipulations
354+
*/}}
355+
{{- define "splunk-otel-collector.resourceMetricsProcessor" -}}
356+
resource/metrics:
357+
attributes:
358+
# Insert the sourcetype value from values.yaml if it has not already been set through annotations.
359+
- key: com.splunk.sourcetype
360+
value: "{{.Values.splunkPlatform.sourcetype }}"
361+
action: insert
362+
{{- end }}
363+
344364
{{/*
345365
The transform processor adds service.name attribute to logs the same way as it's done by istio for the generated traces
346366
https://github.com/istio/istio/blob/6237cb4e63cf9a332327cc0a815d6b46257e6f8a/pkg/config/analysis/analyzers/testdata/common/sidecar-injector-configmap.yaml#L110-L115
@@ -436,9 +456,6 @@ splunk_hec/platform_metrics:
436456
token: "${SPLUNK_PLATFORM_HEC_TOKEN}"
437457
index: {{ .Values.splunkPlatform.metricsIndex | quote }}
438458
source: {{ .Values.splunkPlatform.source | quote }}
439-
{{- if .Values.splunkPlatform.sourcetype }}
440-
sourcetype: {{ .Values.splunkPlatform.sourcetype | quote }}
441-
{{- end }}
442459
max_idle_conns: {{ .Values.splunkPlatform.maxConnections }}
443460
max_idle_conns_per_host: {{ .Values.splunkPlatform.maxConnections }}
444461
disable_compression: {{ .Values.splunkPlatform.disableCompression }}

helm-charts/splunk-otel-collector/templates/config/_otel-agent.tpl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,9 @@ processors:
675675
{{- include "splunk-otel-collector.k8sAttributesSplunkPlatformMetrics" . | nindent 2 }}
676676
filter:
677677
node_from_env_var: K8S_NODE_NAME
678+
{{- if .Values.splunkPlatform.sourcetype }}
679+
{{- include "splunk-otel-collector.resourceMetricsProcessor" . | nindent 2 }}
680+
{{- end }}
678681
{{- end }}
679682
680683
{{- if eq .Values.logsEngine "fluentd" }}
@@ -1065,6 +1068,9 @@ service:
10651068
{{- end }}
10661069
{{- if (eq (include "splunk-otel-collector.platformMetricsEnabled" $) "true") }}
10671070
- k8sattributes/metrics
1071+
{{- if .Values.splunkPlatform.sourcetype }}
1072+
- resource/metrics
1073+
{{- end }}
10681074
{{- end }}
10691075
exporters:
10701076
{{- if $gatewayEnabled }}
@@ -1092,6 +1098,9 @@ service:
10921098
- resource/add_mode
10931099
{{- if (eq (include "splunk-otel-collector.platformMetricsEnabled" $) "true") }}
10941100
- k8sattributes/metrics
1101+
{{- if .Values.splunkPlatform.sourcetype }}
1102+
- resource/metrics
1103+
{{- end }}
10951104
{{- end }}
10961105
exporters:
10971106
{{- if (eq (include "splunk-otel-collector.splunkO11yEnabled" .) "true") }}

helm-charts/splunk-otel-collector/templates/config/_otel-collector.tpl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ processors:
3333
{{- include "splunk-otel-collector.k8sAttributesSplunkPlatformMetrics" . | nindent 2 }}
3434
filter:
3535
node_from_env_var: K8S_NODE_NAME
36+
{{- if .Values.splunkPlatform.sourcetype }}
37+
{{- include "splunk-otel-collector.resourceMetricsProcessor" . | nindent 2 }}
38+
{{- end }}
3639
{{- end }}
3740

3841
{{- include "splunk-otel-collector.resourceLogsProcessor" . | nindent 2 }}
@@ -220,6 +223,9 @@ service:
220223
{{- end }}
221224
{{- if (eq (include "splunk-otel-collector.platformMetricsEnabled" $) "true") }}
222225
- k8sattributes/metrics
226+
{{- if .Values.splunkPlatform.sourcetype }}
227+
- resource/metrics
228+
{{- end }}
223229
{{- end }}
224230
exporters:
225231
{{- if (eq (include "splunk-otel-collector.o11yMetricsEnabled" .) "true") }}
@@ -275,6 +281,9 @@ service:
275281
{{- end }}
276282
{{- if (eq (include "splunk-otel-collector.platformMetricsEnabled" $) "true") }}
277283
- k8sattributes/metrics
284+
{{- if .Values.splunkPlatform.sourcetype }}
285+
- resource/metrics
286+
{{- end }}
278287
{{- end }}
279288
exporters:
280289
{{- if (eq (include "splunk-otel-collector.splunkO11yEnabled" .) "true") }}

helm-charts/splunk-otel-collector/templates/config/_otel-k8s-cluster-receiver-config.tpl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ processors:
7979
{{- include "splunk-otel-collector.k8sAttributesSplunkPlatformMetrics" . | nindent 2 }}
8080
filter:
8181
node_from_env_var: K8S_NODE_NAME
82+
{{- if .Values.splunkPlatform.sourcetype }}
83+
{{- include "splunk-otel-collector.resourceMetricsProcessor" . | nindent 2 }}
84+
{{- end }}
8285
{{- end }}
8386

8487
batch:
@@ -270,6 +273,9 @@ service:
270273
- resource
271274
{{- if (eq (include "splunk-otel-collector.platformMetricsEnabled" $) "true") }}
272275
- k8sattributes/metrics
276+
{{- if .Values.splunkPlatform.sourcetype }}
277+
- resource/metrics
278+
{{- end }}
273279
{{- end }}
274280
- resource/k8s_cluster
275281
exporters:
@@ -292,6 +298,9 @@ service:
292298
- resource
293299
{{- if (eq (include "splunk-otel-collector.platformMetricsEnabled" $) "true") }}
294300
- k8sattributes/metrics
301+
{{- if .Values.splunkPlatform.sourcetype }}
302+
- resource/metrics
303+
{{- end }}
295304
{{- end }}
296305
exporters:
297306
{{- if (eq (include "splunk-otel-collector.o11yMetricsEnabled" .) "true") }}
@@ -314,6 +323,9 @@ service:
314323
- resource/add_mode
315324
{{- if (eq (include "splunk-otel-collector.platformMetricsEnabled" $) "true") }}
316325
- k8sattributes/metrics
326+
{{- if .Values.splunkPlatform.sourcetype }}
327+
- resource/metrics
328+
{{- end }}
317329
{{- end }}
318330
exporters:
319331
{{- if (eq (include "splunk-otel-collector.o11yMetricsEnabled" .) "true") }}

test/k8s_logging_tests/test_config_logging.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,24 @@ def test_metric_index_from_annotations(setup, index, expected):
8181
logger.info("Splunk received %s events in the last minute",
8282
len(events))
8383
assert len(events) >= expected
84+
85+
@pytest.mark.parametrize("index,sourcetype,expected", [
86+
("test_metrics", "sourcetype-anno", 1)
87+
])
88+
def test_metric_sourcetype_from_annotations(setup, index, sourcetype, expected):
89+
90+
'''
91+
Test that metrics are being assigned the "sourcetype-anno" sourcetype, as defined by splunk.com/sourcetype annotation added during setup
92+
'''
93+
logger.info("testing for metrics index={0} sourcetype={1} expected={2} event(s)".format(index, sourcetype, expected))
94+
search_query = "index={0} filter=\"sourcetype={1}\"".format(index, sourcetype)
95+
96+
events = check_events_from_splunk(start_time="-1h@h",
97+
url=setup["splunkd_url"],
98+
user=setup["splunk_user"],
99+
query=["mpreview {0}".format(
100+
search_query)],
101+
password=setup["splunk_password"])
102+
logger.info("Splunk received %s events in the last minute",
103+
len(events))
104+
assert len(events) >= expected

test/test_setup.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ metadata:
2626
name: default
2727
annotations:
2828
splunk.com/metricsIndex: test_metrics
29+
splunk.com/sourcetype: sourcetype-anno
2930
---
3031
apiVersion: batch/v1
3132
kind: Job

0 commit comments

Comments
 (0)