Hi, i have the question related to promtail configuration. I’ve decided to not to use pod_name as label and add it structured metadata.
In my case I had to add it in additional to match step in pipeline because looks like it isn’t inherited from main pipeline stage. Could you please suggest more elegant way to do it if exists.
Here is my config:
config:
clients:
- url: http://loki-gateway/loki/api/v1/push
snippets:
extraRelabelConfigs:
- source_labels: [__meta_kubernetes_pod_annotation_promtail_parser]
action: replace
target_label: promtail_parser
regex: (.*)
replacement: $1
- source_labels: [ __meta_kubernetes_pod_name]
action: replace
target_label: pod_name
regex: (.*)
replacement: $1
pipelineStages:
- cri: {}
- structured_metadata:
pod_name:
- match:
selector: '{promtail_parser="java-basic-format"}'
stages:
- multiline:
firstline: '^ts=[\d\s\-:\.]+ '
max_lines: 512
- regex:
expression: '^(?s)ts=(?P<timestamp>[\d\s:\.\-]+)\s+th=(?P<thread>[^\s]+)\s+ln=(?P<logger_name>[^\s]+)\s+\[(?P<level>[A-Z]+)\]\s+(?P<message>.*)$'
- timestamp:
source: timestamp
format: 2006-01-02 15:04:05.000
- structured_metadata:
thread:
logger_name:
level:
pod_name:
- output:
source: message
- labeldrop:
- promtail_parser
- labeldrop:
- filename
- pod_name
common:
- action: replace
source_labels:
- __meta_kubernetes_pod_node_name
target_label: node_name
- action: replace
source_labels:
- __meta_kubernetes_namespace
target_label: namespace
- action: replace
replacement: $1
separator: /
source_labels:
- namespace
- app
target_label: job
- action: replace
source_labels:
- __meta_kubernetes_pod_container_name
target_label: container
- action: replace
replacement: /var/log/pods/*$1/*.log
separator: /
source_labels:
- __meta_kubernetes_pod_uid
- __meta_kubernetes_pod_container_name
target_label: __path__
- action: replace
replacement: /var/log/pods/*$1/*.log
regex: true/(.*)
separator: /
source_labels:
- __meta_kubernetes_pod_annotationpresent_kubernetes_io_config_hash
- __meta_kubernetes_pod_annotation_kubernetes_io_config_hash
- __meta_kubernetes_pod_container_name
target_label: __path__