Skip to content

Commit 431e451

Browse files
1 parent 4e74903 commit 431e451

File tree

5 files changed

+185
-6
lines changed

5 files changed

+185
-6
lines changed

charts/opentelemetry-collector/Chart.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
apiVersion: v2
22
name: opentelemetry-collector
3-
version: 0.4.3
3+
version: 0.5.0
44
description: OpenTelemetry Collector Helm chart for Kubernetes
55
type: application
66
home: https://opentelemetry.io/
@@ -13,4 +13,4 @@ maintainers:
1313
- name: pjanotti
1414
- name: tigrannajaryan
1515
icon: https://opentelemetry.io/img/logos/opentelemetry-logo-nav.png
16-
appVersion: 0.20.0
16+
appVersion: 0.22.0

charts/opentelemetry-collector/README.md

+73-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ helm install my-opentelemetry-collector open-telemetry/opentelemetry-collector
2525

2626
### Default configuration
2727

28-
By default this chart will deploy an OpenTelemetry Collector as daemonset with two pipelines (traces and metrics)
28+
By default this chart will deploy an OpenTelemetry Collector as daemonset with three pipelines (logs, metrics and traces)
2929
and logging exporter enabled by default. Besides daemonset (agent), it can be also installed as standalone deployment.
30-
Both modes can be enabled together, in that case metrics and traces will be flowing from agents to standalone collectors.
30+
Both modes can be enabled together, in that case logs, metrics and traces will be flowing from agents to standalone collectors.
3131

3232
*Example*: Install collector as a standalone deployment, and do not run it as an agent.
3333

