Merge "Fluentd: Allow for Multiple Config Files"

This commit is contained in:
Zuul 2020-08-05 14:48:13 +00:00 committed by Gerrit Code Review
commit 8cd4e26a42
5 changed files with 201 additions and 446 deletions

View File

@ -18,7 +18,7 @@ set -ex
COMMAND="${@:-start}" COMMAND="${@:-start}"
function start () { function start () {
exec fluentd -c /fluentd/etc/fluent.conf exec fluentd -c /fluentd/etc/main.conf
} }
function stop () { function stop () {

View File

@ -12,8 +12,15 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/}} */}}
{{- define "fluentd_main" }}
{{- $path := .Values.conf.fluentd.path}}
{{- range $name, $conf := .Values.conf.fluentd.conf }}
{{ printf "%s %s/%s.conf" "@include" $path $name | indent 4}}
{{- end }}
{{- end }}
{{- if .Values.manifests.configmap_etc }} {{- if .Values.manifests.configmap_etc }}
{{- $envAll := . }} {{ $envAll := .}}
--- ---
apiVersion: v1 apiVersion: v1
kind: Secret kind: Secret
@ -22,6 +29,12 @@ metadata:
annotations: annotations:
{{ tuple $envAll | include "helm-toolkit.snippets.release_uuid" }} {{ tuple $envAll | include "helm-toolkit.snippets.release_uuid" }}
type: Opaque type: Opaque
stringData:
main.conf: |
{{- template "fluentd_main" . }}
data: data:
{{- include "helm-toolkit.snippets.values_template_renderer" (dict "envAll" $envAll "template" .Values.conf.fluentd.template "key" "fluent.conf" "format" "Secret") | indent 2 }} {{- range $name, $config := .Values.conf.fluentd.conf }}
{{- $filename := printf "%s.conf" $name}}
{{- include "helm-toolkit.snippets.values_template_renderer" (dict "envAll" $envAll "template" $config "key" $filename "format" "Secret") | indent 2 }}
{{- end }}
{{- end }} {{- end }}

View File

@ -15,6 +15,7 @@ limitations under the License.
{{- if .Values.manifests.daemonset }} {{- if .Values.manifests.daemonset }}
{{- $envAll := . }} {{- $envAll := . }}
{{- $config_path := .Values.conf.fluentd.path }}
{{- $mounts_fluentd := .Values.pod.mounts.fluentd.fluentd }} {{- $mounts_fluentd := .Values.pod.mounts.fluentd.fluentd }}
{{- $prometheus_annotations := $envAll.Values.monitoring.prometheus.fluentd }} {{- $prometheus_annotations := $envAll.Values.monitoring.prometheus.fluentd }}
@ -183,9 +184,15 @@ spec:
- name: pod-etc-fluentd - name: pod-etc-fluentd
mountPath: /fluentd/etc mountPath: /fluentd/etc
- name: fluentd-etc - name: fluentd-etc
mountPath: /fluentd/etc/fluent.conf mountPath: {{ printf "%s/%s.conf" $config_path "main" }}
subPath: fluent.conf subPath: {{ printf "%s.conf" "main"}}
readOnly: true readOnly: true
{{- range $name, $config := .Values.conf.fluentd.conf }}
- name: fluentd-etc
mountPath: {{ printf "%s/%s.conf" $config_path $name }}
subPath: {{ printf "%s.conf" $name }}
readOnly: true
{{- end }}
- name: fluentd-bin - name: fluentd-bin
mountPath: /tmp/fluentd.sh mountPath: /tmp/fluentd.sh
subPath: fluentd.sh subPath: fluentd.sh

View File

