Skip to content

Commit 9bf3d1e

Browse files
author
CircleCI
committed
parsed_body based filtering of error, need to remove attribute after filtering
1 parent 715f637 commit 9bf3d1e

File tree

4 files changed

+111
-91
lines changed

4 files changed

+111
-91
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{{ define "clusterAgent.otelCollectorConfig.filelogreceiver.operators" -}}
2+
# Find out which format is used by kubernetes
3+
- type: router
4+
id: get-format
5+
routes:
6+
- output: parser-docker
7+
expr: 'body matches "^\\{"'
8+
- output: parser-crio
9+
expr: 'body matches "^[^ Z]+ "'
10+
- output: parser-containerd
11+
expr: 'body matches "^[^ Z]+Z"'
12+
# Parse CRI-O format
13+
- type: regex_parser
14+
id: parser-crio
15+
regex:
16+
'^(?P<time>[^ Z]+) (?P<stream>stdout|stderr) (?P<logtag>[^ ]*) ?(?P<log>.*)$'
17+
output: overwrite-log-body
18+
timestamp:
19+
parse_from: attributes.time
20+
layout_type: gotime
21+
layout: '2006-01-02T15:04:05.999999999Z07:00'
22+
# Parse CRI-Containerd format
23+
- type: regex_parser
24+
id: parser-containerd
25+
regex:
26+
'^(?P<time>[^ ^Z]+Z) (?P<stream>stdout|stderr) (?P<logtag>[^ ]*) ?(?P<log>.*)$'
27+
output: overwrite-log-body
28+
timestamp:
29+
parse_from: attributes.time
30+
layout: '%Y-%m-%dT%H:%M:%S.%LZ'
31+
# Parse Docker format
32+
- type: json_parser
33+
id: parser-docker
34+
output: overwrite-log-body
35+
timestamp:
36+
parse_from: attributes.time
37+
layout: '%Y-%m-%dT%H:%M:%S.%LZ'
38+
- type: move
39+
id: overwrite-log-body
40+
from: attributes["log"]
41+
to: body
42+
# best effort attempt to parse the body as a stringified JSON object
43+
- type: json_parser
44+
parse_from: body
45+
parse_to: attributes["parsed_body"]
46+
on_error: send_quiet
47+
# Extract metadata from file path
48+
- type: regex_parser
49+
id: extract-metadata-from-filepath
50+
regex: '^.*\/(?P<namespace>[^_]+)_(?P<pod_name>[^_]+)_(?P<uid>[a-f0-9\-]{36})\/(?P<container_name>[^\._]+)\/(?P<restart_count>\d+)\.log$'
51+
parse_from: attributes["log.file.path"]
52+
cache:
53+
size: 128 # default maximum amount of Pods per Node is 110
54+
# Rename attributes
55+
- type: move
56+
from: attributes.stream
57+
to: attributes["log.iostream"]
58+
- type: move
59+
from: attributes.container_name
60+
to: resource["k8s.container.name"]
61+
- type: move
62+
from: attributes.namespace
63+
to: resource["k8s.namespace.name"]
64+
- type: move
65+
from: attributes.pod_name
66+
to: resource["k8s.pod.name"]
67+
- type: move
68+
from: attributes.restart_count
69+
to: resource["k8s.container.restart_count"]
70+
- type: move
71+
from: attributes.uid
72+
to: resource["k8s.pod.uid"]
73+
{{- end }}

