Skip to content

Commit

Permalink
Implement code review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
mstopa-splunk committed Jan 7, 2025
1 parent 861eeb3 commit 19b586d
Show file tree
Hide file tree
Showing 23 changed files with 87 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .chloggen/fixmetricssourcetypeannotation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ component: other
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fixed updating metrics' sourcetype with annotations
# One or more tracking issues related to the change
issues: []
issues: [1375]
# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
Expand Down
3 changes: 2 additions & 1 deletion docs/advanced-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,8 @@ Manage Splunk OTel Collector Logging with these supported annotations.
* Filter logs using pod and/or namespace annotation
* 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.
* 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.
* Use `splunk.com/sourcetype` annotation on pod to overwrite `sourcetype` field. If not set, it is dynamically generated to be `kube:container:CONTAINER_NAME` for logs and defaults to "httpevent" for metrics.
* 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`.
* For metrics, use the `splunk.com/sourcetype` annotation on the namespace to override the sourcetype field. If not set, it defaults to `httpevent`.

### Performance of native OpenTelemetry logs collection

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ data:
k8sattributes/metrics:
extract:
annotations:
- from: namespace
key: splunk.com/sourcetype
tag_name: com.splunk.sourcetype
- from: pod
key: splunk.com/sourcetype
tag_name: com.splunk.sourcetype
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ data:
k8sattributes/metrics:
extract:
annotations:
- from: namespace
key: splunk.com/sourcetype
tag_name: com.splunk.sourcetype
- from: pod
key: splunk.com/sourcetype
tag_name: com.splunk.sourcetype
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ spec:
component: otel-collector-agent
release: default
annotations:
checksum/config: 8f13ff66652ba33fe2a9aee4c1a2e43517bfe12d57093be5d675ef515f537d78
checksum/config: 8cf566b711b895e8209d8c055fc25b2245e74abe84743cf64655a07cb78fee92
kubectl.kubernetes.io/default-container: otel-collector
spec:
hostNetwork: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ spec:
component: otel-k8s-cluster-receiver
release: default
annotations:
checksum/config: 31057c8fa63ede3a8e48bce75a40865619cdd244a7cc16ade3471013072fb603
checksum/config: 130873286d49dc56b755805d556b3094fcb6696ce4e9326408389c58942d46db
spec:
serviceAccountName: default-splunk-otel-collector
nodeSelector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ data:
k8sattributes/metrics:
extract:
annotations:
- from: namespace
key: splunk.com/sourcetype
tag_name: com.splunk.sourcetype
- from: pod
key: splunk.com/sourcetype
tag_name: com.splunk.sourcetype
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ data:
k8sattributes/metrics:
extract:
annotations:
- from: namespace
key: splunk.com/sourcetype
tag_name: com.splunk.sourcetype
- from: pod
key: splunk.com/sourcetype
tag_name: com.splunk.sourcetype
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ spec:
component: otel-collector-agent
release: default
annotations:
checksum/config: 7e28ba091fe865d050d7328d4484a25a517e3f7937d660ab8aca68b1f7206d21
checksum/config: 07fe1f32f371cae54b4ed702d65fd1a60a134f0c4d8b66dcfec1eb81ed1907bc
kubectl.kubernetes.io/default-container: otel-collector
spec:
hostNetwork: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ spec:
component: otel-k8s-cluster-receiver
release: default
annotations:
checksum/config: 31057c8fa63ede3a8e48bce75a40865619cdd244a7cc16ade3471013072fb603
checksum/config: 130873286d49dc56b755805d556b3094fcb6696ce4e9326408389c58942d46db
spec:
serviceAccountName: default-splunk-otel-collector
nodeSelector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ data:
k8sattributes/metrics:
extract:
annotations:
- from: namespace
key: splunk.com/sourcetype
tag_name: com.splunk.sourcetype
- from: pod
key: splunk.com/sourcetype
tag_name: com.splunk.sourcetype
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ data:
k8sattributes/metrics:
extract:
annotations:
- from: namespace
key: splunk.com/sourcetype
tag_name: com.splunk.sourcetype
- from: pod
key: splunk.com/sourcetype
tag_name: com.splunk.sourcetype
Expand Down
2 changes: 1 addition & 1 deletion examples/multi-metrics/rendered_manifests/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ spec:
component: otel-collector-agent
release: default
annotations:
checksum/config: 5b4ddaf2cc99de360060d11ef3f956eaf152f249d2aeb62cf477602745b4cea1
checksum/config: 03163bd786efbdb0c43d07cb64eb17cf6cd9595af1c5db2ccf2c4c84615a2dfb
kubectl.kubernetes.io/default-container: otel-collector
spec:
hostNetwork: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ spec:
component: otel-k8s-cluster-receiver
release: default
annotations:
checksum/config: 31057c8fa63ede3a8e48bce75a40865619cdd244a7cc16ade3471013072fb603
checksum/config: 130873286d49dc56b755805d556b3094fcb6696ce4e9326408389c58942d46db
spec:
serviceAccountName: default-splunk-otel-collector
nodeSelector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ data:
k8sattributes/metrics:
extract:
annotations:
- from: namespace
key: splunk.com/sourcetype
tag_name: com.splunk.sourcetype
- from: pod
key: splunk.com/sourcetype
tag_name: com.splunk.sourcetype
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ data:
k8sattributes/metrics:
extract:
annotations:
- from: namespace
key: splunk.com/sourcetype
tag_name: com.splunk.sourcetype
- from: pod
key: splunk.com/sourcetype
tag_name: com.splunk.sourcetype
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ spec:
component: otel-collector-agent
release: default
annotations:
checksum/config: 1d48c12fc0681c6793c2c6e581e5199248d33a81165761431e28cc813cecd5c5
checksum/config: c3dbc1971b6dfeee15734ef1758d5b78e03f60fa6ce35f5d58b4df90ea71c24d
kubectl.kubernetes.io/default-container: otel-collector
spec:
hostNetwork: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ spec:
component: otel-k8s-cluster-receiver
release: default
annotations:
checksum/config: 31057c8fa63ede3a8e48bce75a40865619cdd244a7cc16ade3471013072fb603
checksum/config: 130873286d49dc56b755805d556b3094fcb6696ce4e9326408389c58942d46db
spec:
serviceAccountName: default-splunk-otel-collector
nodeSelector:
Expand Down
24 changes: 21 additions & 3 deletions helm-charts/splunk-otel-collector/templates/config/_common.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ k8sattributes/clusterReceiver:
{{- if eq (include "splunk-otel-collector.splunkPlatformEnabled" .) "true"}}
annotations:
- key: splunk.com/sourcetype
tag_name: com.splunk.sourcetype
from: namespace
- key: splunk.com/sourcetype
tag_name: com.splunk.sourcetype
from: pod
- key: splunk.com/index
tag_name: com.splunk.index
Expand Down Expand Up @@ -265,6 +269,9 @@ k8sattributes/metrics:
extract:
metadata: []
annotations:
- key: splunk.com/sourcetype
tag_name: com.splunk.sourcetype
from: namespace
- key: splunk.com/sourcetype
tag_name: com.splunk.sourcetype
from: pod
Expand Down Expand Up @@ -339,6 +346,20 @@ resource/logs:
{{- end }}
{{- end }}

{{/*
Resource processor for metrics manipulations
*/}}
{{- define "splunk-otel-collector.resourceMetricsProcessor" -}}
resource/metrics:
attributes:
{{- if .Values.splunkPlatform.sourcetype }}
# Insert the sourcetype value from values.yaml if it has not already been set through annotations.
- key: com.splunk.sourcetype
value: "{{.Values.splunkPlatform.sourcetype }}"
action: insert
{{- end }}
{{- end }}

{{/*
The transform processor adds service.name attribute to logs the same way as it's done by istio for the generated traces
https://github.com/istio/istio/blob/6237cb4e63cf9a332327cc0a815d6b46257e6f8a/pkg/config/analysis/analyzers/testdata/common/sidecar-injector-configmap.yaml#L110-L115
Expand Down Expand Up @@ -436,9 +457,6 @@ splunk_hec/platform_metrics:
token: "${SPLUNK_PLATFORM_HEC_TOKEN}"
index: {{ .Values.splunkPlatform.metricsIndex | quote }}
source: {{ .Values.splunkPlatform.source | quote }}
{{- if .Values.splunkPlatform.sourcetype }}
sourcetype: {{ .Values.splunkPlatform.sourcetype | quote }}
{{- end }}
max_idle_conns: {{ .Values.splunkPlatform.maxConnections }}
max_idle_conns_per_host: {{ .Values.splunkPlatform.maxConnections }}
disable_compression: {{ .Values.splunkPlatform.disableCompression }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,9 @@ processors:
{{- include "splunk-otel-collector.k8sAttributesSplunkPlatformMetrics" . | nindent 2 }}
filter:
node_from_env_var: K8S_NODE_NAME
{{- if .Values.splunkPlatform.sourcetype }}
{{- include "splunk-otel-collector.resourceMetricsProcessor" . | nindent 2 }}
{{- end }}
{{- end }}
{{- if eq .Values.logsEngine "fluentd" }}
Expand Down Expand Up @@ -1026,6 +1029,9 @@ service:
{{- end }}
{{- if (eq (include "splunk-otel-collector.platformMetricsEnabled" $) "true") }}
- k8sattributes/metrics
{{- if .Values.splunkPlatform.sourcetype }}
- resource/metrics
{{- end }}
{{- end }}
exporters:
{{- if $gatewayEnabled }}
Expand All @@ -1052,6 +1058,9 @@ service:
- resource
{{- if (eq (include "splunk-otel-collector.platformMetricsEnabled" $) "true") }}
- k8sattributes/metrics
{{- if .Values.splunkPlatform.sourcetype }}
- resource/metrics
{{- end }}
{{- end }}
exporters:
{{- if (eq (include "splunk-otel-collector.splunkO11yEnabled" .) "true") }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ processors:
{{- include "splunk-otel-collector.k8sAttributesSplunkPlatformMetrics" . | nindent 2 }}
filter:
node_from_env_var: K8S_NODE_NAME
{{- if .Values.splunkPlatform.sourcetype }}
{{- include "splunk-otel-collector.resourceMetricsProcessor" . | nindent 2 }}
{{- end }}
{{- end }}

{{- include "splunk-otel-collector.resourceLogsProcessor" . | nindent 2 }}
Expand Down Expand Up @@ -207,6 +210,9 @@ service:
{{- end }}
{{- if (eq (include "splunk-otel-collector.platformMetricsEnabled" $) "true") }}
- k8sattributes/metrics
{{- if .Values.splunkPlatform.sourcetype }}
- resource/metrics
{{- end }}
{{- end }}
exporters:
{{- if (eq (include "splunk-otel-collector.o11yMetricsEnabled" .) "true") }}
Expand Down Expand Up @@ -261,6 +267,9 @@ service:
{{- end }}
{{- if (eq (include "splunk-otel-collector.platformMetricsEnabled" $) "true") }}
- k8sattributes/metrics
{{- if .Values.splunkPlatform.sourcetype }}
- resource/metrics
{{- end }}
{{- end }}
exporters:
{{- if (eq (include "splunk-otel-collector.splunkO11yEnabled" .) "true") }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ processors:
{{- include "splunk-otel-collector.k8sAttributesSplunkPlatformMetrics" . | nindent 2 }}
filter:
node_from_env_var: K8S_NODE_NAME
{{- if .Values.splunkPlatform.sourcetype }}
{{- include "splunk-otel-collector.resourceMetricsProcessor" . | nindent 2 }}
{{- end }}
{{- end }}

batch:
Expand Down Expand Up @@ -237,6 +240,9 @@ service:
- resource
{{- if (eq (include "splunk-otel-collector.platformMetricsEnabled" $) "true") }}
- k8sattributes/metrics
{{- if .Values.splunkPlatform.sourcetype }}
- resource/metrics
{{- end }}
{{- end }}
- resource/k8s_cluster
exporters:
Expand All @@ -259,6 +265,9 @@ service:
- resource
{{- if (eq (include "splunk-otel-collector.platformMetricsEnabled" $) "true") }}
- k8sattributes/metrics
{{- if .Values.splunkPlatform.sourcetype }}
- resource/metrics
{{- end }}
{{- end }}
exporters:
{{- if (eq (include "splunk-otel-collector.o11yMetricsEnabled" .) "true") }}
Expand All @@ -280,6 +289,9 @@ service:
- resource
{{- if (eq (include "splunk-otel-collector.platformMetricsEnabled" $) "true") }}
- k8sattributes/metrics
{{- if .Values.splunkPlatform.sourcetype }}
- resource/metrics
{{- end }}
{{- end }}
exporters:
{{- if (eq (include "splunk-otel-collector.o11yMetricsEnabled" .) "true") }}
Expand Down
1 change: 1 addition & 0 deletions test/test_setup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ metadata:
name: default
annotations:
splunk.com/metricsIndex: test_metrics
splunk.com/sourcetype: sourcetype-anno
---
apiVersion: batch/v1
kind: Job
Expand Down

0 comments on commit 19b586d

Please sign in to comment.