Commit e6636f4d authored by Anton Kulikov's avatar Anton Kulikov

Refactoring

parent 1d9073f8
......@@ -3,7 +3,7 @@ name: promtail
description: Responsible for gathering logs and sending them to Loki
version: 1.1.1
appVersion: 2.0.0
kubeVersion: ">= 1.18.0"
kubeVersion: ">= 1.17.7"
keywords:
- grafana
- promtail
......
This diff is collapsed.
{{- define "promtail.auditLogPath" -}}
{{- default "/var/log/audit/audit.log" .Values.auditLog.path -}}
{{- end -}}
{{- define "promtail.auditLogDirectory" -}}
{{- include "promtail.auditLogPath" . | dir -}}
{{- end -}}
{{- define "promtail.scrapeAuditLog" -}}
- job_name: auditLog
{{- with .Values.auditLog.pipelineStages }}
pipeline_stages:
{{- toYaml . | nindent 4 }}
{{- end }}
static_configs:
- labels:
__path__: {{ include "promtail.auditLogPath" . }}
jobName: auditLog
relabel_configs: []
{{- end -}}
{{- define "promtail.auditLogJob" -}}
- job_name: audit-log
{{- with .pipelineStages }}
pipeline_stages:
{{- toYaml . | nindent 4 }}
{{- end }}
static_configs:
- labels:
__path__: {{ default "/var/log/audit" .path | printf "%s/*.log" }}
job: system/audit_log
relabel_configs: []
{{- end -}}
{{/* vim: set filetype=mustache: */}}
{{- define "promtail.clientConfig" -}}
- url: {{ default "http://loki/loki/api/v1/push" .url | toString }}
{{- if .tenantId }}
tenant_id: {{ .tenantId | toString }}
{{- end }}
batchwait: {{ default "1s" .batchwait | toString }}
batchsize: {{ default 102400 .batchsize | int64 | toString }}
{{- if or (and .basicAuth.username .basicAuth.password) .basicAuth.passwordFile }}
basic_auth:
username: {{ .basicAuth.username | toString }}
password: {{ .basicAuth.password | toString }}
password_file: {{ .basicAuth.passwordFile | toString }}
{{- end }}
{{- if .bearerToken }}
bearer_token: {{ .bearerToken | toString }}
{{- end }}
{{- if .bearerTokenFile }}
bearer_token_file: {{ .bearerTokenFile | toString }}
{{- end }}
{{- if .proxyUrl }}
proxy_url: {{ .proxyUrl | toString }}
{{- end }}
tls_config:
ca_file: {{ .tlsConfig.caFile | toString }}
cert_file: {{ .tlsConfig.certFile | toString }}
key_file: {{ .tlsConfig.keyFile | toString }}
server_name: {{ .tlsConfig.serverName | toString }}
insecure_skip_verify: {{ default false .tlsConfig.insecureSkipVerify | toString }}
backoff_config:
min_period: {{ default "500ms" .backoffConfig.minPeriod | toString }}
max_period: {{ default "5m" .backoffConfig.maxPeriod | toString }}
max_retries: {{ default 10 .backoffConfig.maxRetries | int64 | toString }}
timeout: {{ default "10s" .timeout | toString }}
{{- end -}}
{{/* vim: set filetype=mustache: */}}
{{- define "promtail.positionsPath" -}}
{{- default "/run/promtail/positions.yaml" .Values.positionsPath -}}
{{- end -}}
{{- define "promtail.positionsDirectory" -}}
{{- include "promtail.positionsPath" . | dir -}}
{{- end -}}
{{- define "promtail.config" -}}
server:
{{- include "promtail.serverConfig" .Values.server | trim | nindent 2 }}
http_listen_address: 0.0.0.0
http_listen_port: {{ .Values.server.httpPort | int64 | toString }}
grpc_listen_address: 0.0.0.0
grpc_listen_port: {{ .Values.server.grpcPort | int64 | toString }}
graceful_shutdown_timeout: {{ .Values.server.gracefulShutdownTimeout | toString }}
http_server_read_timeout: {{ .Values.server.httpReadTimeout | toString }}
http_server_write_timeout: {{ .Values.server.httpWriteTimeout | toString }}
http_server_idle_timeout: {{ .Values.server.httpIdleTimeout | toString }}
grpc_server_max_recv_msg_size: {{ .Values.server.grpcMaxRecvMsgSize | int64 | toString }}
grpc_server_max_send_msg_size: {{ .Values.server.grpcMaxSendMsgSize | int64 | toString }}
grpc_server_max_concurrent_streams: {{ .Values.server.grpcMaxConcurrentStreams | int64 | toString }}
log_level: {{ .Values.logLevel | toString }}
http_path_prefix: {{ .Values.server.httpPathPrefix | toString }}
health_check_target: {{ .Values.server.healthCheckTarget | toString }}
clients:
{{- include "promtail.clientConfig" .Values.client | trim | nindent 2 }}
- url: {{ .Values.lokiUrl | toString }}
{{- if .Values.tenantId }}
tenant_id: {{ .Values.tenantId | toString }}
{{- end }}
{{- with .Values.client }}
batchwait: {{ .batchwait | toString }}
batchsize: {{ .batchsize | int64 | toString }}
{{- if or .basicAuth.username .basicAuth.password .basicAuth.passwordFile }}
basic_auth:
username: {{ .basicAuth.username | toString }}
password: {{ .basicAuth.password | toString }}
password_file: {{ .basicAuth.passwordFile | toString }}
{{- end }}
{{- if .bearerToken }}
bearer_token: {{ .bearerToken | toString }}
{{- end }}
{{- if .bearerTokenFile }}
bearer_token_file: {{ .bearerTokenFile | toString }}
{{- end }}
{{- if .proxyUrl }}
proxy_url: {{ .proxyUrl | toString }}
{{- end }}
tls_config:
ca_file: {{ .tls.caFile | toString }}
cert_file: {{ .tls.certFile | toString }}
key_file: {{ .tls.keyFile | toString }}
server_name: {{ .tls.serverName | toString }}
insecure_skip_verify: {{ .insecureSkipVerify }}
backoff_config:
min_period: {{ .backoffConfig.minPeriod | toString }}
max_period: {{ .backoffConfig.maxPeriod | toString }}
max_retries: {{ .backoffConfig.maxRetries | int64 | toString }}
timeout: {{ .timeout | toString }}
{{- end }}
{{- with .Values.extraClientConfigs }}
{{- toYaml . | nindent 2 }}
{{- end }}
scrape_configs:
{{- if .Values.scrapeConfigs.containers.enabled }}
{{- with .Values.scrapeConfigs.containers }}
{{- include "promtail.kubernetesPodsNameJob" . | trim | nindent 2 }}
{{- include "promtail.kubernetesPodsK8sAppJob" . | trim | nindent 2 }}
{{- include "promtail.kubernetesPodsAppJob" . | trim | nindent 2 }}
{{- include "promtail.kubernetesPodsDirectControllersJob" . | trim | nindent 2 }}
{{- include "promtail.kubernetesPodsIndirectControllerJob" . | trim | nindent 2 }}
{{- include "promtail.kubernetesPodsStaticJob" . | trim | nindent 2 }}
{{- end }}
{{- if .Values.pods.scrape }}
{{- include "promtail.scrapePods" . | trim | nindent 2 }}
{{- end }}
{{- if .Values.systemJournal.scrape }}
{{- include "promtail.scrapeSystemJournal" . | trim | nindent 2 }}
{{- end }}
{{- if .Values.scrapeConfigs.systemdJournal.enabled }}
{{- include "promtail.systemdJournalJob" .Values.scrapeConfigs.systemdJournal | trim | nindent 2 }}
{{- if .Values.auditLog.scrape }}
{{- include "promtail.scrapeAuditLog" . | trim | nindent 2 }}
{{- end }}
{{- if .Values.scrapeConfigs.auditLog.enabled }}
{{- include "promtail.auditLogJob" .Values.scrapeConfigs.auditLog | trim | nindent 2 }}
{{- if .Values.syslog.listen }}
{{- include "promtail.syslog" . | trim | nindent 2 }}
{{- end }}
{{- if .Values.scrapeConfigs.syslog.enabled }}
{{- include "promtail.syslogJob" .Values.scrapeConfigs.syslog | trim | nindent 2 }}
{{- with .Values.extraScrapeConfigs }}
{{- toYaml . | nindent 2 }}
{{- end }}
positions:
filename: /run/promtail/positions.yaml
filename: {{ include "promtail.positionsPath" . }}
sync_period: 10s
ignore_invalid_yaml: false
target_config:
sync_period: 10s
{{- end -}}
{{- define "promtail.podsDropDebug" -}}
- match:
selector: '{pod=~".+"} |~ `\b(level=debug|debug=true)\b`'
stages:
- drop:
expression: .*
drop_counter_reason: drop_debug
- match:
selector: '{pod=~".+"} |~ `^(DEBUG|level=debug|{"level":"debug)\b`'
stages:
- drop:
expression: .*
drop_counter_reason: drop_debug
- match:
selector: '{level="debug"}'
stages:
- drop:
source: level
expression: debug
- match:
selector: '{debug="true"}'
stages:
- drop:
source: level
expression: debug
- match:
selector: '{pod=~".+"} |~ `^[\.-]+$`'
stages:
- drop:
expression: .*
drop_counter_reason: drop_debug
{{- end -}}
{{- define "promtail.podsDropReadinessProbes" -}}
- match:
selector: '{pod=~".+"} |= "GET /"'
stages:
- drop:
expression: '"kube-probe/1.[0-9]+"'
drop_counter_reason: drop_readiness_probes
- drop:
expression: '^127.0.0.1 .* 200 '
drop_counter_reason: drop_readiness_probes
- drop:
expression: 'GET /(healthz|ping|ready)\b.* 200 '
drop_counter_reason: drop_readiness_probes
{{- end -}}
{{- define "promtail.podsDropDeprecated" -}}
- match:
selector: '{pod=~".+"} |~ `\b[Dd][Ee][Pp][Rr][Ee][Cc][Aa][Tt][Ee][Dd]\b`'
stages:
- drop:
expression: .*
drop_counter_reason: drop_deprecated
{{- end -}}
{{- define "promtail.kubernetesPodsAppJob" -}}
- job_name: kubernetes-pods-app
pipeline_stages:
{{- include "promtail.kubernetesPodsPipelineStages" . | trim | nindent 4 }}
kubernetes_sd_configs:
- role: pod
relabel_configs:
{{- if .excludeNamespaces }}
{{- include "promtail.kubernetesPodsExcludeNamespaces" . | trim | nindent 4 }}
{{- end }}
{{- include "promtail.kubernetesPodsDropAnnotation" . | trim | nindent 4 }}
- action: drop
regex: .+
source_labels:
- __meta_kubernetes_pod_label_name
- __meta_kubernetes_pod_label_k8s_app
- source_labels:
- __meta_kubernetes_pod_label_app
target_label: __service__
- source_labels:
- __meta_kubernetes_pod_node_name
target_label: __host__
- action: drop
regex: ''
source_labels:
- __service__
{{- include "promtail.kubernetesPodsLabelmapConfig" . | trim | nindent 4 }}
- action: replace
replacement: $1
separator: /
source_labels:
- __meta_kubernetes_namespace
- __service__
target_label: job
- action: replace
source_labels:
- __meta_kubernetes_namespace
target_label: namespace
- action: replace
source_labels:
- __meta_kubernetes_pod_name
target_label: pod
- action: replace
source_labels:
- __meta_kubernetes_pod_container_name
target_label: container
- replacement: {{ default "/var/log/pods" .podsPath | printf "%s/*$1/*.log" }}
separator: /
source_labels:
- __meta_kubernetes_pod_uid
- __meta_kubernetes_pod_container_name
target_label: __path__
{{- end -}}
{{- define "promtail.kubernetesPodsDirectControllersJob" -}}
- job_name: kubernetes-pods-direct-controllers
pipeline_stages:
{{- include "promtail.kubernetesPodsPipelineStages" . | trim | nindent 4 }}
kubernetes_sd_configs:
- role: pod
relabel_configs:
{{- if .excludeNamespaces }}
{{- include "promtail.kubernetesPodsExcludeNamespaces" . | trim | nindent 4 }}
{{- end }}
{{- include "promtail.kubernetesPodsDropAnnotation" . | trim | nindent 4 }}
- action: drop
regex: .+
separator: ''
source_labels:
- __meta_kubernetes_pod_label_name
- __meta_kubernetes_pod_label_k8s_app
- __meta_kubernetes_pod_label_app
- action: drop
regex: '[0-9a-z-.]+-[0-9a-f]{8,10}'
source_labels:
- __meta_kubernetes_pod_controller_name
- source_labels:
- __meta_kubernetes_pod_controller_name
target_label: __service__
- source_labels:
- __meta_kubernetes_pod_node_name
target_label: __host__
- action: drop
regex: ''
source_labels:
- __service__
{{- include "promtail.kubernetesPodsLabelmapConfig" . | trim | nindent 4 }}
- action: replace
replacement: $1
separator: /
source_labels:
- __meta_kubernetes_namespace
- __service__
target_label: job
- action: replace
source_labels:
- __meta_kubernetes_namespace
target_label: namespace
- action: replace
source_labels:
- __meta_kubernetes_pod_name
target_label: pod
- action: replace
source_labels:
- __meta_kubernetes_pod_container_name
target_label: container
- replacement: {{ default "/var/log/pods" .podsPath | printf "%s/*$1/*.log" }}
separator: /
source_labels:
- __meta_kubernetes_pod_uid
- __meta_kubernetes_pod_container_name
target_label: __path__
{{- end -}}
{{- define "promtail.kubernetesPodsDropAnnotation" -}}
{{- $dropAnnotation := default "promtail.kube-ops.io/drop" .dropAnnotation | replace "." "_" | replace "-" "_" | replace "/" "_" | lower | printf "__meta_kubernetes_pod_annotationpresent_%s" -}}
- action: drop
regex: .+
source_labels:
- {{ $dropAnnotation }}
{{- end -}}
{{- define "promtail.kubernetesPodsExcludeNamespaces" -}}
{{- $namespaces := join "|" .excludeNamespaces -}}
- action: drop
regex: {{ printf "^(%s)$" $namespaces }}
source_labels:
- __meta_kubernetes_namespace
{{- end -}}
{{- define "promtail.kubernetesPodsIndirectControllerJob" -}}
- job_name: kubernetes-pods-indirect-controller
pipeline_stages:
{{- include "promtail.kubernetesPodsPipelineStages" . | trim | nindent 4 }}
kubernetes_sd_configs:
- role: pod
relabel_configs:
{{- if .excludeNamespaces }}
{{- include "promtail.kubernetesPodsExcludeNamespaces" . | trim | nindent 4 }}
{{- end }}
{{- include "promtail.kubernetesPodsDropAnnotation" . | trim | nindent 4 }}
- action: drop
regex: .+
separator: ''
source_labels:
- __meta_kubernetes_pod_label_name
- __meta_kubernetes_pod_label_k8s_app
- __meta_kubernetes_pod_label_app
- action: keep
regex: '[0-9a-z-.]+-[0-9a-f]{8,10}'
source_labels:
- __meta_kubernetes_pod_controller_name
- action: replace
regex: '([0-9a-z-.]+)-[0-9a-f]{8,10}'
source_labels:
- __meta_kubernetes_pod_controller_name
target_label: __service__
- source_labels:
- __meta_kubernetes_pod_node_name
target_label: __host__
- action: drop
regex: ''
source_labels:
- __service__
{{- include "promtail.kubernetesPodsLabelmapConfig" . | trim | nindent 4 }}
- action: replace
replacement: $1
separator: /
source_labels:
- __meta_kubernetes_namespace
- __service__
target_label: job
- action: replace
source_labels:
- __meta_kubernetes_namespace
target_label: namespace
- action: replace
source_labels:
- __meta_kubernetes_pod_name
target_label: pod
- action: replace
source_labels:
- __meta_kubernetes_pod_container_name
target_label: container
- replacement: {{ default "/var/log/pods" .podsPath | printf "%s/*$1/*.log" }}
separator: /
source_labels:
- __meta_kubernetes_pod_uid
- __meta_kubernetes_pod_container_name
target_label: __path__
{{- end -}}
{{- define "promtail.kubernetesPodsK8sAppJob" -}}
- job_name: kubernetes-pods-k8s-app
pipeline_stages:
{{- include "promtail.kubernetesPodsPipelineStages" . | trim | nindent 4 }}
kubernetes_sd_configs:
- role: pod
relabel_configs:
{{- if .excludeNamespaces }}
{{- include "promtail.kubernetesPodsExcludeNamespaces" . | trim | nindent 4 }}
{{- end }}
{{- include "promtail.kubernetesPodsDropAnnotation" . | trim | nindent 4 }}
- action: drop
regex: .+
source_labels:
- __meta_kubernetes_pod_label_name
- source_labels:
- __meta_kubernetes_pod_label_k8s_app
target_label: __service__
- source_labels:
- __meta_kubernetes_pod_node_name
target_label: __host__
- action: drop
regex: ''
source_labels:
- __service__
{{- include "promtail.kubernetesPodsLabelmapConfig" . | trim | nindent 4 }}
- action: replace
replacement: $1
separator: /
source_labels:
- __meta_kubernetes_namespace
- __service__
target_label: job
- action: replace
source_labels:
- __meta_kubernetes_namespace
target_label: namespace
- action: replace
source_labels:
- __meta_kubernetes_pod_name
target_label: pod
- action: replace
source_labels:
- __meta_kubernetes_pod_container_name
target_label: container
- replacement: {{ default "/var/log/pods" .podsPath | printf "%s/*$1/*.log" }}
separator: /
source_labels:
- __meta_kubernetes_pod_uid
- __meta_kubernetes_pod_container_name
target_label: __path__
{{- end -}}
{{- define "promtail.kubernetesPodsLabelmapConfig" -}}
{{- $labelsPrefix := default "promtail.kube-ops.io/label" .labelsPrefix | replace "." "_" | replace "-" "_" | replace "/" "_" | lower | printf "__meta_kubernetes_pod_label_%s" -}}
- action: labelmap
regex: {{ printf "%s_(.+)" $labelsPrefix }}
replacement: '__labelmap_$1'
- action: labeldrop
regex: {{ printf "%s_(.+)" $labelsPrefix }}
- action: labelmap
regex: __meta_kubernetes_pod_label_(.+)
- action: labelmap
regex: __labelmap_(.+)
{{- end -}}
{{- define "promtail.kubernetesPodsNameJob" -}}
- job_name: kubernetes-pods-name
pipeline_stages:
{{- include "promtail.kubernetesPodsPipelineStages" . | trim | nindent 4 }}
kubernetes_sd_configs:
- role: pod
relabel_configs:
{{- if .excludeNamespaces }}
{{- include "promtail.kubernetesPodsExcludeNamespaces" . | trim | nindent 4 }}
{{- end }}
{{- include "promtail.kubernetesPodsDropAnnotation" . | trim | nindent 4 }}
- source_labels:
- __meta_kubernetes_pod_label_name
target_label: __service__
- source_labels:
- __meta_kubernetes_pod_node_name
target_label: __host__
- action: drop
regex: ''
source_labels:
- __service__
{{- include "promtail.kubernetesPodsLabelmapConfig" . | trim | nindent 4 }}
- action: replace
replacement: $1
separator: /
source_labels:
- __meta_kubernetes_namespace
- __service__
target_label: job
- action: replace
source_labels:
- __meta_kubernetes_namespace
target_label: namespace
- action: replace
source_labels:
- __meta_kubernetes_pod_name
target_label: pod
- action: replace
source_labels:
- __meta_kubernetes_pod_container_name
target_label: container
- replacement: {{ default "/var/log/pods" .podsPath | printf "%s/*$1/*.log" }}
separator: /
source_labels:
- __meta_kubernetes_pod_uid
- __meta_kubernetes_pod_container_name
target_label: __path__
{{- end -}}
{{- define "promtail.kubernetesPodsPipelineStages" -}}
{{- if .pipelineStages }}
{{- toYaml .pipelineStages }}
{{- else }}
- docker: {}
- match:
selector: '{pod=~".+"} |~ "\b(level=debug|debug=true)\b"'
stages:
- drop:
expression: '.*'
drop_counter_reason: drop_debug_messages
- match:
selector: '{pod=~".+"} |~ "\b[Dd]eprecated\b"'
stages:
- drop:
expression: '.*'
drop_counter_reason: drop_deprecated_messages
- match:
selector: '{pod=~".+"} |= "GET /"'
stages:
- drop:
expression: '"kube-probe/1.[0-9]+"'
drop_counter_reason: drop_readiness_probes
- drop:
expression: '^127.0.0.1 .* 200 '
drop_counter_reason: drop_readiness_probes
- drop:
expression: 'GET /(healthz|ping)\b.* 200 '
drop_counter_reason: drop_readiness_probes
- match:
selector: '{pod=~".+"} |~ `^[DNIWEF]\d+ .*.go:\d+\] `'
stages:
- regex:
expression: '^(?s)(?P<level>[DNIWEF])\d+ .* (?P<go_file>[\w-]+\.go):(?P<go_line>\d+)\] (?P<message>.*)$'
- template:
source: level
template: {{ "'{{ if eq .level \"D\" }}debug{{ else if eq .level \"N\" }}notice{{ else if eq .level \"I\" }}info{{ else if eq .level \"W\" }}warning{{ else if eq .level \"E\" }}error{{ else if eq .level \"F\" }}fatal{{ end }}'" }}
- drop:
source: level
expression: (debug|notice)
drop_counter_reason: drop_debug_messages
- labels:
level:
go_file:
go_line:
- output:
source: message
{{- end }}
{{- if .extraPipelineStages }}
{{ toYaml .extraPipelineStages }}