Skip to content

Commit d13a098

Browse files
authored
feat: support custom otelcol config (#108)
For issue: #78
1 parent 2161d81 commit d13a098

File tree

7 files changed

+796
-2
lines changed

7 files changed

+796
-2
lines changed

.changeset/light-emus-attack.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"helm-charts": patch
3+
---
4+
5+
feat: support custom otelcol config
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{{- if and .Values.otel.enabled .Values.otel.customConfig }}
2+
apiVersion: v1
3+
kind: ConfigMap
4+
metadata:
5+
name: {{ include "hdx-oss.fullname" . }}-otel-custom-config
6+
labels:
7+
{{- include "hdx-oss.labels" . | nindent 4 }}
8+
app: otel-collector
9+
data:
10+
custom.config.yaml: |
11+
{{ .Values.otel.customConfig | indent 4 }}
12+
{{- end }}

charts/hdx-oss-v2/templates/otel-collector-deployment.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ spec:
3636
imagePullSecrets:
3737
{{- toYaml .Values.global.imagePullSecrets | nindent 8 }}
3838
{{- end }}
39+
{{- if .Values.otel.customConfig }}
40+
volumes:
41+
- name: custom-config
42+
configMap:
43+
name: {{ include "hdx-oss.fullname" . }}-otel-custom-config
44+
{{- end }}
3945
containers:
4046
- name: otel-collector
4147
image: "{{ .Values.otel.image.repository }}:{{ .Values.otel.image.tag | default .Chart.AppVersion }}"
@@ -94,9 +100,20 @@ spec:
94100
value: {{ .Values.otel.clickhouseUser | default .Values.clickhouse.config.users.otelUserName }}
95101
- name: CLICKHOUSE_PASSWORD
96102
value: {{ .Values.otel.clickhousePassword | default .Values.clickhouse.config.users.otelUserPassword }}
103+
{{- if .Values.otel.customConfig }}
104+
- name: CUSTOM_OTELCOL_CONFIG_FILE
105+
value: /etc/otelcol-contrib/custom.config.yaml
106+
{{- end }}
97107
{{- with .Values.otel.env }}
98108
{{- toYaml . | nindent 12 }}
99109
{{- end }}
110+
{{- if .Values.otel.customConfig }}
111+
volumeMounts:
112+
- name: custom-config
113+
mountPath: /etc/otelcol-contrib/custom.config.yaml
114+
subPath: custom.config.yaml
115+
readOnly: true
116+
{{- end }}
100117
---
101118
apiVersion: v1
102119
kind: Service

charts/hdx-oss-v2/tests/configmap_test.yaml renamed to charts/hdx-oss-v2/tests/app-configmap_test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
suite: Test ConfigMap
1+
suite: Test App ConfigMap
22
templates:
33
- configmaps/app-configmap.yaml
44
tests:
@@ -118,7 +118,7 @@ tests:
118118
apiPort: 8000
119119
appPort: 3000
120120
appUrl: "http://localhost"
121-
frontendUrl: "{{ if eq .Values.env \"production\" }}https://prod.example.com{{ else }}{{ .Values.hyperdx.appUrl }}:{{ .Values.hyperdx.appPort }}{{ end }}"
121+
frontendUrl: '{{ if eq .Values.env "production" }}https://prod.example.com{{ else }}{{ .Values.hyperdx.appUrl }}:{{ .Values.hyperdx.appPort }}{{ end }}'
122122
env: "development"
123123
mongodb:
124124
port: 27017
Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
suite: Test OTEL Collector ConfigMap
2+
templates:
3+
- configmaps/otel-collector-configmap.yaml
4+
tests:
5+
- it: should not render when otel is disabled
6+
set:
7+
otel:
8+
enabled: false
9+
customConfig: |
10+
receivers:
11+
otlp:
12+
protocols:
13+
grpc:
14+
endpoint: 0.0.0.0:4317
15+
asserts:
16+
- hasDocuments:
17+
count: 0
18+
19+
- it: should not render when customConfig is not provided
20+
set:
21+
otel:
22+
enabled: true
23+
asserts:
24+
- hasDocuments:
25+
count: 0
26+
27+
- it: should render when both enabled and customConfig are set
28+
set:
29+
otel:
30+
enabled: true
31+
customConfig: |
32+
receivers:
33+
otlp:
34+
protocols:
35+
grpc:
36+
endpoint: 0.0.0.0:4317
37+
http:
38+
endpoint: 0.0.0.0:4318
39+
release:
40+
name: my-release
41+
asserts:
42+
- hasDocuments:
43+
count: 1
44+
- isKind:
45+
of: ConfigMap
46+
- equal:
47+
path: metadata.name
48+
value: my-release-hdx-oss-v2-otel-custom-config
49+
- matchRegex:
50+
path: data["custom.config.yaml"]
51+
pattern: "receivers:"
52+
- matchRegex:
53+
path: data["custom.config.yaml"]
54+
pattern: "endpoint: 0.0.0.0:4317"
55+
- matchRegex:
56+
path: data["custom.config.yaml"]
57+
pattern: "endpoint: 0.0.0.0:4318"
58+
59+
- it: should include proper labels
60+
set:
61+
otel:
62+
enabled: true
63+
customConfig: |
64+
test: config
65+
release:
66+
name: test-release
67+
chart:
68+
version: 1.0.0
69+
asserts:
70+
- equal:
71+
path: metadata.labels.app
72+
value: otel-collector
73+
- matchRegex:
74+
path: metadata.labels["helm.sh/chart"]
75+
pattern: "hdx-oss-v2-"
76+
- equal:
77+
path: metadata.labels["app.kubernetes.io/name"]
78+
value: hdx-oss-v2
79+
- equal:
80+
path: metadata.labels["app.kubernetes.io/instance"]
81+
value: test-release
82+
83+
- it: should handle multi-line config with proper indentation
84+
set:
85+
otel:
86+
enabled: true
87+
customConfig: |
88+
receivers:
89+
otlp:
90+
protocols:
91+
grpc:
92+
endpoint: 0.0.0.0:4317
93+
keepalive:
94+
server_parameters:
95+
max_connection_idle: 30s
96+
max_connection_age: 60s
97+
processors:
98+
batch:
99+
timeout: 10s
100+
send_batch_size: 1024
101+
memory_limiter:
102+
limit_mib: 512
103+
exporters:
104+
logging:
105+
loglevel: debug
106+
service:
107+
pipelines:
108+
traces:
109+
receivers: [otlp]
110+
processors: [memory_limiter, batch]
111+
exporters: [logging]
112+
asserts:
113+
- matchRegex:
114+
path: data["custom.config.yaml"]
115+
pattern: "keepalive:"
116+
- matchRegex:
117+
path: data["custom.config.yaml"]
118+
pattern: "server_parameters:"
119+
- matchRegex:
120+
path: data["custom.config.yaml"]
121+
pattern: "max_connection_idle: 30s"
122+
- matchRegex:
123+
path: data["custom.config.yaml"]
124+
pattern: "memory_limiter:"
125+
- matchRegex:
126+
path: data["custom.config.yaml"]
127+
pattern: "limit_mib: 512"
128+
- matchRegex:
129+
path: data["custom.config.yaml"]
130+
pattern: "pipelines:"
131+
- matchRegex:
132+
path: data["custom.config.yaml"]
133+
pattern: "processors: \\[memory_limiter, batch\\]"
134+
135+
- it: should preserve environment variable references
136+
set:
137+
otel:
138+
enabled: true
139+
customConfig: |
140+
receivers:
141+
otlp:
142+
protocols:
143+
grpc:
144+
endpoint: ${OTEL_GRPC_ENDPOINT:-0.0.0.0:4317}
145+
exporters:
146+
clickhouse:
147+
endpoint: ${CLICKHOUSE_ENDPOINT}
148+
database: ${HYPERDX_OTEL_EXPORTER_CLICKHOUSE_DATABASE}
149+
username: ${CLICKHOUSE_USER}
150+
password: ${CLICKHOUSE_PASSWORD}
151+
asserts:
152+
- matchRegex:
153+
path: data["custom.config.yaml"]
154+
pattern: "\\$\\{OTEL_GRPC_ENDPOINT:-0.0.0.0:4317\\}"
155+
- matchRegex:
156+
path: data["custom.config.yaml"]
157+
pattern: "\\$\\{CLICKHOUSE_ENDPOINT\\}"
158+
- matchRegex:
159+
path: data["custom.config.yaml"]
160+
pattern: "\\$\\{HYPERDX_OTEL_EXPORTER_CLICKHOUSE_DATABASE\\}"
161+
- matchRegex:
162+
path: data["custom.config.yaml"]
163+
pattern: "\\$\\{CLICKHOUSE_USER\\}"
164+
- matchRegex:
165+
path: data["custom.config.yaml"]
166+
pattern: "\\$\\{CLICKHOUSE_PASSWORD\\}"
167+
168+
- it: should handle empty customConfig string
169+
set:
170+
otel:
171+
enabled: true
172+
customConfig: ""
173+
asserts:
174+
- hasDocuments:
175+
count: 0
176+
177+
- it: should render with minimal config
178+
set:
179+
otel:
180+
enabled: true
181+
customConfig: |
182+
test: minimal
183+
release:
184+
name: minimal-test
185+
asserts:
186+
- hasDocuments:
187+
count: 1
188+
- equal:
189+
path: metadata.name
190+
value: minimal-test-hdx-oss-v2-otel-custom-config
191+
- matchRegex:
192+
path: data["custom.config.yaml"]
193+
pattern: "test: minimal"
194+
195+
- it: should handle config with special characters
196+
set:
197+
otel:
198+
enabled: true
199+
customConfig: |
200+
receivers:
201+
prometheus:
202+
config:
203+
scrape_configs:
204+
- job_name: 'otel-collector'
205+
metrics_path: /metrics
206+
static_configs:
207+
- targets: ['localhost:8888']
208+
labels:
209+
env: "prod-us-west-2"
210+
cluster: "k8s-cluster-1"
211+
asserts:
212+
- matchRegex:
213+
path: data["custom.config.yaml"]
214+
pattern: "job_name: 'otel-collector'"
215+
- matchRegex:
216+
path: data["custom.config.yaml"]
217+
pattern: "metrics_path: /metrics"
218+
- matchRegex:
219+
path: data["custom.config.yaml"]
220+
pattern: "targets: \\['localhost:8888'\\]"
221+
- matchRegex:
222+
path: data["custom.config.yaml"]
223+
pattern: "env: \"prod-us-west-2\""
224+
- matchRegex:
225+
path: data["custom.config.yaml"]
226+
pattern: "cluster: \"k8s-cluster-1\""
227+
228+
- it: should handle config with yaml anchors and references
229+
set:
230+
otel:
231+
enabled: true
232+
customConfig: |
233+
extensions:
234+
health_check:
235+
endpoint: 0.0.0.0:13133
236+
237+
receivers:
238+
otlp: &otlp-receiver
239+
protocols:
240+
grpc:
241+
endpoint: 0.0.0.0:4317
242+
http:
243+
endpoint: 0.0.0.0:4318
244+
245+
otlp/secondary:
246+
<<: *otlp-receiver
247+
protocols:
248+
grpc:
249+
endpoint: 0.0.0.0:14317
250+
asserts:
251+
- matchRegex:
252+
path: data["custom.config.yaml"]
253+
pattern: "otlp: &otlp-receiver"
254+
- matchRegex:
255+
path: data["custom.config.yaml"]
256+
pattern: "<<: \\*otlp-receiver"
257+
- matchRegex:
258+
path: data["custom.config.yaml"]
259+
pattern: "endpoint: 0.0.0.0:14317"

0 commit comments

Comments
 (0)