Skip to content

Commit 9dc7a42

Browse files
authored
otel: support custom hostPort values for agents (#245)
* otel: support custom `hostPort` values for agents * add unit tests * Add changelog entry * Update `charts/sourcegraph/README.md`
1 parent f901d95 commit 9dc7a42

File tree

6 files changed

+89
-6
lines changed

6 files changed

+89
-6
lines changed

charts/sourcegraph/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Use `**BREAKING**:` to denote a breaking change
77
<!-- START CHANGELOG -->
88

99
## Unreleased
10-
10+
* The default `hostPort`s for OpenTelemetry agent pods deployed by the DaemonSet can now be overridden by setting `openTelemetry.agent.hostPorts` for one or more of `otlpGrpc`, `otlpHttp`, and `zpages`. This allows multiple instances of Sourcegraph to be deployed on a single cluster [#245](https://github.com/sourcegraph/deploy-sourcegraph-helm/pull/245).
1111

1212
## 4.5.0
1313

charts/sourcegraph/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,12 @@ In addition to the documented values, all services also support the following va
189189
| nodeExporter.resources | object | `{"limits":{"cpu":"1","memory":"1Gi"},"requests":{"cpu":".2","memory":"100Mi"}}` | Resource requests & limits for the `node-exporter` container, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/) |
190190
| nodeExporter.serviceAccount.create | bool | `false` | Enable creation of ServiceAccount for `node-exporter` |
191191
| nodeExporter.serviceAccount.name | string | `"node-exporter"` | Name of the ServiceAccount to be created or an existing ServiceAccount |
192+
| openTelemetry.agent.hostPorts | object | `{"otlpGrpc":4317,"otlpHttp":4318,"zpages":55679}` | Resource requests & limits for the `otel-agent` container, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/) |
192193
| openTelemetry.agent.name | string | `"otel-agent"` | Name used by resources. Does not affect service names or PVCs. |
193-
| openTelemetry.agent.resources | object | `{"limits":{"cpu":"500m","memory":"500Mi"},"requests":{"cpu":"100m","memory":"100Mi"}}` | Resource requests & limits for the `otel-agent` container, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/) |
194+
| openTelemetry.agent.resources.limits.cpu | string | `"500m"` | |
195+
| openTelemetry.agent.resources.limits.memory | string | `"500Mi"` | |
196+
| openTelemetry.agent.resources.requests.cpu | string | `"100m"` | |
197+
| openTelemetry.agent.resources.requests.memory | string | `"100Mi"` | |
194198
| openTelemetry.enabled | bool | `true` | |
195199
| openTelemetry.gateway.config.traces.exporters | object | `{}` | Define where traces should be exported to. Read how to configure different backends in the [OpenTelemetry documentation](https://opentelemetry.io/docs/collector/configuration/#exporters) |
196200
| openTelemetry.gateway.config.traces.exportersTlsSecretName | string | `""` | Define the name of a preexisting secret containing TLS certificates for exporters, which will be mounted under "/tls". Read more about TLS configuration of exporters in the [OpenTelemetry Collector documentation](https://github.com/open-telemetry/opentelemetry-collector/blob/main/config/configtls/README.md) |

charts/sourcegraph/templates/_helpers.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ app.kubernetes.io/name: jaeger
146146
fieldRef:
147147
fieldPath: status.hostIP
148148
- name: OTEL_EXPORTER_OTLP_ENDPOINT
149-
value: http://$(OTEL_AGENT_HOST):4317
149+
value: http://$(OTEL_AGENT_HOST):{{ toYaml .Values.openTelemetry.agent.hostPorts.otlpGrpc }}
150150
{{- end }}
151151
{{- end }}
152152

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ spec:
6868
port: 13133
6969
ports:
7070
- containerPort: 55679
71-
hostPort: 55679
71+
hostPort: {{ toYaml .Values.openTelemetry.agent.hostPorts.zpages }}
7272
name: zpages
7373
- containerPort: 4317
74-
hostPort: 4317
74+
hostPort: {{ toYaml .Values.openTelemetry.agent.hostPorts.otlpGrpc }}
7575
name: otlp-grpc
7676
- containerPort: 4318
77-
hostPort: 4318
77+
hostPort: {{ toYaml .Values.openTelemetry.agent.hostPorts.otlpHttp }}
7878
name: otlp-http
7979
volumeMounts:
8080
- name: config
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
suite: otelAgentHostPort
3+
tests:
4+
- it: should use the default host ports when not defined in values
5+
template: otel-collector/otel-agent.DaemonSet.yaml
6+
asserts:
7+
- contains:
8+
path: spec.template.spec.containers[0].ports
9+
content:
10+
containerPort: 55679
11+
hostPort: 55679
12+
name: zpages
13+
- contains:
14+
path: spec.template.spec.containers[0].ports
15+
content:
16+
containerPort: 4317
17+
hostPort: 4317
18+
name: otlp-grpc
19+
- contains:
20+
path: spec.template.spec.containers[0].ports
21+
content:
22+
containerPort: 4318
23+
hostPort: 4318
24+
name: otlp-http
25+
- it: should render the agent endpoint with the default gRPC host port
26+
template: searcher/searcher.StatefulSet.yaml
27+
asserts:
28+
- contains:
29+
path: spec.template.spec.containers[0].env
30+
content:
31+
name: OTEL_EXPORTER_OTLP_ENDPOINT
32+
value: "http://$(OTEL_AGENT_HOST):4317"
33+
- it: should set the host ports when defined in values
34+
template: otel-collector/otel-agent.DaemonSet.yaml
35+
set:
36+
openTelemetry:
37+
agent:
38+
hostPorts:
39+
otlpGrpc: 4319
40+
otlpHttp: 4320
41+
zpages: 55680
42+
asserts:
43+
- contains:
44+
path: spec.template.spec.containers[0].ports
45+
content:
46+
containerPort: 55679
47+
hostPort: 55680
48+
name: zpages
49+
- contains:
50+
path: spec.template.spec.containers[0].ports
51+
content:
52+
containerPort: 4317
53+
hostPort: 4319
54+
name: otlp-grpc
55+
- contains:
56+
path: spec.template.spec.containers[0].ports
57+
content:
58+
containerPort: 4318
59+
hostPort: 4320
60+
name: otlp-http
61+
- it: should render the agent endpoint with the custom gRPC host port
62+
template: searcher/searcher.StatefulSet.yaml
63+
set:
64+
openTelemetry:
65+
agent:
66+
hostPorts:
67+
otlpGrpc: 4319
68+
otlpHttp: 4320
69+
zpages: 55680
70+
asserts:
71+
- contains:
72+
path: spec.template.spec.containers[0].env
73+
content:
74+
name: OTEL_EXPORTER_OTLP_ENDPOINT
75+
value: "http://$(OTEL_AGENT_HOST):4319"

charts/sourcegraph/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,10 @@ openTelemetry:
642642
name: "otel-agent"
643643
# -- Resource requests & limits for the `otel-agent` container,
644644
# learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/)
645+
hostPorts:
646+
otlpGrpc: 4317
647+
otlpHttp: 4318
648+
zpages: 55679
645649
resources:
646650
limits:
647651
cpu: "500m"

0 commit comments

Comments
 (0)