@@ -42,6 +42,7 @@ By default collector has the following receivers enabled:
4242
4343
- **metrics**: OTLP and prometheus. Prometheus is configured only for scraping collector's own metrics.
4444
- **traces**: OTLP, zipkin and jaeger (thrift and grpc).
45+
- **logs**: OTLP (to enable container logs, see [Configuration for Kubernetes container logs](#configuration-for-kubernetes-container-logs)).
4546
4647
There are two ways to configure collector pipelines, which can be used together as well.
4748
@@ -107,6 +108,76 @@ agentCollector:
107108
mountPropagation: HostToContainer
108109
```
109110

111+
### Configuration for Kubernetes container logs
112+
113+
The collector can be used to collect logs sent to standard output by Kubernetes containers.
114+
This feature is disabled by default. It has the following requirements:
115+
116+
- It needs agent collector to be deployed, which means it will not work if only standalone collector is enabled.
117+
- It requires the [contrib](https://github.com/open-telemetry/opentelemetry-collector-contrib) version
118+
of the collector image.
119+
120+
To enable this feature, set the `agentCollector.containerLogs.enabled` property to `true` and replace the collector image.
121+
Here is an example `values.yaml`:
122+
123+
```yaml
124+
agentCollector:
125+
containerLogs:
126+
enabled: true
127+
128+
image:
129+
repository: otel/opentelemetry-collector-contrib
130+
131+
command:
132+
name: otelcontribcol
133+
```
134+
135+
The way this feature works is it adds a `filelog` receiver on the `logs` pipeline. This receiver is preconfigured
136+
to read the files where Kubernetes container runtime writes all containers' console output to.
137+
138+
#### :warning: Warning: Risk of looping the exported logs back into the receiver, causing "log explosion"
139+
140+
The container logs pipeline uses the `logging` console exporter by default.
141+
Paired with the default `filelog` receiver that receives all containers' console output,
142+
it is easy to accidentally feed the exported logs back into the receiver.
143+
144+
Also note that using the `--log-level=debug` option for the `logging` exporter causes it to output
145+
multiple lines per single received log, which when looped, would amplify the logs exponentially.
146+
147+
To prevent the looping, the default configuration of the receiver excludes logs from the collector's containers.
148+
149+
If you want to include the collector's logs, make sure to replace the `logging` exporter
150+
with an exporter that does not send logs to collector's standard output.
151+
152+
Here's an example `values.yaml` file that replaces the default `logging` exporter on the `logs` pipeline
153+
with an `otlphttp` exporter that sends the container logs to `https://example.com:55681` endpoint.
154+
It also clears the `filelog` receiver's `exclude` property, for collector logs to be included in the pipeline.
155+
156+
```yaml
157+
agentCollector:
158+
containerLogs:
159+
enabled: true
160+
161+
configOverride:
162+
exporters:
163+
otlphttp:
164+
endpoint: https://example.com:55681
165+
receivers:
166+
filelog:
167+
exclude: []
168+
service:
169+
pipelines:
170+
logs:
171+
exporters:
172+
- otlphttp
173+
174+
image:
175+
repository: otel/opentelemetry-collector-contrib
176+
177+
command:
178+
name: otelcontribcol
179+
```
180+
110181
### Other configuration options
111182

112183
The [values.yaml](./values.yaml) file contains information about all other configuration

charts/opentelemetry-collector/templates/_config.tpl

+82
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Build config file for agent OpenTelemetry Collector
3232
{{- $values := deepCopy .Values.agentCollector | mustMergeOverwrite (deepCopy .Values) }}
3333
{{- $data := dict "Values" $values | mustMergeOverwrite (deepCopy .) }}
3434
{{- $config := include "opentelemetry-collector.baseConfig" $data | fromYaml }}
35+
{{- $config := include "opentelemetry-collector.agent.containerLogsConfig" $data | fromYaml | mustMergeOverwrite $config }}
3536
{{- $config := include "opentelemetry-collector.agentConfigOverride" $data | fromYaml | mustMergeOverwrite $config }}
3637
{{- .Values.agentCollector.configOverride | mustMergeOverwrite $config | toYaml }}
3738
{{- end }}
@@ -115,9 +116,90 @@ exporters:
115116
{{- if .Values.standaloneCollector.enabled }}
116117
service:
117118
pipelines:
119+
logs:
120+
exporters: [otlp]
118121
metrics:
119122
exporters: [otlp]
120123
traces:
121124
exporters: [otlp]
122125
{{- end }}
123126
{{- end }}
127+
128+
{{- define "opentelemetry-collector.agent.containerLogsConfig" -}}
129+
{{- if .Values.agentCollector.containerLogs.enabled }}
130+
receivers:
131+
filelog:
132+
include: [ /var/log/pods/*/*/*.log ]
133+
# Exclude collector container's logs. The file format is /var/log/pods/<namespace_name>_<pod_name>_<pod_uid>/<container_name>/<run_id>.log
134+
exclude: [ /var/log/pods/{{ .Release.Namespace }}_{{ include "opentelemetry-collector.fullname" . }}*_*/{{ .Chart.Name }}/*.log ]
135+
start_at: beginning
136+
include_file_path: true
137+
include_file_name: false
138+
operators:
139+
# Find out which format is used by kubernetes
140+
- type: router
141+
id: get-format
142+
routes:
143+
- output: parser-docker
144+
expr: '$$record matches "^\\{"'
145+
- output: parser-crio
146+
expr: '$$record matches "^[^ Z]+ "'
147+
- output: parser-containerd
148+
expr: '$$record matches "^[^ Z]+Z"'
149+
# Parse CRI-O format
150+
- type: regex_parser
151+
id: parser-crio
152+
regex: '^(?P<time>[^ Z]+) (?P<stream>stdout|stderr) (?P<logtag>[^ ]*) (?P<log>.*)$'
153+
output: extract_metadata_from_filepath
154+
timestamp:
155+
parse_from: time
156+
layout_type: gotime
157+
layout: '2006-01-02T15:04:05.000000000-07:00'
158+
# Parse CRI-Containerd format
159+
- type: regex_parser
160+
id: parser-containerd
161+
regex: '^(?P<time>[^ ^Z]+Z) (?P<stream>stdout|stderr) (?P<logtag>[^ ]*) (?P<log>.*)$'
162+
output: extract_metadata_from_filepath
163+
timestamp:
164+
parse_from: time
165+
layout: '%Y-%m-%dT%H:%M:%S.%LZ'
166+
# Parse Docker format
167+
- type: json_parser
168+
id: parser-docker
169+
output: extract_metadata_from_filepath
170+
timestamp:
171+
parse_from: time
172+
layout: '%Y-%m-%dT%H:%M:%S.%LZ'
173+
# Extract metadata from file path
174+
- type: regex_parser
175+
id: extract_metadata_from_filepath
176+
regex: '^.*\/(?P<namespace>[^_]+)_(?P<pod_name>[^_]+)_(?P<uid>[a-f0-9\-]{36})\/(?P<container_name>[^\._]+)\/(?P<run_id>\d+)\.log$'
177+
parse_from: $$attributes.file_path
178+
# Move out attributes to Attributes
179+
- type: metadata
180+
labels:
181+
stream: 'EXPR($.stream)'
182+
k8s.container.name: 'EXPR($.container_name)'
183+
k8s.namespace.name: 'EXPR($.namespace)'
184+
k8s.pod.name: 'EXPR($.pod_name)'
185+
run_id: 'EXPR($.run_id)'
186+
k8s.pod.uid: 'EXPR($.uid)'
187+
# Clean up log record
188+
- type: restructure
189+
id: clean-up-log-record
190+
ops:
191+
- remove: logtag
192+
- remove: stream
193+
- remove: container_name
194+
- remove: namespace
195+
- remove: pod_name
196+
- remove: run_id
197+
- remove: uid
198+
service:
199+
pipelines:
200+
logs:
201+
receivers:
202+
- filelog
203+
- otlp
204+
{{- end }}
205+
{{- end }}

charts/opentelemetry-collector/templates/_pod.tpl

+16
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ containers:
6161
mountPropagation: {{ .mountPropagation }}
6262
{{- end }}
6363
{{- end }}
64+
{{- if and $.isAgent .Values.agentCollector.containerLogs.enabled }}
65+
- name: varlogpods
66+
mountPath: /var/log/pods
67+
readOnly: true
68+
- name: varlibdockercontainers
69+
mountPath: /var/lib/docker/containers
70+
readOnly: true
71+
{{- end }}
6472
volumes:
6573
- name: {{ .Chart.Name }}-configmap
6674
configMap:
@@ -73,6 +81,14 @@ volumes:
7381
hostPath:
7482
path: {{ .hostPath }}
7583
{{- end }}
84+
{{- if and $.isAgent .Values.agentCollector.containerLogs.enabled }}
85+
- name: varlogpods
86+
hostPath:
87+
path: /var/log/pods
88+
- name: varlibdockercontainers
89+
hostPath:
90+
path: /var/lib/docker/containers
91+
{{- end }}
7692
{{- with .Values.nodeSelector }}
7793
nodeSelector:
7894
{{- toYaml . | nindent 2 }}

charts/opentelemetry-collector/values.yaml

+12-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ config:
3939
extensions:
4040
- health_check
4141
pipelines:
42+
logs:
43+
exporters:
44+
- logging
45+
processors:
46+
- memory_limiter
47+
- batch
48+
receivers:
49+
- otlp
4250
metrics:
4351
exporters:
4452
- logging
@@ -63,8 +71,8 @@ config:
6371
# Can be overridden here or for any component independently using the same keys.
6472

6573
image:
74+
# If you want to use the contrib image `otel/opentelemetry-collector-contrib`, you also need to change `command.name` value to `otelcontribcol`.
6675
repository: otel/opentelemetry-collector
67-
# repository: otel/opentelemetry-collector-contrib
6876
pullPolicy: IfNotPresent
6977
# Overrides the image tag whose default is the chart appVersion.
7078
tag: ""
@@ -73,7 +81,6 @@ imagePullSecrets: []
7381
# OpenTelemetry Collector executable
7482
command:
7583
name: otelcol
76-
# name: otelcontribcol
7784
extraArgs: []
7885

7986
serviceAccount:
@@ -127,6 +134,9 @@ ports:
127134
agentCollector:
128135
enabled: true
129136

137+
containerLogs:
138+
enabled: false
139+
130140
resources:
131141
limits:
132142
cpu: 256m

0 commit comments

Comments
 (0)