Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add include logs functionality #260

Merged
merged 3 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions helm-charts/splunk-otel-collector/templates/config/_common.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ zipkin:
{{- end }}
{{- end }}

{{/*
Filter Attributes Function
*/}}
{{- define "splunk-otel-collector.filterAttr" -}}
{{- if .Values.logsCollection.containers.useSplunkIncludeAnnotation -}}
splunk.com/include
{{- else -}}
splunk.com/exclude
{{- end }}
{{- end }}

{{/*
Common config for resourcedetection processor
*/}}
Expand Down Expand Up @@ -94,7 +105,7 @@ resource/logs:
action: upsert
- key: k8s.pod.annotations.splunk.com/sourcetype
action: delete
- key: splunk.com/exclude
- key: {{ include "splunk-otel-collector.filterAttr" . }}
action: delete
{{- if .Values.autodetect.istio }}
- key: service.name
Expand Down Expand Up @@ -158,9 +169,9 @@ Filter logs processor
# Drop logs coming from pods and namespaces with splunk.com/exclude annotation.
filter/logs:
logs:
exclude:
{{ .Values.logsCollection.containers.useSplunkIncludeAnnotation | ternary "include" "exclude" }}:
resource_attributes:
- key: splunk.com/exclude
- key: {{ include "splunk-otel-collector.filterAttr" . }}
value: "true"
{{- end }}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,11 @@ processors:
annotations:
- key: splunk.com/sourcetype
from: pod
- key: splunk.com/exclude
tag_name: splunk.com/exclude
- key: {{ include "splunk-otel-collector.filterAttr" . }}
tag_name: {{ include "splunk-otel-collector.filterAttr" . }}
from: namespace
- key: splunk.com/exclude
tag_name: splunk.com/exclude
- key: {{ include "splunk-otel-collector.filterAttr" . }}
tag_name: {{ include "splunk-otel-collector.filterAttr" . }}
from: pod
- key: splunk.com/index
tag_name: com.splunk.index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ processors:
annotations:
- key: splunk.com/sourcetype
from: pod
- key: splunk.com/exclude
tag_name: splunk.com/exclude
- key: {{ include "splunk-otel-collector.filterAttr" . }}
tag_name: {{ include "splunk-otel-collector.filterAttr" . }}
from: namespace
- key: splunk.com/exclude
tag_name: splunk.com/exclude
- key: {{ include "splunk-otel-collector.filterAttr" . }}
tag_name: {{ include "splunk-otel-collector.filterAttr" . }}
from: pod
- key: splunk.com/index
tag_name: com.splunk.index
Expand Down
3 changes: 3 additions & 0 deletions helm-charts/splunk-otel-collector/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,9 @@
"type": "string"
}
},
"useSplunkIncludeAnnotation": {
"type": "boolean"
},
"multilineConfigs": {
"type": "array",
"items": {
Expand Down
5 changes: 4 additions & 1 deletion helm-charts/splunk-otel-collector/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ logsCollection:
# By the time of reconstructing a multiline log the following information is available to
# identify source of the logs: namespace, pod and container names. At least one source
# identifier has to be specified in for each multiline config.
multilineConfigs: []
# The following example shows how to setup multiline log processing for logs having subsequent
# log lines written with an offset. Let's say a k8s deployment called "buttercup-app" is
# scheduled to run in "default" namespace with a java container called "server", and the
Expand All @@ -371,6 +370,10 @@ logsCollection:
# containerName:
# value: server
# firstEntryRegex: ^[^\s].*
multilineConfigs: []
# Set useSplunkIncludeAnnotation flag to `true` to collect logs from pods with `splunk.com/include: true` annotation and ignore others.
# All other logs will be ignored.
useSplunkIncludeAnnotation: false

checkpointPath: "/var/addon/splunk/otel_pos"

Expand Down