@ -54,227 +54,36 @@ dependencies:
conf: conf:
fluentd: fluentd:
# This field is now rendered as a helm template! path: /fluentd/etc
template: | conf:
<source> input: |
@type prometheus
port {{ tuple "fluentd" "internal" "metrics" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }}
</source>
<source>
@type prometheus_monitor
</source>
<source>
@type prometheus_output_monitor
</source>
<source>
@type prometheus_tail_monitor
</source>
<source> <source>
bind 0.0.0.0 bind 0.0.0.0
port "#{ENV['FLUENTD_PORT']}" port "#{ENV['FLUENTD_PORT']}"
@type forward @type forward
</source> </source>
<source>
<match fluent.**> <parse>
@type null time_format %Y-%m-%dT%H:%M:%S.%NZ
@type json
</parse>
path /var/log/containers/*.log
read_from_head true
tag kubernetes.*
@type tail
</source>
<match **>
@type relabel
@label @output
</match> </match>
output: |
<match kube.var.log.containers.**.log> <label @output>
<rule>
key log
pattern /info/i
tag info.${tag}
</rule>
<rule>
key log
pattern /warn/i
tag warn.${tag}
</rule>
<rule>
key log
pattern /error/i
tag error.${tag}
</rule>
<rule>
key log
pattern /critical/i
tag critical.${tag}
</rule>
<rule>
key log
pattern (.+)
tag info.${tag}
</rule>
@type rewrite_tag_filter
</match>
<filter **.kube.var.log.containers.**.log>
enable_ruby true
<record>
application ${record["kubernetes"]["labels"]["application"]}
level ${tag_parts[0]}
</record>
@type record_transformer
</filter>
<filter openstack.**>
<record>
application ${tag_parts[1]}
</record>
@type record_transformer
</filter>
<match openstack.**>
<rule>
key level
pattern INFO
tag info.${tag}
</rule>
<rule>
key level
pattern WARN
tag warn.${tag}
</rule>
<rule>
key level
pattern ERROR
tag error.${tag}
</rule>
<rule>
key level
pattern CRITICAL
tag critical.${tag}
</rule>
@type rewrite_tag_filter
</match>
<match *.openstack.**>
<rule>
key application
pattern keystone
tag auth.${tag}
</rule>
<rule>
key application
pattern horizon
tag auth.${tag}
</rule>
<rule>
key application
pattern mariadb
tag auth.${tag}
</rule>
<rule>
key application
pattern memcached
tag auth.${tag}
</rule>
<rule>
key application
pattern rabbitmq
tag auth.${tag}
</rule>
@type rewrite_tag_filter
</match>
<match libvirt>
<buffer>
chunk_limit_size 8MB
flush_interval 15s
flush_thread_count 8
queue_limit_length 256
retry_forever false
retry_max_interval 30
</buffer>
host "#{ENV['ELASTICSEARCH_HOST']}"
reload_connections false
reconnect_on_error true
reload_on_failure true
include_tag_key true
logstash_format true
logstash_prefix libvirt
password "#{ENV['ELASTICSEARCH_PASSWORD']}"
port "#{ENV['ELASTICSEARCH_PORT']}"
@type elasticsearch
user "#{ENV['ELASTICSEARCH_USERNAME']}"
</match>
<match qemu>
<buffer>
chunk_limit_size 8MB
flush_interval 15s
flush_thread_count 8
queue_limit_length 256
retry_forever false
retry_max_interval 30
</buffer>
host "#{ENV['ELASTICSEARCH_HOST']}"
reload_connections false
reconnect_on_error true
reload_on_failure true
include_tag_key true
logstash_format true
logstash_prefix qemu
password "#{ENV['ELASTICSEARCH_PASSWORD']}"
port "#{ENV['ELASTICSEARCH_PORT']}"
@type elasticsearch
user "#{ENV['ELASTICSEARCH_USERNAME']}"
</match>
<match journal.**>
<buffer>
chunk_limit_size 8MB
flush_interval 15s
flush_thread_count 8
queue_limit_length 256
retry_forever false
retry_max_interval 30
</buffer>
host "#{ENV['ELASTICSEARCH_HOST']}"
reload_connections false
reconnect_on_error true
reload_on_failure true
include_tag_key true
logstash_format true
logstash_prefix journal
password "#{ENV['ELASTICSEARCH_PASSWORD']}"
port "#{ENV['ELASTICSEARCH_PORT']}"
@type elasticsearch
user "#{ENV['ELASTICSEARCH_USERNAME']}"
</match>
<match kernel>
<buffer>
chunk_limit_size 8MB
flush_interval 15s
flush_thread_count 8
queue_limit_length 256
retry_forever false
retry_max_interval 30
</buffer>
host "#{ENV['ELASTICSEARCH_HOST']}"
reload_connections false
reconnect_on_error true
reload_on_failure true
include_tag_key true
logstash_format true
logstash_prefix kernel
password "#{ENV['ELASTICSEARCH_PASSWORD']}"
port "#{ENV['ELASTICSEARCH_PORT']}"
@type elasticsearch
user "#{ENV['ELASTICSEARCH_USERNAME']}"
</match>
<match **> <match **>
<buffer> <buffer>
chunk_limit_size 8MB chunk_limit_size 512K
flush_interval 15s flush_interval 5s
flush_thread_count 8 flush_thread_count 8
queue_limit_length 256 queue_limit_length 32
retry_forever false retry_forever false
retry_max_interval 30 retry_max_interval 30
</buffer> </buffer>
@ -287,10 +96,9 @@ conf:
password "#{ENV['ELASTICSEARCH_PASSWORD']}" password "#{ENV['ELASTICSEARCH_PASSWORD']}"
port "#{ENV['ELASTICSEARCH_PORT']}" port "#{ENV['ELASTICSEARCH_PORT']}"
@type elasticsearch @type elasticsearch
type_name fluent
user "#{ENV['ELASTICSEARCH_USERNAME']}" user "#{ENV['ELASTICSEARCH_USERNAME']}"
</match> </match>
</label>
endpoints: endpoints:
cluster_domain_suffix: cluster.local cluster_domain_suffix: cluster.local
local_image_registry: local_image_registry:

View File

@ -28,8 +28,9 @@ pod:
MY_TEST_SECRET: BAR MY_TEST_SECRET: BAR
conf: conf:
fluentd: fluentd:
# This field is now rendered as a helm template! conf:
template: | # These fields are rendered as helm templates
input: |
<source> <source>
@type prometheus @type prometheus
port {{ tuple "fluentd" "internal" "metrics" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }} port {{ tuple "fluentd" "internal" "metrics" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }}
@ -126,6 +127,13 @@ conf:
</entry> </entry>
</source> </source>
<match **>
@type relabel
@label @filter
</match>
filter: |
<label @filter>
<filter kubernetes.**> <filter kubernetes.**>
@type kubernetes_metadata @type kubernetes_metadata
</filter> </filter>
@ -137,99 +145,17 @@ conf:
fluentd_pod "#{ENV['POD_NAME']}" fluentd_pod "#{ENV['POD_NAME']}"
</record> </record>
</filter> </filter>
<match **>
@type relabel
@label @output
</match>
</label>
output: |
<label @output>
<match fluent.**> <match fluent.**>
@type null @type null
</match> </match>
<match libvirt.**>
<buffer>
chunk_limit_size 512K
flush_interval 5s
flush_thread_count 8
queue_limit_length 32
retry_forever false
retry_max_interval 30
</buffer>
host "#{ENV['ELASTICSEARCH_HOST']}"
reload_connections false
reconnect_on_error true
reload_on_failure true
include_tag_key true
logstash_format true
logstash_prefix libvirt
password "#{ENV['ELASTICSEARCH_PASSWORD']}"
port "#{ENV['ELASTICSEARCH_PORT']}"
@type elasticsearch
user "#{ENV['ELASTICSEARCH_USERNAME']}"
</match>
<match kernel>
<buffer>
chunk_limit_size 512K
flush_interval 5s
flush_thread_count 8
queue_limit_length 32
retry_forever false
disable_chunk_backup true
</buffer>
host "#{ENV['ELASTICSEARCH_HOST']}"
reload_connections false
reconnect_on_error true
reload_on_failure true
include_tag_key true
logstash_format true
logstash_prefix kernel
password "#{ENV['ELASTICSEARCH_PASSWORD']}"
port "#{ENV['ELASTICSEARCH_PORT']}"
@type elasticsearch
user "#{ENV['ELASTICSEARCH_USERNAME']}"
</match>
<match auth>
<buffer>
chunk_limit_size 512K
flush_interval 5s
flush_thread_count 8
queue_limit_length 32
retry_forever false
retry_max_interval 30
</buffer>
host "#{ENV['ELASTICSEARCH_HOST']}"
reload_connections false
reconnect_on_error true
reload_on_failure true
include_tag_key true
logstash_format true
logstash_prefix auth
password "#{ENV['ELASTICSEARCH_PASSWORD']}"
port "#{ENV['ELASTICSEARCH_PORT']}"
@type elasticsearch
user "#{ENV['ELASTICSEARCH_USERNAME']}"
</match>
<match journal.**>
<buffer>
chunk_limit_size 512K
flush_interval 5s
flush_thread_count 8
queue_limit_length 32
retry_forever false
retry_max_interval 30
</buffer>
host "#{ENV['ELASTICSEARCH_HOST']}"
reload_connections false
reconnect_on_error true
reload_on_failure true
include_tag_key true
logstash_format true
logstash_prefix journal
password "#{ENV['ELASTICSEARCH_PASSWORD']}"
port "#{ENV['ELASTICSEARCH_PORT']}"
@type elasticsearch
user "#{ENV['ELASTICSEARCH_USERNAME']}"
</match>
<match **> <match **>
<buffer> <buffer>
chunk_limit_size 512K chunk_limit_size 512K
@ -250,6 +176,7 @@ conf:
@type elasticsearch @type elasticsearch
user "#{ENV['ELASTICSEARCH_USERNAME']}" user "#{ENV['ELASTICSEARCH_USERNAME']}"
</match> </match>
</label>
EOF EOF
helm upgrade --install fluentd ./fluentd \ helm upgrade --install fluentd ./fluentd \
--namespace=osh-infra \ --namespace=osh-infra \