charts/lumigo-operator/templates/cluster-agent-daemonset.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
{{- $logsEnabled := or .Values.clusterCollection.logs.enabled .Values.watchdog.logs.enabled }}
2-
{{- if or $logsEnabled .Values.clusterCollection.metrics.enabled }}
1+
{{- $watchdogLogsEnabled := and .Values.watchdog.enabled .Values.watchdog.logs.enabled -}}
2+
{{- $logCollectionEnabled := or .Values.clusterCollection.logs.enabled $watchdogLogsEnabled -}}
3+
{{- if $logCollectionEnabled }}
34
apiVersion: v1
45
kind: ConfigMap
56
metadata:
@@ -35,7 +36,7 @@ spec:
3536
lumigo.auto-trace: 'false' # We don't want the operator to inject itself into pods from this daemonset
3637
spec:
3738
containers:
38-
{{- if $logsEnabled }}
39+
{{- if $logCollectionEnabled }}
3940
- name: otel-collector
4041
image: {{ .Values.logFileCollector.image.repository }}:{{ .Values.logFileCollector.image.tag }}
4142
env:
@@ -89,7 +90,7 @@ spec:
8990
- name: collector-config
9091
configMap:
9192
name: {{ include "helm.fullname" . }}-cluster-agent-config
92-
{{- if $logsEnabled }}
93+
{{- if $logCollectionEnabled }}
9394
- name: varlogpods
9495
hostPath:
9596
path: /var/log/pods/
Lines changed: 32 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
{{- define "clusterAgent.otelCollectorConfig" -}}
2+
{{ $logCollectionEnabled := .Values.clusterCollection.logs.enabled }}
3+
{{ $watchdogLogsEnabled := and .Values.watchdog.enabled .Values.watchdog.logs.enabled }}
24
receivers:
3-
{{- if or .Values.watchdog.logs.enabled .Values.watchdog.logs.include }}
4-
filelog/watchdog:
5-
include:
6-
- /var/log/pods/{{ .Release.Namespace }}_{{ include "helm.fullname" . }}-controller-manager_*/*/*.log
7-
- /var/log/pods/{{ .Release.Namespace }}_{{ include "helm.fullname" . }}-telemetry-proxy_*/*/*.log
8-
{{- end }}
5+
{{ if $logCollectionEnabled }}
96
filelog/application:
107
include:
11-
{{ if .Values.clusterCollection.logs.include }}
12-
{{- range .Values.clusterCollection.logs.include }}
8+
{{ if .Values.clusterCollection.logs.include }}
9+
{{- range .Values.clusterCollection.logs.include }}
1310
- /var/log/pods/{{ .namespacePattern | default "*" }}_{{ .podPattern | default "*" }}_*/{{ .containerPattern | default "*" }}/*.log
14-
{{- end }}
15-
{{- else }}
11+
{{- end }}
12+
{{- else }}
1613
- /var/log/pods/*/*/*.log
17-
{{- end }}
14+
{{- end }}
1815
exclude:
16+
- /var/log/pods/{{ .Release.Namespace }}_*/*/*.log
1917
- /var/log/pods/kube-system_*/*/*.log
20-
- /var/log/pods/lumigo-system_*/*/*.log
2118
# Exclude logs from the otlp-sink in tests (Kind cluster)
2219
- /var/log/pods/local-path-storage_*/*/*.log
2320
- /var/log/pods/otlp-sink_*/*/*.log
@@ -30,76 +27,20 @@ receivers:
3027
include_file_path: true
3128
include_file_name: false
3229
operators:
33-
# Find out which format is used by kubernetes
34-
- type: router
35-
id: get-format
36-
routes:
37-
- output: parser-docker
38-
expr: 'body matches "^\\{"'
39-
- output: parser-crio
40-
expr: 'body matches "^[^ Z]+ "'
41-
- output: parser-containerd
42-
expr: 'body matches "^[^ Z]+Z"'
43-
# Parse CRI-O format
44-
- type: regex_parser
45-
id: parser-crio
46-
regex:
47-
'^(?P<time>[^ Z]+) (?P<stream>stdout|stderr) (?P<logtag>[^ ]*) ?(?P<log>.*)$'
48-
output: overwrite-log-body
49-
timestamp:
50-
parse_from: attributes.time
51-
layout_type: gotime
52-
layout: '2006-01-02T15:04:05.999999999Z07:00'
53-
# Parse CRI-Containerd format
54-
- type: regex_parser
55-
id: parser-containerd
56-
regex:
57-
'^(?P<time>[^ ^Z]+Z) (?P<stream>stdout|stderr) (?P<logtag>[^ ]*) ?(?P<log>.*)$'
58-
output: overwrite-log-body
59-
timestamp:
60-
parse_from: attributes.time
61-
layout: '%Y-%m-%dT%H:%M:%S.%LZ'
62-
# Parse Docker format
63-
- type: json_parser
64-
id: parser-docker
65-
output: overwrite-log-body
66-
timestamp:
67-
parse_from: attributes.time
68-
layout: '%Y-%m-%dT%H:%M:%S.%LZ'
69-
- type: move
70-
id: overwrite-log-body
71-
from: attributes["log"]
72-
to: body
73-
# best effort attempt to parse the body as a stringified JSON object
74-
- type: json_parser
75-
parse_to: body
76-
on_error: send_quiet
77-
# Extract metadata from file path
78-
- type: regex_parser
79-
id: extract-metadata-from-filepath
80-
regex: '^.*\/(?P<namespace>[^_]+)_(?P<pod_name>[^_]+)_(?P<uid>[a-f0-9\-]{36})\/(?P<container_name>[^\._]+)\/(?P<restart_count>\d+)\.log$'
81-
parse_from: attributes["log.file.path"]
82-
cache:
83-
size: 128 # default maximum amount of Pods per Node is 110
84-
# Rename attributes
85-
- type: move
86-
from: attributes.stream
87-
to: attributes["log.iostream"]
88-
- type: move
89-
from: attributes.container_name
90-
to: resource["k8s.container.name"]
91-
- type: move
92-
from: attributes.namespace
93-
to: resource["k8s.namespace.name"]
94-
- type: move
95-
from: attributes.pod_name
96-
to: resource["k8s.pod.name"]
97-
- type: move
98-
from: attributes.restart_count
99-
to: resource["k8s.container.restart_count"]
100-
- type: move
101-
from: attributes.uid
102-
to: resource["k8s.pod.uid"]
30+
{{ include "clusterAgent.otelCollectorConfig.filelogreceiver.operators" . | indent 4 }}
31+
{{- end }}
32+
{{- if $watchdogLogsEnabled }}
33+
filelog/watchdog:
34+
include:
35+
- /var/log/pods/{{ .Release.Namespace }}_{{ include "helm.fullname" . }}-controller-manager-*_*/*/*.log
36+
- /var/log/pods/{{ .Release.Namespace }}_{{ include "helm.fullname" . }}-telemetry-proxy-*_*/*/*.log
37+
start_at: end
38+
include_file_path: true
39+
include_file_name: false
40+
operators:
41+
{{ include "clusterAgent.otelCollectorConfig.filelogreceiver.operators" . | indent 4 }}
42+
{{- end }}
43+
10344
exporters:
10445
otlphttp:
10546
endpoint: ${env:LUMIGO_LOGS_ENDPOINT}
@@ -110,6 +51,7 @@ exporters:
11051
verbosity: detailed
11152
{{- end }}
11253
processors:
54+
batch:
11355
transform/application:
11456
log_statements:
11557
- context: log
@@ -120,13 +62,15 @@ processors:
12062
log_statements:
12163
- context: log
12264
statements:
123-
- set(instrumentation_scope.name, "lumigo-operator.watchdog_log_file_collector")
65+
- set(instrumentation_scope.name, "lumigo-operator.watchdog.log_file_collector")
12466
- set(resource.attributes["k8s.cluster.name"], "${env:KUBERNETES_CLUSTER_NAME}")
12567
filter/drop_non_error_logs:
68+
error_mode: propagate
12669
logs:
12770
log_record:
128-
- 'not IsMatch(body, ".*error.*")'
129-
batch:
71+
- not IsMap(log.attributes["parsed_body"])
72+
- not IsString(log.attributes["parsed_body"]["error"])
73+
13074
service:
13175
{{- if .Values.debug.enabled }}
13276
telemetry:
@@ -135,7 +79,7 @@ service:
13579
encoding: json
13680
{{- end }}
13781
pipelines:
138-
{{- if .Values.watchdog.logs.enabled }}
82+
{{ if $logCollectionEnabled }}
13983
logs/application:
14084
receivers:
14185
- filelog/application
@@ -148,6 +92,7 @@ service:
14892
- debug
14993
{{- end }}
15094
{{- end }}
95+
{{- if $watchdogLogsEnabled }}
15196
logs/watchdog:
15297
receivers:
15398
- filelog/watchdog
@@ -161,3 +106,4 @@ service:
161106
- debug
162107
{{- end }}
163108
{{- end }}
109+
{{- end }}

charts/lumigo-operator/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ controllerManager:
7474
logFileCollector:
7575
image:
7676
repository: otel/opentelemetry-collector-contrib
77-
tag: 0.112.0
77+
tag: 0.122.0
7878
resources:
7979
limits:
8080
cpu: 500m

0 commit comments

Comments
 (0)