Skip to content

Commit 965d21e

Browse files
author
Gimi Liang
committed
Fxied source and sourcetype, and updated to the latest images.
1 parent d4d4079 commit 965d21e

File tree

29 files changed

+558
-309
lines changed

29 files changed

+558
-309
lines changed

helm-chart/LICENSE.md

Lines changed: 53 additions & 0 deletions
Large diffs are not rendered by default.

helm-chart/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,7 @@ See also:
3939
* [charts/splunk-kubernetes-logging/values.yaml](charts/splunk-kubernetes-logging/values.yaml) for configurable parameters for `splunk-kubernetes-logging`.
4040
* [charts/splunk-kubernetes-objects/values.yaml](charts/splunk-kubernetes-objects/values.yaml) for configurable parameters for `splunk-kubernetes-objects`.
4141
* [charts/splunk-kubernetes-metrics/values.yaml](charts/splunk-kubernetes-metrics/values.yaml) for configurable parameters for `splunk-kubernetes-metrics`.
42+
43+
## License ##
44+
45+
[SPLUNK PRE-RELEASE SOFTWARE LICENSE AGREEMENT](https://www.splunk.com/en_us/legal/splunk-pre-release-software-license-agreement.html)

helm-chart/charts/splunk-kubernetes-logging/LICENSE.md

Lines changed: 53 additions & 0 deletions
Large diffs are not rendered by default.

helm-chart/charts/splunk-kubernetes-logging/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,7 @@ Component | Description | Template
4343
`Daemonset` | deploys one pod that runs fluentd on each node to collect logs. | [daemonset.yaml](templates/daemonset.yaml)
4444
`ConfigMap` | contains configuration files for fluentd. | [configmap.yaml](templates/configmap.yaml)
4545
`Secret` | stores credentials like the Splunk HEC token, and SSL certs and keys for HTTPS connection, etc. | [secret.yaml](templates/secret.yaml)
46+
47+
## License ##
48+
49+
[SPLUNK PRE-RELEASE SOFTWARE LICENSE AGREEMENT](https://www.splunk.com/en_us/legal/splunk-pre-release-software-license-agreement.html)

helm-chart/charts/splunk-kubernetes-logging/examples/full.yaml

Lines changed: 0 additions & 16 deletions
This file was deleted.

helm-chart/charts/splunk-kubernetes-logging/templates/_helpers.tpl

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,35 @@ multiline_flush_interval 5s
7979
{{/*
8080
This is a fluentd configuration block that shared by all journald sources.
8181
*/}}
82-
{{- define "splunk-kubernetes-logging.common-journald-source-conf" -}}
83-
@type systemd
84-
path {{ .Values.journalLogPath | default "/run/log/journal" | quote }}
85-
read_from_head true
86-
<storage>
87-
@type local
88-
persistent true
89-
</storage>
90-
<entry>
91-
field_map {"MESSAGE": "log", "_SYSTEMD_UNIT": "source"}
92-
field_map_strict true
93-
</entry>
82+
{{- define "splunk-kubernetes-logging.journald-source" -}}
83+
<source>
84+
@id journald-{{ .name }}
85+
@type systemd
86+
tag journal.kube.{{ .name }}
87+
path {{ .journalLogPath | quote }}
88+
filters [{ "_SYSTEMD_UNIT": {{ .unit | quote }} }]
89+
read_from_head true
90+
<storage>
91+
@type local
92+
persistent true
93+
</storage>
94+
<entry>
95+
field_map {"MESSAGE": "log", "_SYSTEMD_UNIT": "source"}
96+
field_map_strict true
97+
</entry>
98+
</source>
99+
{{- end -}}
100+
101+
{{/*
102+
The jq filter used to generate source and sourcetype for container logs.
103+
Define it as a template here so there we don't need to escape the double quotes `` " ''.
104+
*/}}
105+
{{- define "splunk-kubernetes-logging.container_jq_filter" -}}
106+
def extract_container_name:
107+
split("_") | .[-1] | split("-") | .[:-1] | join("-");
108+
109+
def container_sourcetype:
110+
. as $n | if ({{ toJson (keys .Values.logSources) }} | any(.==$n)) then "kube:" else "kube:container:" end + $n;
111+
112+
.record.sourcetype = (if (.tag | startswith("tail.containers.")) then (.record.source | extract_container_name | container_sourcetype) else (.tag | ltrimstr("tail.") | gsub("\\."; ":")) end) | .record
94113
{{- end -}}

helm-chart/charts/splunk-kubernetes-logging/templates/configMap.yaml

Lines changed: 55 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ data:
2020
system.conf: |-
2121
# system wide configurations
2222
<system>
23-
log_level {{ or .Values.logLevel .Values.global.logLevel | default "info" }}
23+
log_level {{ or .Values.logLevel .Values.global.logLevel }}
2424
root_dir /tmp/fluentd
2525
</system>
2626
@@ -46,7 +46,7 @@ data:
4646
tag raw.tail.containers.*
4747
path /var/log/containers/*.log
4848
pos_file /var/log/splunk-fluentd-containers.log.pos
49-
path_key _file_path
49+
path_key source
5050
read_from_head true
5151
<parse>
5252
@type json
@@ -78,10 +78,10 @@ data:
7878
<source>
7979
@id minion
8080
@type tail
81-
tag tail.salt
81+
tag tail.kube.salt
8282
path /var/log/salt/minion
8383
pos_file /var/log/splunk-fluentd-salt.pos
84-
path_key _file_path
84+
path_key source
8585
<parse>
8686
@type regexp
8787
expression /^(?<time>[^ ]* [^ ,]*)(?<message>.*)$/
@@ -96,25 +96,26 @@ data:
9696
<source>
9797
@id startupscript.log
9898
@type tail
99-
tag tail.startupscript
99+
tag tail.kube.startupscript
100100
path /var/log/startupscript.log
101101
pos_file /var/log/splunk-fluentd-startupscript.log.pos
102-
path_key _file_path
102+
path_key source
103103
<parse>
104104
@type syslog
105105
</parse>
106106
</source>
107107
108+
{{- if .Values.logSources.docker.file }}
108109
# Examples:
109110
# time="2016-02-04T06:51:03.053580605Z" level=info msg="GET /containers/json"
110111
# time="2016-02-04T07:53:57.505612354Z" level=error msg="HTTP Error" err="No such image: -f" statusCode=404
111112
<source>
112113
@id docker.log
113114
@type tail
114-
tag tail.docker
115-
path /var/log/docker.log
115+
tag tail.kube.docker
116+
path {{ .Values.logSources.docker.file.path }}
116117
pos_file /var/log/splunk-fluentd-docker.log.pos
117-
path_key _file_path
118+
path_key source
118119
<parse>
119120
@type regexp
120121
expression /^time="(?<time>[^)]*)" (?<message>.*)$/
@@ -123,145 +124,60 @@ data:
123124
time_format %Y-%m-%dT%H:%M:%S.%NZ
124125
</parse>
125126
</source>
127+
{{- end }}
126128
129+
{{- range $name := tuple "etcd-server" "etcd-server-events" }}
130+
{{- with index $.Values.logSources $name }}
131+
{{- if .file }}
127132
# Example:
128-
# 2016/02/04 06:52:38 filePurge: successfully removed file /var/etcd/data/member/wal/00000000000006d0-00000000010a23d1.wal
133+
# 2018-04-13 05:04:38.537777 I | etcdmain: listening for peers on http://0.0.0.0:2381
129134
<source>
130135
@id etcd.log
131136
@type tail
132-
tag tail.etcd
133-
path /var/log/etcd.log
137+
tag tail.kube.{{ $name }}
138+
path {{ .file.path }}
134139
pos_file /var/log/splunk-fluentd-etcd.log.pos
135-
path_key _file_path
140+
path_key source
136141
<parse>
137-
# Not parsing this, because it doesn't have anything particularly useful to
138-
# parse out of it (like severities).
139-
@type none
142+
@type regexp
143+
expression ^(?<time>\d{4}-d{2}-d{2} \d{2}:\d{2}:\d{2}\.\d{6}) (?<message>.*)$
144+
time_key time
145+
time_type string
146+
time_format %Y-%m-%d %H:%M:%S.%6N
140147
</parse>
141148
</source>
149+
{{- end }}
150+
{{- end }}
151+
{{- end }}
142152
143153
# Multi-line parsing is required for all the kube logs because very large log
144154
# statements, such as those that include entire object bodies, get split into
145155
# multiple lines by glog.
146156
147-
# Example:
148-
# I0204 07:32:30.020537 3368 server.go:1048] POST /stats/container/: (13.972191ms) 200 [[Go-http-client/1.1] 10.244.1.3:40537]
149-
<source>
150-
@id kubelet.log
151-
@type tail
152-
tag tail.kubelet
153-
path /var/log/kubelet.log
154-
pos_file /var/log/splunk-fluentd-kubelet.log.pos
155-
path_key _file_path
156-
{{ include "splunk-kubernetes-logging.tail-glog-multiline" . | indent 6 }}
157-
</source>
158-
159-
# Example:
160-
# I1118 21:26:53.975789 6 proxier.go:1096] Port "nodePort for kube-system/default-http-backend:http" (:31429/tcp) was open before and is still needed
161-
<source>
162-
@id kube-proxy.log
163-
@type tail
164-
tag tail.kube-proxy
165-
path /var/log/kube-proxy.log
166-
pos_file /var/log/splunk-fluentd-kube-proxy.log.pos
167-
path_key _file_path
168-
{{ include "splunk-kubernetes-logging.tail-glog-multiline" . | indent 6 }}
169-
</source>
170-
171-
# Example:
172-
# I0204 07:00:19.604280 5 handlers.go:131] GET /api/v1/nodes: (1.624207ms) 200 [[kube-controller-manager/v1.1.3 (linux/amd64) kubernetes/6a81b50] 127.0.0.1:38266]
173-
<source>
174-
@id kube-apiserver.log
175-
@type tail
176-
tag tail.kube-apiserver
177-
path /var/log/kube-apiserver.log
178-
pos_file /var/log/splunk-fluentd-kube-apiserver.log.pos
179-
path_key _file_path
180-
{{ include "splunk-kubernetes-logging.tail-glog-multiline" . | indent 6 }}
181-
</source>
182-
183-
# Example:
184-
# I0204 06:55:31.872680 5 servicecontroller.go:277] LB already exists and doesn't need update for service kube-system/kube-ui
185-
<source>
186-
@id kube-controller-manager.log
187-
@type tail
188-
tag tail.kube-controller-manager
189-
path /var/log/kube-controller-manager.log
190-
pos_file /var/log/splunk-fluentd-kube-controller-manager.log.pos
191-
path_key _file_path
192-
{{ include "splunk-kubernetes-logging.tail-glog-multiline" . | indent 6 }}
193-
</source>
194-
195-
# Example:
196-
# W0204 06:49:18.239674 7 reflector.go:245] pkg/scheduler/factory/factory.go:193: watch of *api.Service ended with: 401: The event in requested index is outdated and cleared (the requested history has been cleared [2578313/2577886]) [2579312]
197-
<source>
198-
@id kube-scheduler.log
199-
@type tail
200-
tag tail.kube-scheduler
201-
path /var/log/kube-scheduler.log
202-
pos_file /var/log/splunk-fluentd-kube-scheduler.log.pos
203-
path_key _file_path
204-
{{ include "splunk-kubernetes-logging.tail-glog-multiline" . | indent 6 }}
205-
</source>
206-
207-
# Example:
208-
# I1104 10:36:20.242766 5 rescheduler.go:73] Running Rescheduler
209-
<source>
210-
@id rescheduler.log
211-
@type tail
212-
tag tail.rescheduler
213-
path /var/log/rescheduler.log
214-
pos_file /var/log/splunk-fluentd-rescheduler.log.pos
215-
path_key _file_path
216-
{{ include "splunk-kubernetes-logging.tail-glog-multiline" . | indent 6 }}
217-
</source>
218-
219-
# Example:
220-
# I0603 15:31:05.793605 6 cluster_manager.go:230] Reading config from path /etc/gce.conf
157+
{{- range "etcd-server" | without ("etcd-server-events" | without ("docker" | without (keys .Values.logSources))) }}
158+
{{- $source := index $.Values.logSources . }}
159+
{{- if $source.file }}
221160
<source>
222-
@id glbc.log
161+
@id {{ . }}.log
223162
@type tail
224-
tag tail.glbc
225-
path /var/log/glbc.log
226-
pos_file /var/log/splunk-fluentd-glbc.log.pos
227-
path_key _file_path
163+
tag tail.kube.{{ . }}
164+
path {{ $source.file.path }}
165+
pos_file /var/log/splunk-fluentd-{{ . }}.log.pos
166+
path_key source
228167
{{ include "splunk-kubernetes-logging.tail-glog-multiline" . | indent 6 }}
229168
</source>
169+
{{- end }}
170+
{{- end }}
230171

231-
# Example:
232-
# I0603 15:31:05.793605 6 cluster_manager.go:230] Reading config from path /etc/gce.conf
233-
<source>
234-
@id cluster-autoscaler.log
235-
@type tail
236-
tag tail.cluster-autoscaler
237-
path /var/log/cluster-autoscaler.log
238-
pos_file /var/log/splunk-fluentd-cluster-autoscaler.log.pos
239-
path_key _file_path
240-
{{ include "splunk-kubernetes-logging.tail-glog-multiline" . | indent 6 }}
241-
</source>
242172

243173
source.journal.kube.conf: |-
244174
# This fluentd conf file contains configurations for reading logs from systemd journal.
245-
<source>
246-
@id journald-docker
247-
tag journal.docker
248-
filters [{ "_SYSTEMD_UNIT": "docker.service" }]
249-
{{ include "splunk-kubernetes-logging.common-journald-source-conf" . | indent 6 }}
250-
</source>
251-
252-
<source>
253-
@id journald-kubelet
254-
tag journal.kubelet
255-
filters [{ "_SYSTEMD_UNIT": "kubelet.service" }]
256-
{{ include "splunk-kubernetes-logging.common-journald-source-conf" . | indent 6 }}
257-
</source>
175+
{{- range $name, $source := .Values.logSources }}
176+
{{- if $source.journald }}
177+
{{ include "splunk-kubernetes-logging.journald-source" (dict "name" $name "unit" $source.journald.unit "journalLogPath" $.Values.journalLogPath) | indent 4 }}
178+
{{- end }}
179+
{{- end }}
258180

259-
<source>
260-
@id journald-node-problem-detector
261-
tag journal.node-problem-detector
262-
filters [{ "_SYSTEMD_UNIT": "node-problem-detector.service" }]
263-
{{ include "splunk-kubernetes-logging.common-journald-source-conf" . | indent 6 }}
264-
</source>
265181

266182
monit.conf: |-
267183
<source>
@@ -274,17 +190,17 @@ data:
274190
# these filters are for generating the source and sourcetype for each event.
275191
<filter tail.**>
276192
@type jq_transformer
277-
jq '{log: .record.log, source: .record._file_path, sourcetype: (if (.tag | startswith("tail.containers.")) then (.record._file_path | split("_") | .[-1] | split("-") | .[:-1] | join("-")) else (.tag | ltrimstr("tail.")) end)} | .sourcetype = "kube:" + .sourcetype | .'
193+
jq {{ include "splunk-kubernetes-logging.container_jq_filter" . | replace "\n" " " | quote }}
278194
</filter>
279195
280196
<filter journal.**>
281197
@type jq_transformer
282-
jq '.record.source = "{{ .Values.journalLogPath | default "/run/log/journal" }}/" + .record.source | .record'
198+
jq '.record.source = "{{ .Values.journalLogPath }}/" + .record.source | .record.sourcetype = (.tag | ltrimstr("journal.") | gsub("\\\\."; ":")) | .record'
283199
</filter>
284200
285201
<filter monitor_agent>
286202
@type jq_transformer
287-
jq ".record.source = \"namespace:#{ENV['MY_NAMESPACE']}/pod:#{ENV['MY_POD_NAME']}\" | .record.sourcetype = \"fluentd:monitor_agent\" | .record"
203+
jq ".record.source = \"namespace:#{ENV['MY_NAMESPACE']}/pod:#{ENV['MY_POD_NAME']}\" | .record.sourcetype = \"fluentd:monitor-agent\" | .record"
288204
</filter>
289205
290206
@@ -296,27 +212,27 @@ data:
296212
297213
<match **>
298214
@type splunk_hec
299-
protocol {{ or .Values.splunk.hec.protocol .Values.global.splunk.hec.protocol | default "https" }}
215+
protocol {{ or .Values.splunk.hec.protocol .Values.global.splunk.hec.protocol }}
300216
hec_host {{ required "splunk.hec.host is required." (or .Values.splunk.hec.host .Values.global.splunk.hec.host) }}
301-
{{- with $hecPort := or .Values.splunk.hec.port .Values.global.splunk.hec.port }}
302-
{{ if $hecPort }}hec_port {{ $hecPort }}{{ end }}
217+
{{- with or .Values.splunk.hec.port .Values.global.splunk.hec.port }}
218+
hec_port {{ . }}
303219
{{- end }}
304220
hec_token "#{ENV['SPLUNK_HEC_TOKEN']}"
305221
host "#{ENV['SPLUNK_HEC_HOST']}"
306222
source_key source
307223
sourcetype_key sourcetype
308-
{{- if .Values.splunk.hec.indexName }}
309-
index {{ .Values.splunk.hec.indexName }}
224+
{{- with or .Values.splunk.hec.indexName .Values.global.splunk.hec.indexName }}
225+
index {{ . }}
310226
{{- end }}
311227
insecure_ssl {{ or .Values.splunk.hec.insecureSSL .Values.global.splunk.hec.insecureSSL | default false }}
312-
{{- with $clientCert := or .Values.splunk.hec.clientCert .Values.global.splunk.hec.clientCert }}
313-
{{ if $clientCert }}client_cert /fluentd/etc/splunk/hec_client_cert{{ end }}
228+
{{- if or .Values.splunk.hec.clientCert .Values.global.splunk.hec.clientCert }}
229+
client_cert /fluentd/etc/splunk/hec_client_cert
314230
{{- end }}
315-
{{- with $clientKey := or .Values.splunk.hec.clientKey .Values.global.splunk.hec.clientKey }}
316-
{{ if $clientKey }}client_key /fluentd/etc/splunk/hec_client_key{{ end }}
231+
{{- if or .Values.splunk.hec.clientKey .Values.global.splunk.hec.clientKey }}
232+
client_key /fluentd/etc/splunk/hec_client_key
317233
{{- end }}
318-
{{- with $caFile := or .Values.splunk.hec.caFile .Values.global.splunk.hec.caFile }}
319-
{{ if $caFile }}ca_file /fluentd/etc/splunk/hec_ca_file{{ end }}
234+
{{- if or .Values.splunk.hec.caFile .Values.global.splunk.hec.caFile }}
235+
ca_file /fluentd/etc/splunk/hec_ca_file
320236
{{- end }}
321237
<buffer>
322238
@type memory

helm-chart/charts/splunk-kubernetes-logging/templates/daemonset.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ spec:
6363
mountPath: /var/lib/docker/containers
6464
readOnly: true
6565
- name: journallogpath
66-
mountPath: {{ .Values.journalLogPath | default "/run/log/journal" | quote }}
66+
mountPath: {{ .Values.journalLogPath | quote }}
6767
readOnly: true
6868
- name: conf-configmap
6969
mountPath: /fluentd/etc
@@ -80,7 +80,7 @@ spec:
8080
path: /var/lib/docker/containers
8181
- name: journallogpath
8282
hostPath:
83-
path: {{ .Values.journalLogPath | default "/run/log/journal" | quote }}
83+
path: {{ .Values.journalLogPath | quote }}
8484
- name: conf-configmap
8585
configMap:
8686
name: {{ template "splunk-kubernetes-logging.fullname" . }}

0 commit comments

Comments
 (0)