fluentd-gcp-configmap.yaml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. # This ConfigMap is used to ingest logs against new resources like
  2. # "k8s_container" and "k8s_node" when $LOGGING_STACKDRIVER_RESOURCE_TYPES is set
  3. # to "new".
  4. # When $LOGGING_STACKDRIVER_RESOURCE_TYPES is set to "old", the ConfigMap in
  5. # fluentd-gcp-configmap-old.yaml will be used for ingesting logs against old
  6. # resources like "gke_container" and "gce_instance".
  7. kind: ConfigMap
  8. apiVersion: v1
  9. data:
  10. containers.input.conf: |-
  11. # This configuration file for Fluentd is used
  12. # to watch changes to Docker log files that live in the
  13. # directory /var/lib/docker/containers/ and are symbolically
  14. # linked to from the /var/log/containers directory using names that capture the
  15. # pod name and container name. These logs are then submitted to
  16. # Google Cloud Logging which assumes the installation of the cloud-logging plug-in.
  17. #
  18. # Example
  19. # =======
  20. # A line in the Docker log file might look like this JSON:
  21. #
  22. # {"log":"2014/09/25 21:15:03 Got request with path wombat\\n",
  23. # "stream":"stderr",
  24. # "time":"2014-09-25T21:15:03.499185026Z"}
  25. #
  26. # The original tag is derived from the log file's location.
  27. # For example a Docker container's logs might be in the directory:
  28. # /var/lib/docker/containers/997599971ee6366d4a5920d25b79286ad45ff37a74494f262e3bc98d909d0a7b
  29. # and in the file:
  30. # 997599971ee6366d4a5920d25b79286ad45ff37a74494f262e3bc98d909d0a7b-json.log
  31. # where 997599971ee6... is the Docker ID of the running container.
  32. # The Kubernetes kubelet makes a symbolic link to this file on the host
  33. # machine in the /var/log/containers directory which includes the pod name,
  34. # the namespace name and the Kubernetes container name:
  35. # synthetic-logger-0.25lps-pod_default_synth-lgr-997599971ee6366d4a5920d25b79286ad45ff37a74494f262e3bc98d909d0a7b.log
  36. # ->
  37. # /var/lib/docker/containers/997599971ee6366d4a5920d25b79286ad45ff37a74494f262e3bc98d909d0a7b/997599971ee6366d4a5920d25b79286ad45ff37a74494f262e3bc98d909d0a7b-json.log
  38. # The /var/log directory on the host is mapped to the /var/log directory in the container
  39. # running this instance of Fluentd and we end up collecting the file:
  40. # /var/log/containers/synthetic-logger-0.25lps-pod_default_synth-lgr-997599971ee6366d4a5920d25b79286ad45ff37a74494f262e3bc98d909d0a7b.log
  41. # This results in the tag:
  42. # var.log.containers.synthetic-logger-0.25lps-pod_default_synth-lgr-997599971ee6366d4a5920d25b79286ad45ff37a74494f262e3bc98d909d0a7b.log
  43. # where 'synthetic-logger-0.25lps-pod' is the pod name, 'default' is the
  44. # namespace name, 'synth-lgr' is the container name and '997599971ee6..' is
  45. # the container ID.
  46. # The record reformer is used to extract pod_name, namespace_name and
  47. # container_name from the tag and set them in a local_resource_id in the
  48. # format of:
  49. # 'k8s_container.<NAMESPACE_NAME>.<POD_NAME>.<CONTAINER_NAME>'.
  50. # The reformer also changes the tags to 'stderr' or 'stdout' based on the
  51. # value of 'stream'.
  52. # local_resource_id is later used by google_cloud plugin to determine the
  53. # monitored resource to ingest logs against.
  54. # Json Log Example:
  55. # {"log":"[info:2016-02-16T16:04:05.930-08:00] Some log text here\n","stream":"stdout","time":"2016-02-17T00:04:05.931087621Z"}
  56. # CRI Log Example:
  57. # 2016-02-17T00:04:05.931087621Z stdout F [info:2016-02-16T16:04:05.930-08:00] Some log text here
  58. <source>
  59. @type tail
  60. path /var/log/containers/*.log
  61. pos_file /var/log/gcp-containers.log.pos
  62. # Tags at this point are in the format of:
  63. # reform.var.log.containers.<POD_NAME>_<NAMESPACE_NAME>_<CONTAINER_NAME>-<CONTAINER_ID>.log
  64. tag reform.*
  65. read_from_head true
  66. <parse>
  67. @type multi_format
  68. <pattern>
  69. format json
  70. time_key time
  71. time_format %Y-%m-%dT%H:%M:%S.%NZ
  72. </pattern>
  73. <pattern>
  74. format /^(?<time>.+) (?<stream>stdout|stderr) [^ ]* (?<log>.*)$/
  75. time_format %Y-%m-%dT%H:%M:%S.%N%:z
  76. </pattern>
  77. </parse>
  78. </source>
  79. <filter reform.**>
  80. @type parser
  81. format /^(?<severity>\w)(?<time>\d{4} [^\s]*)\s+(?<pid>\d+)\s+(?<source>[^ \]]+)\] (?<log>.*)/
  82. reserve_data true
  83. suppress_parse_error_log true
  84. emit_invalid_record_to_error false
  85. key_name log
  86. </filter>
  87. <match reform.**>
  88. @type record_reformer
  89. enable_ruby true
  90. <record>
  91. # Extract local_resource_id from tag for 'k8s_container' monitored
  92. # resource. The format is:
  93. # 'k8s_container.<namespace_name>.<pod_name>.<container_name>'.
  94. "logging.googleapis.com/local_resource_id" ${"k8s_container.#{tag_suffix[4].rpartition('.')[0].split('_')[1]}.#{tag_suffix[4].rpartition('.')[0].split('_')[0]}.#{tag_suffix[4].rpartition('.')[0].split('_')[2].rpartition('-')[0]}"}
  95. # Rename the field 'log' to a more generic field 'message'. This way the
  96. # fluent-plugin-google-cloud knows to flatten the field as textPayload
  97. # instead of jsonPayload after extracting 'time', 'severity' and
  98. # 'stream' from the record.
  99. message ${record['log']}
  100. # If 'severity' is not set, assume stderr is ERROR and stdout is INFO.
  101. severity ${record['severity'] || if record['stream'] == 'stderr' then 'ERROR' else 'INFO' end}
  102. </record>
  103. tag ${if record['stream'] == 'stderr' then 'raw.stderr' else 'raw.stdout' end}
  104. remove_keys stream,log
  105. </match>
  106. # Detect exceptions in the log output and forward them as one log entry.
  107. <match {raw.stderr,raw.stdout}>
  108. @type detect_exceptions
  109. remove_tag_prefix raw
  110. message message
  111. stream "logging.googleapis.com/local_resource_id"
  112. multiline_flush_interval 5
  113. max_bytes 500000
  114. max_lines 1000
  115. </match>
  116. system.input.conf: |-
  117. # Example:
  118. # Dec 21 23:17:22 gke-foo-1-1-4b5cbd14-node-4eoj startupscript: Finished running startup script /var/run/google.startup.script
  119. <source>
  120. @type tail
  121. format syslog
  122. path /var/log/startupscript.log
  123. pos_file /var/log/gcp-startupscript.log.pos
  124. tag startupscript
  125. </source>
  126. # Examples:
  127. # time="2016-02-04T06:51:03.053580605Z" level=info msg="GET /containers/json"
  128. # time="2016-02-04T07:53:57.505612354Z" level=error msg="HTTP Error" err="No such image: -f" statusCode=404
  129. # TODO(random-liu): Remove this after cri container runtime rolls out.
  130. <source>
  131. @type tail
  132. format /^time="(?<time>[^)]*)" level=(?<severity>[^ ]*) msg="(?<message>[^"]*)"( err="(?<error>[^"]*)")?( statusCode=($<status_code>\d+))?/
  133. path /var/log/docker.log
  134. pos_file /var/log/gcp-docker.log.pos
  135. tag docker
  136. </source>
  137. # Example:
  138. # 2016/02/04 06:52:38 filePurge: successfully removed file /var/etcd/data/member/wal/00000000000006d0-00000000010a23d1.wal
  139. <source>
  140. @type tail
  141. # Not parsing this, because it doesn't have anything particularly useful to
  142. # parse out of it (like severities).
  143. format none
  144. path /var/log/etcd.log
  145. pos_file /var/log/gcp-etcd.log.pos
  146. tag etcd
  147. </source>
  148. # Multi-line parsing is required for all the kube logs because very large log
  149. # statements, such as those that include entire object bodies, get split into
  150. # multiple lines by glog.
  151. # Example:
  152. # 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]
  153. <source>
  154. @type tail
  155. format multiline
  156. multiline_flush_interval 5s
  157. format_firstline /^\w\d{4}/
  158. format1 /^(?<severity>\w)(?<time>\d{4} [^\s]*)\s+(?<pid>\d+)\s+(?<source>[^ \]]+)\] (?<message>.*)/
  159. time_format %m%d %H:%M:%S.%N
  160. path /var/log/kubelet.log
  161. pos_file /var/log/gcp-kubelet.log.pos
  162. tag kubelet
  163. </source>
  164. # Example:
  165. # 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
  166. <source>
  167. @type tail
  168. format multiline
  169. multiline_flush_interval 5s
  170. format_firstline /^\w\d{4}/
  171. format1 /^(?<severity>\w)(?<time>\d{4} [^\s]*)\s+(?<pid>\d+)\s+(?<source>[^ \]]+)\] (?<message>.*)/
  172. time_format %m%d %H:%M:%S.%N
  173. path /var/log/kube-proxy.log
  174. pos_file /var/log/gcp-kube-proxy.log.pos
  175. tag kube-proxy
  176. </source>
  177. # Example:
  178. # 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]
  179. <source>
  180. @type tail
  181. format multiline
  182. multiline_flush_interval 5s
  183. format_firstline /^\w\d{4}/
  184. format1 /^(?<severity>\w)(?<time>\d{4} [^\s]*)\s+(?<pid>\d+)\s+(?<source>[^ \]]+)\] (?<message>.*)/
  185. time_format %m%d %H:%M:%S.%N
  186. path /var/log/kube-apiserver.log
  187. pos_file /var/log/gcp-kube-apiserver.log.pos
  188. tag kube-apiserver
  189. </source>
  190. # Example:
  191. # I0204 06:55:31.872680 5 servicecontroller.go:277] LB already exists and doesn't need update for service kube-system/kube-ui
  192. <source>
  193. @type tail
  194. format multiline
  195. multiline_flush_interval 5s
  196. format_firstline /^\w\d{4}/
  197. format1 /^(?<severity>\w)(?<time>\d{4} [^\s]*)\s+(?<pid>\d+)\s+(?<source>[^ \]]+)\] (?<message>.*)/
  198. time_format %m%d %H:%M:%S.%N
  199. path /var/log/kube-controller-manager.log
  200. pos_file /var/log/gcp-kube-controller-manager.log.pos
  201. tag kube-controller-manager
  202. </source>
  203. # Example:
  204. # 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]
  205. <source>
  206. @type tail
  207. format multiline
  208. multiline_flush_interval 5s
  209. format_firstline /^\w\d{4}/
  210. format1 /^(?<severity>\w)(?<time>\d{4} [^\s]*)\s+(?<pid>\d+)\s+(?<source>[^ \]]+)\] (?<message>.*)/
  211. time_format %m%d %H:%M:%S.%N
  212. path /var/log/kube-scheduler.log
  213. pos_file /var/log/gcp-kube-scheduler.log.pos
  214. tag kube-scheduler
  215. </source>
  216. # Example:
  217. # I0603 15:31:05.793605 6 cluster_manager.go:230] Reading config from path /etc/gce.conf
  218. <source>
  219. @type tail
  220. format multiline
  221. multiline_flush_interval 5s
  222. format_firstline /^\w\d{4}/
  223. format1 /^(?<severity>\w)(?<time>\d{4} [^\s]*)\s+(?<pid>\d+)\s+(?<source>[^ \]]+)\] (?<message>.*)/
  224. time_format %m%d %H:%M:%S.%N
  225. path /var/log/glbc.log
  226. pos_file /var/log/gcp-glbc.log.pos
  227. tag glbc
  228. </source>
  229. # Example:
  230. # I0603 15:31:05.793605 6 cluster_manager.go:230] Reading config from path /etc/gce.conf
  231. <source>
  232. @type tail
  233. format multiline
  234. multiline_flush_interval 5s
  235. format_firstline /^\w\d{4}/
  236. format1 /^(?<severity>\w)(?<time>\d{4} [^\s]*)\s+(?<pid>\d+)\s+(?<source>[^ \]]+)\] (?<message>.*)/
  237. time_format %m%d %H:%M:%S.%N
  238. path /var/log/cluster-autoscaler.log
  239. pos_file /var/log/gcp-cluster-autoscaler.log.pos
  240. tag cluster-autoscaler
  241. </source>
  242. # Logs from systemd-journal for interesting services.
  243. # TODO(random-liu): Keep this for compatibility, remove this after
  244. # cri container runtime rolls out.
  245. <source>
  246. @type systemd
  247. filters [{ "_SYSTEMD_UNIT": "docker.service" }]
  248. pos_file /var/log/gcp-journald-docker.pos
  249. read_from_head true
  250. tag docker
  251. </source>
  252. <source>
  253. @type systemd
  254. filters [{ "_SYSTEMD_UNIT": "{{ fluentd_container_runtime_service }}.service" }]
  255. pos_file /var/log/gcp-journald-container-runtime.pos
  256. read_from_head true
  257. tag container-runtime
  258. </source>
  259. <source>
  260. @type systemd
  261. filters [{ "_SYSTEMD_UNIT": "kubelet.service" }]
  262. pos_file /var/log/gcp-journald-kubelet.pos
  263. read_from_head true
  264. tag kubelet
  265. </source>
  266. <source>
  267. @type systemd
  268. filters [{ "_SYSTEMD_UNIT": "node-problem-detector.service" }]
  269. pos_file /var/log/gcp-journald-node-problem-detector.pos
  270. read_from_head true
  271. tag node-problem-detector
  272. </source>
  273. # BEGIN_NODE_JOURNAL
  274. # Whether to include node-journal or not is determined when starting the
  275. # cluster. It is not changed when the cluster is already running.
  276. <source>
  277. @type systemd
  278. pos_file /var/log/gcp-journald.pos
  279. read_from_head true
  280. tag node-journal
  281. </source>
  282. <filter node-journal>
  283. @type grep
  284. <exclude>
  285. key _SYSTEMD_UNIT
  286. pattern ^(docker|{{ fluentd_container_runtime_service }}|kubelet|node-problem-detector)\.service$
  287. </exclude>
  288. </filter>
  289. # END_NODE_JOURNAL
  290. monitoring.conf: |-
  291. # This source is used to acquire approximate process start timestamp,
  292. # which purpose is explained before the corresponding output plugin.
  293. <source>
  294. @type exec
  295. command /bin/sh -c 'date +%s'
  296. tag process_start
  297. time_format %Y-%m-%d %H:%M:%S
  298. keys process_start_timestamp
  299. </source>
  300. # This filter is used to convert process start timestamp to integer
  301. # value for correct ingestion in the prometheus output plugin.
  302. <filter process_start>
  303. @type record_transformer
  304. enable_ruby true
  305. auto_typecast true
  306. <record>
  307. process_start_timestamp ${record["process_start_timestamp"].to_i}
  308. </record>
  309. </filter>
  310. output.conf: |-
  311. # This match is placed before the all-matching output to provide metric
  312. # exporter with a process start timestamp for correct exporting of
  313. # cumulative metrics to Stackdriver.
  314. <match process_start>
  315. @type prometheus
  316. <metric>
  317. type gauge
  318. name process_start_time_seconds
  319. desc Timestamp of the process start in seconds
  320. key process_start_timestamp
  321. </metric>
  322. </match>
  323. # This filter allows to count the number of log entries read by fluentd
  324. # before they are processed by the output plugin. This in turn allows to
  325. # monitor the number of log entries that were read but never sent, e.g.
  326. # because of liveness probe removing buffer.
  327. <filter **>
  328. @type prometheus
  329. <metric>
  330. type counter
  331. name logging_entry_count
  332. desc Total number of log entries generated by either application containers or system components
  333. </metric>
  334. </filter>
  335. # This section is exclusive for k8s_container logs. Those come with
  336. # 'stderr'/'stdout' tags.
  337. # TODO(instrumentation): Reconsider this workaround later.
  338. # Trim the entries which exceed slightly less than 100KB, to avoid
  339. # dropping them. It is a necessity, because Stackdriver only supports
  340. # entries that are up to 100KB in size.
  341. <filter {stderr,stdout}>
  342. @type record_transformer
  343. enable_ruby true
  344. <record>
  345. message ${record['message'].length > 100000 ? "[Trimmed]#{record['message'][0..100000]}..." : record['message']}
  346. </record>
  347. </filter>
  348. # Do not collect fluentd's own logs to avoid infinite loops.
  349. <match fluent.**>
  350. @type null
  351. </match>
  352. # Add a unique insertId to each log entry that doesn't already have it.
  353. # This helps guarantee the order and prevent log duplication.
  354. <filter **>
  355. @type add_insert_ids
  356. </filter>
  357. # This section is exclusive for k8s_container logs. These logs come with
  358. # 'stderr'/'stdout' tags.
  359. # We use a separate output stanza for 'k8s_node' logs with a smaller buffer
  360. # because node logs are less important than user's container logs.
  361. <match {stderr,stdout}>
  362. @type google_cloud
  363. # Try to detect JSON formatted log entries.
  364. detect_json true
  365. # Collect metrics in Prometheus registry about plugin activity.
  366. enable_monitoring true
  367. monitoring_type prometheus
  368. # Allow log entries from multiple containers to be sent in the same request.
  369. split_logs_by_tag false
  370. # Set the buffer type to file to improve the reliability and reduce the memory consumption
  371. buffer_type file
  372. buffer_path /var/log/fluentd-buffers/kubernetes.containers.buffer
  373. # Set queue_full action to block because we want to pause gracefully
  374. # in case of the off-the-limits load instead of throwing an exception
  375. buffer_queue_full_action block
  376. # Set the chunk limit conservatively to avoid exceeding the recommended
  377. # chunk size of 5MB per write request.
  378. buffer_chunk_limit 512k
  379. # Cap the combined memory usage of this buffer and the one below to
  380. # 512KiB/chunk * (6 + 2) chunks = 4 MiB
  381. buffer_queue_limit 6
  382. # Never wait more than 5 seconds before flushing logs in the non-error case.
  383. flush_interval 5s
  384. # Never wait longer than 30 seconds between retries.
  385. max_retry_wait 30
  386. # Disable the limit on the number of retries (retry forever).
  387. disable_retry_limit
  388. # Use multiple threads for processing.
  389. num_threads 2
  390. use_grpc true
  391. # Skip timestamp adjustment as this is in a controlled environment with
  392. # known timestamp format. This helps with CPU usage.
  393. adjust_invalid_timestamps false
  394. </match>
  395. # Attach local_resource_id for 'k8s_node' monitored resource.
  396. <filter **>
  397. @type record_transformer
  398. enable_ruby true
  399. <record>
  400. "logging.googleapis.com/local_resource_id" ${"k8s_node.#{ENV['NODE_NAME']}"}
  401. </record>
  402. </filter>
  403. # This section is exclusive for 'k8s_node' logs. These logs come with tags
  404. # that are neither 'stderr' or 'stdout'.
  405. # We use a separate output stanza for 'k8s_container' logs with a larger
  406. # buffer because user's container logs are more important than node logs.
  407. <match **>
  408. @type google_cloud
  409. detect_json true
  410. enable_monitoring true
  411. monitoring_type prometheus
  412. # Allow entries from multiple system logs to be sent in the same request.
  413. split_logs_by_tag false
  414. detect_subservice false
  415. buffer_type file
  416. buffer_path /var/log/fluentd-buffers/kubernetes.system.buffer
  417. buffer_queue_full_action block
  418. buffer_chunk_limit 512k
  419. buffer_queue_limit 2
  420. flush_interval 5s
  421. max_retry_wait 30
  422. disable_retry_limit
  423. num_threads 2
  424. use_grpc true
  425. # Skip timestamp adjustment as this is in a controlled environment with
  426. # known timestamp format. This helps with CPU usage.
  427. adjust_invalid_timestamps false
  428. </match>
  429. metadata:
  430. name: fluentd-gcp-config-v1.2.5
  431. namespace: kube-system
  432. labels:
  433. addonmanager.kubernetes.io/mode: Reconcile