Skip to content

Commit 227d138

Browse files
michaellzcclaude
andauthored
otel-agent: support Deployment kind, routing directly to existing otel-collector (#863)
ref sourcegraph/sourcegraph#12299 ref https://sourcegraph.slack.com/archives/C05MW2TMYAV/p1778179723106999 ## Summary Added `openTelemetry.agent.kind` value (`"DaemonSet"` | `"Deployment"`, default `"DaemonSet"`) for environments where DaemonSets are restricted (e.g. some customer limitation) When `kind: "Deployment"`, the otel-agent DaemonSet is not created and application pods send traces directly to the existing `otel-collector` Deployment via `http://otel-collector:4317` (the pre-existing ClusterIP service with gRPC OTLP on port 4317) ## Test plan kind cluster with below override. tested and it worked ```yml storageClass: create: false name: standard sourcegraph: localDevMode: true image: repository: us-docker.pkg.dev/sourcegraph-images/external defaultTag: docker-images-notest-michaellz_370952_2026-05-08_7.2-48f70aff43d4 #370941_2026-05-07_7.2-2c8911ef83a9 useGlobalTagAsDefault: true openTelemetry: enabled: true agent: kind: Deployment jaeger: enabled: true ``` there's no more `otel-agent` ds: <img width="740" height="92" alt="CleanShot 2026-05-07 at 18 51 42" src="https://github.com/user-attachments/assets/544ee8e1-5353-433e-835a-caecb0286cd4" /> can view the trace in jager: <img width="1400" height="976" alt="CleanShot 2026-05-07 at 18 49 50" src="https://github.com/user-attachments/assets/42de66af-62b4-4ce4-ae27-7a3635d94e1c" /> <img width="1448" height="833" alt="CleanShot 2026-05-07 at 18 49 31" src="https://github.com/user-attachments/assets/d0652be5-13ca-4495-bd0f-3dab7664a4b1" /> --- _Generated by [Claude Code](https://claude.ai/code/session_01K2AnXLduzruntPtUsC7xiA)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 7f6386f commit 227d138

5 files changed

Lines changed: 54 additions & 1 deletion

File tree

charts/sourcegraph/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ In addition to the documented values, all services also support the following va
203203
| openTelemetry.agent.containerSecurityContext.runAsGroup | int | `101` | |
204204
| openTelemetry.agent.containerSecurityContext.runAsUser | int | `100` | |
205205
| openTelemetry.agent.hostPorts | object | `{"grpcOtlp":4317,"httpOtlp":4318,"httpZpages":55679}` | Resource requests & limits for the `otel-agent` container, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/) |
206+
| openTelemetry.agent.kind | string | `"DaemonSet"` | The workload kind for the otel-agent. Valid values are `DaemonSet` and `Deployment`. Use `Deployment` in environments where DaemonSets are restricted (e.g. some managed Kubernetes offerings). When set to `Deployment`, the otel-agent DaemonSet is not created and application pods send traces directly to the existing otel-collector Deployment (otel-collector:4317) instead. |
206207
| openTelemetry.agent.name | string | `"otel-agent"` | Name used by resources. Does not affect service names or PVCs. |
207208
| openTelemetry.agent.resources.limits.cpu | string | `"500m"` | |
208209
| openTelemetry.agent.resources.limits.memory | string | `"500Mi"` | |

charts/sourcegraph/templates/_helpers.tpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ app.kubernetes.io/name: jaeger
169169

170170
{{- define "sourcegraph.openTelemetryEnv" -}}
171171
{{- if .Values.openTelemetry.enabled -}}
172+
{{- if eq (.Values.openTelemetry.agent.kind | default "DaemonSet") "Deployment" -}}
173+
- name: OTEL_EXPORTER_OTLP_ENDPOINT
174+
value: http://otel-collector:4317
175+
{{- else -}}
172176
# OTEL_AGENT_HOST must be defined before OTEL_EXPORTER_OTLP_ENDPOINT to substitute the node IP on which the DaemonSet pod instance runs in the latter variable
173177
- name: OTEL_AGENT_HOST
174178
valueFrom:
@@ -178,6 +182,7 @@ app.kubernetes.io/name: jaeger
178182
value: http://$(OTEL_AGENT_HOST):{{ toYaml .Values.openTelemetry.agent.hostPorts.grpcOtlp }}
179183
{{- end }}
180184
{{- end }}
185+
{{- end }}
181186

182187
{{- define "sourcegraph.databaseAuth" -}}
183188
{{- $top := index . 0 -}}

charts/sourcegraph/templates/otel-collector/otel-agent.DaemonSet.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if .Values.openTelemetry.enabled -}}
1+
{{- if and .Values.openTelemetry.enabled (eq (.Values.openTelemetry.agent.kind | default "DaemonSet") "DaemonSet") -}}
22
apiVersion: apps/v1
33
kind: DaemonSet
44
metadata:
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
suite: otelAgentKind
3+
tests:
4+
- it: should render a DaemonSet by default
5+
template: otel-collector/otel-agent.DaemonSet.yaml
6+
asserts:
7+
- isKind:
8+
of: DaemonSet
9+
- it: should render a DaemonSet when kind is DaemonSet
10+
template: otel-collector/otel-agent.DaemonSet.yaml
11+
set:
12+
openTelemetry:
13+
agent:
14+
kind: "DaemonSet"
15+
asserts:
16+
- isKind:
17+
of: DaemonSet
18+
- it: should not render a DaemonSet when kind is Deployment
19+
template: otel-collector/otel-agent.DaemonSet.yaml
20+
set:
21+
openTelemetry:
22+
agent:
23+
kind: "Deployment"
24+
asserts:
25+
- hasDocuments:
26+
count: 0
27+
- it: should set OTEL_EXPORTER_OTLP_ENDPOINT to otel-collector when kind is Deployment
28+
template: searcher/searcher.StatefulSet.yaml
29+
set:
30+
openTelemetry:
31+
agent:
32+
kind: "Deployment"
33+
asserts:
34+
- contains:
35+
path: spec.template.spec.containers[0].env
36+
content:
37+
name: OTEL_EXPORTER_OTLP_ENDPOINT
38+
value: "http://otel-collector:4317"
39+
- notContains:
40+
path: spec.template.spec.containers[0].env
41+
content:
42+
name: OTEL_AGENT_HOST

charts/sourcegraph/values.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,11 @@ openTelemetry:
658658
agent:
659659
# -- Name used by resources. Does not affect service names or PVCs.
660660
name: "otel-agent"
661+
# -- The workload kind for the otel-agent. Valid values are `DaemonSet` and `Deployment`.
662+
# Use `Deployment` in environments where DaemonSets are restricted (e.g. some managed Kubernetes offerings).
663+
# When set to `Deployment`, the otel-agent DaemonSet is not created and application pods send
664+
# traces directly to the existing otel-collector Deployment (otel-collector:4317) instead.
665+
kind: "DaemonSet"
661666
# -- Resource requests & limits for the `otel-agent` container,
662667
# learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/)
663668
hostPorts:

0 commit comments

Comments
 (0)