Skip to content

Commit f81d03e

Browse files
committed
Helm chart for OpenTelemetry Collector
1 parent 7b89268 commit f81d03e

20 files changed

+764
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: v2
2+
name: opentelemetry-collector
3+
description: A Helm chart for Kubernetes
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 0.1.0
19+
20+
# This is the version number of the application being deployed. This version number should be
21+
# incremented each time you make changes to the application. Versions are not expected to
22+
# follow Semantic Versioning. They should reflect the version the application is using.
23+
appVersion: 0.9.0

helm-charts/opentelemetry-collector/templates/NOTES.txt

Whitespace-only changes.
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "opentelemetry-collector.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "opentelemetry-collector.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "opentelemetry-collector.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "opentelemetry-collector.labels" -}}
37+
helm.sh/chart: {{ include "opentelemetry-collector.chart" . }}
38+
{{ include "opentelemetry-collector.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "opentelemetry-collector.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "opentelemetry-collector.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{/*
54+
Create the name of the service account to use
55+
*/}}
56+
{{- define "opentelemetry-collector.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "opentelemetry-collector.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}
63+
64+
{{/*
65+
Build config file with pipelines but without output
66+
*/}}
67+
{{- define "opentelemetry-collector.pipelinesConfig" -}}
68+
{{- $config := include "opentelemetry-collector.baseConfig" . | fromYaml -}}
69+
{{- range $telemetryName, $telemetryParams := .Values.telemetry }}
70+
{{- if index $telemetryParams "enabled" }}
71+
{{- $config := include (printf "opentelemetry-collector.%sPipelineConfig" $telemetryName) $telemetryParams | fromYaml | mustMergeOverwrite $config }}
72+
{{- end }}
73+
{{- end }}
74+
{{- $config | toYaml }}
75+
{{- end }}
76+
77+
{{/*
78+
Build config file for agent OpenTelemetry Collector
79+
*/}}
80+
{{- define "opentelemetry-collector.agentCollectorConfig" -}}
81+
{{- $values := .Values | deepCopy | mustMergeOverwrite .Values.agentCollector }}
82+
{{- $data := . | deepCopy | mustMergeOverwrite (dict "Values" $values) }}
83+
{{- $config := include "opentelemetry-collector.pipelinesConfig" $data | fromYaml -}}
84+
{{- if .Values.telemetry.metrics.enabled }}
85+
{{- $config := include "opentelemetry-collector.agentMetricsPipelineConfig" . | fromYaml | mustMergeOverwrite $config }}
86+
{{- end }}
87+
{{- if .Values.standaloneCollector.enabled }}
88+
{{- $config := include "opentelemetry-collector.standaloneCollectorOutputConfig" . | fromYaml | mustMergeOverwrite $config }}
89+
{{- else }}
90+
{{- $config := include (printf "opentelemetry-collector.%sOutputConfig" .Values.output.type) . | fromYaml | mustMergeOverwrite $config }}
91+
{{- end }}
92+
{{- $config | mustMergeOverwrite .Values.agentCollector.configOverride | toYaml }}
93+
{{- end }}
94+
95+
{{/*
96+
Build config file for standalone OpenTelemetry Collector
97+
*/}}
98+
{{- define "opentelemetry-collector.standaloneCollectorConfig" -}}
99+
{{- $values := .Values | deepCopy | mustMergeOverwrite .Values.standaloneCollector }}
100+
{{- $data := . | deepCopy | mustMergeOverwrite (dict "Values" $values) }}
101+
{{- $config := include "opentelemetry-collector.pipelinesConfig" $data | fromYaml -}}
102+
{{- if .Values.output.enabled }}
103+
{{- $config := include (printf "opentelemetry-collector.%sOutputConfig" .Values.output.type) . | fromYaml | mustMergeOverwrite $config }}
104+
{{- end }}
105+
{{- $config | mustMergeOverwrite .Values.standaloneCollector.configOverride | toYaml }}
106+
{{- end }}
107+
108+
{{/*
109+
Convert memory value from resources.limit to numeric value in MiB to be used by otel memory_limiter processor.
110+
*/}}
111+
{{- define "opentelemetry-collector.convertMemToMib" -}}
112+
{{- $mem := lower . -}}
113+
{{- if hasSuffix "e" $mem -}}
114+
{{- trimSuffix "e" $mem | atoi | mul 1000 | mul 1000 | mul 1000 | mul 1000 -}}
115+
{{- else if hasSuffix "ei" $mem -}}
116+
{{- trimSuffix "ei" $mem | atoi | mul 1024 | mul 1024 | mul 1024 | mul 1024 -}}
117+
{{- else if hasSuffix "p" $mem -}}
118+
{{- trimSuffix "p" $mem | atoi | mul 1000 | mul 1000 | mul 1000 -}}
119+
{{- else if hasSuffix "pi" $mem -}}
120+
{{- trimSuffix "pi" $mem | atoi | mul 1024 | mul 1024 | mul 1024 -}}
121+
{{- else if hasSuffix "t" $mem -}}
122+
{{- trimSuffix "t" $mem | atoi | mul 1000 | mul 1000 -}}
123+
{{- else if hasSuffix "ti" $mem -}}
124+
{{- trimSuffix "ti" $mem | atoi | mul 1024 | mul 1024 -}}
125+
{{- else if hasSuffix "g" $mem -}}
126+
{{- trimSuffix "g" $mem | atoi | mul 1000 -}}
127+
{{- else if hasSuffix "gi" $mem -}}
128+
{{- trimSuffix "gi" $mem | atoi | mul 1024 -}}
129+
{{- else if hasSuffix "m" $mem -}}
130+
{{- div (trimSuffix "m" $mem | atoi | mul 1000) 1024 -}}
131+
{{- else if hasSuffix "mi" $mem -}}
132+
{{- trimSuffix "mi" $mem | atoi -}}
133+
{{- else if hasSuffix "k" $mem -}}
134+
{{- div (trimSuffix "k" $mem | atoi) 1000 -}}
135+
{{- else if hasSuffix "ki" $mem -}}
136+
{{- div (trimSuffix "ki" $mem | atoi) 1024 -}}
137+
{{- else -}}
138+
{{- div (div ($mem | atoi) 1024) 1024 -}}
139+
{{- end -}}
140+
{{- end -}}
141+
142+
{{/*
143+
Get otel memory_limiter limit_mib value based on 80% of resources.memory.limit.
144+
*/}}
145+
{{- define "opentelemetry-collector.getMemLimitMib" -}}
146+
{{- div (mul (include "opentelemetry-collector.convertMemToMib" .) 80) 100 }}
147+
{{- end -}}
148+
149+
{{/*
150+
Get otel memory_limiter spike_limit_mib value based on 25% of resources.memory.limit.
151+
*/}}
152+
{{- define "opentelemetry-collector.getMemSpikeLimitMib" -}}
153+
{{- div (mul (include "opentelemetry-collector.convertMemToMib" .) 25) 100 }}
154+
{{- end -}}
155+
156+
{{/*
157+
Get otel memory_limiter ballast_size_mib value based on 40% of resources.memory.limit.
158+
*/}}
159+
{{- define "opentelemetry-collector.getMemBallastSizeMib" }}
160+
{{- div (mul (include "opentelemetry-collector.convertMemToMib" .) 40) 100 }}
161+
{{- end -}}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{{- define "opentelemetry-collector.pod" -}}
2+
{{- with .Values.imagePullSecrets }}
3+
imagePullSecrets:
4+
{{- toYaml . | nindent 2 }}
5+
{{- end }}
6+
serviceAccountName: {{ include "opentelemetry-collector.serviceAccountName" . }}
7+
securityContext:
8+
{{- toYaml .Values.podSecurityContext | nindent 2 }}
9+
containers:
10+
- name: {{ .Chart.Name }}
11+
command:
12+
- /{{ .Values.command.name }}
13+
- --config=/conf/relay.yaml
14+
- --metrics-addr=0.0.0.0:8888
15+
- --mem-ballast-size-mib={{ template "opentelemetry-collector.getMemBallastSizeMib" .Values.resources.limits.memory }}
16+
{{- range .Values.command.extraArgs }}
17+
- {{ . }}
18+
{{- end }}
19+
securityContext:
20+
{{- toYaml .Values.securityContext | nindent 6 }}
21+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
22+
imagePullPolicy: {{ .Values.image.pullPolicy }}
23+
ports:
24+
{{- range $key, $port := .Values.ports }}
25+
- name: {{ $key }}
26+
containerPort: {{ $port.containerPort }}
27+
protocol: {{ $port.protocol }}
28+
{{- if and $.isAgent $port.hostPort }}
29+
hostPort: {{ $port.hostPort }}
30+
{{- end }}
31+
{{- end }}
32+
env:
33+
- name: MY_POD_IP
34+
valueFrom:
35+
fieldRef:
36+
apiVersion: v1
37+
fieldPath: status.podIP
38+
{{- if and .isAgent .Values.telemetry.metrics.enabled }}
39+
# Env variables for host metrics receiver
40+
- name: HOST_PROC
41+
value: /hostfs/proc
42+
- name: HOST_SYS
43+
value: /hostfs/sys
44+
- name: HOST_ETC
45+
value: /hostfs/etc
46+
- name: HOST_VAR
47+
value: /hostfs/var
48+
- name: HOST_RUN
49+
value: /hostfs/run
50+
- name: HOST_DEV
51+
value: /hostfs/dev
52+
{{- end }}
53+
livenessProbe:
54+
httpGet:
55+
path: /
56+
port: 13133
57+
readinessProbe:
58+
httpGet:
59+
path: /
60+
port: 13133
61+
resources:
62+
{{- toYaml .Values.resources | nindent 6 }}
63+
volumeMounts:
64+
- mountPath: /conf
65+
name: {{ .Chart.Name }}-configmap
66+
{{- if and .isAgent .Values.telemetry.metrics.enabled }}
67+
- mountPath: /hostfs
68+
name: hostfs
69+
readOnly: true
70+
mountPropagation: HostToContainer
71+
{{- end }}
72+
volumes:
73+
- name: {{ .Chart.Name }}-configmap
74+
configMap:
75+
name: {{ include "opentelemetry-collector.fullname" . }}{{ .configmapSuffix }}
76+
items:
77+
- key: relay
78+
path: relay.yaml
79+
{{- if and .isAgent .Values.telemetry.metrics.enabled }}
80+
- name: hostfs
81+
hostPath:
82+
path: /
83+
{{- end }}
84+
{{- with .Values.nodeSelector }}
85+
nodeSelector:
86+
{{- toYaml . | nindent 2 }}
87+
{{- end }}
88+
{{- with .Values.affinity }}
89+
affinity:
90+
{{- toYaml . | nindent 2 }}
91+
{{- end }}
92+
{{- with .Values.tolerations }}
93+
tolerations:
94+
{{- toYaml . | nindent 2 }}
95+
{{- end }}
96+
{{- end }}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{{/*
2+
Base configuration for OpenTelemetry Collector
3+
*/}}
4+
{{- define "opentelemetry-collector.baseConfig" -}}
5+
extensions:
6+
health_check: {}
7+
8+
receivers:
9+
otlp:
10+
protocols:
11+
grpc:
12+
http:
13+
14+
processors:
15+
queued_retry: {}
16+
batch: {}
17+
18+
memory_limiter:
19+
# check_interval is the time between measurements of memory usage.
20+
check_interval: 5s
21+
22+
# By default limit_mib is set to 80% of ".Values.resources.limits.memory"
23+
limit_mib: {{ include "opentelemetry-collector.getMemLimitMib" .Values.resources.limits.memory }}
24+
25+
# By default spike_limit_mib is set to 25% of ".Values.resources.limits.memory"
26+
spike_limit_mib: {{ include "opentelemetry-collector.getMemSpikeLimitMib" .Values.resources.limits.memory }}
27+
28+
# By default ballast_size_mib is set to 40% of ".Values.resources.limits.memory"
29+
ballast_size_mib: {{ include "opentelemetry-collector.getMemBallastSizeMib" .Values.resources.limits.memory }}
30+
31+
service:
32+
extensions: [health_check]
33+
pipelines: {}
34+
{{- end }}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{{/*
2+
Default config for logging output
3+
*/}}
4+
{{- define "opentelemetry-collector.loggingOutputConfig" -}}
5+
exporters:
6+
logging:
7+
logLevel: {{ .Values.output.logLevel | default "info" }}
8+
service:
9+
pipelines:
10+
{{- if .Values.telemetry.metrics.enabled }}
11+
metrics:
12+
exporters: [logging]
13+
{{- end }}
14+
15+
{{- if .Values.telemetry.traces.enabled }}
16+
traces:
17+
exporters: [logging]
18+
{{- end }}
19+
{{- end }}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{{/*
2+
Default output for agent collector pointed to standalone collector
3+
*/}}
4+
{{- define "opentelemetry-collector.standaloneCollectorOutputConfig" -}}
5+
exporters:
6+
otlp:
7+
endpoint: {{ include "opentelemetry-collector.fullname" . }}:55680
8+
insecure: true
9+
service:
10+
pipelines:
11+
{{- if .Values.telemetry.metrics.enabled }}
12+
metrics:
13+
exporters: [otlp]
14+
{{- end }}
15+
16+
{{- if .Values.telemetry.traces.enabled }}
17+
traces:
18+
exporters: [otlp]
19+
{{- end }}
20+
{{- end }}

0 commit comments

Comments
 (0)