Skip to content

Commit ee2d978

Browse files
committed
Wire bundled otel-collector to monoscope via in-cluster agent
- monoscope-k8s/values-agent.yaml: enable ClusterIP service for the daemonset (internalTrafficPolicy: Local) so other in-cluster collectors can forward OTLP to a stable DNS name; drop the explicit k8s_attributes block in favour of the chart's preset (richer metadata, per-node filtering); add resources block so GOMEMLIMIT activates. - monoscope-k8s/values-cluster.yaml: drop the explicit k8s_attributes block (same reason); add resources block. - monoscope-k8s/otel-demo-overlay.yaml: minimal additive overlay (mode: deployment + one otlp/monoscope-agent forward exporter). No secrets, no x-api-key — auth lives entirely in monoscope-agent. Logs intentionally NOT forwarded here to avoid double-counting filelog. - Makefile: add k8s-apply-monoscope, k8s-apply-otel-demo-overlay, k8s-delete-monoscope targets.
1 parent 0d49bdf commit ee2d978

4 files changed

Lines changed: 141 additions & 21 deletions

File tree

Makefile

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,59 @@ endif
255255
.PHONY: build-react-native-android
256256
build-react-native-android:
257257
$(DOCKER_CMD) build -f src/react-native-app/android.Dockerfile --platform=linux/amd64 --output=. src/react-native-app
258+
259+
# --- Monoscope Kubernetes deployment ---------------------------------------
260+
# Apply the Monoscope OTel collector Helm releases (DaemonSet agent + cluster
261+
# Deployment) defined in monoscope-k8s/. The MONOSCOPE_API_KEY must be set in
262+
# the environment — it's stored in a k8s Secret, never written to disk.
263+
#
264+
# Example:
265+
# MONOSCOPE_API_KEY=xxx make k8s-apply-monoscope
266+
267+
K8S_NAMESPACE ?= default
268+
269+
.PHONY: k8s-apply-monoscope
270+
k8s-apply-monoscope:
271+
ifndef MONOSCOPE_API_KEY
272+
$(error MONOSCOPE_API_KEY is not set. Export it or pass MONOSCOPE_API_KEY=... to make)
273+
endif
274+
@echo "→ Adding/updating open-telemetry helm repo"
275+
@helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts >/dev/null 2>&1 || true
276+
@helm repo update open-telemetry >/dev/null
277+
@echo "→ Upserting monoscope-secrets in namespace $(K8S_NAMESPACE)"
278+
@kubectl create secret generic monoscope-secrets \
279+
--namespace $(K8S_NAMESPACE) \
280+
--from-literal=api-key='$(MONOSCOPE_API_KEY)' \
281+
--dry-run=client -o yaml | kubectl apply -f -
282+
@echo "→ Installing/upgrading agent (DaemonSet)"
283+
helm upgrade --install monoscope-agent open-telemetry/opentelemetry-collector \
284+
--namespace $(K8S_NAMESPACE) --values monoscope-k8s/values-agent.yaml
285+
@echo "→ Installing/upgrading cluster collector (Deployment)"
286+
helm upgrade --install monoscope-cluster open-telemetry/opentelemetry-collector \
287+
--namespace $(K8S_NAMESPACE) --values monoscope-k8s/values-cluster.yaml
288+
@echo ""
289+
@echo "Monoscope collectors deployed. Verify with:"
290+
@echo " kubectl get pods -l 'app.kubernetes.io/instance in (monoscope-agent,monoscope-cluster)'"
291+
@echo " monoscope events search 'resource.k8s.cluster.uid != \"\"' --since 5m --limit 1"
292+
293+
.PHONY: k8s-delete-monoscope
294+
k8s-delete-monoscope:
295+
-helm uninstall monoscope-agent --namespace $(K8S_NAMESPACE)
296+
-helm uninstall monoscope-cluster --namespace $(K8S_NAMESPACE)
297+
-kubectl delete secret monoscope-secrets --namespace $(K8S_NAMESPACE)
298+
299+
# Patch the otel-demo helm release so its bundled otel-collector fans
300+
# traces/metrics/logs out to monoscope alongside the in-cluster sinks.
301+
# Requires the monoscope-secrets secret (run `make k8s-apply-monoscope` first).
302+
.PHONY: k8s-apply-otel-demo-overlay
303+
k8s-apply-otel-demo-overlay:
304+
@helm get values otel-demo --namespace $(K8S_NAMESPACE) >/dev/null 2>&1 || \
305+
(echo "otel-demo release not found in $(K8S_NAMESPACE); install it first" && exit 1)
306+
@kubectl get secret monoscope-secrets --namespace $(K8S_NAMESPACE) >/dev/null 2>&1 || \
307+
(echo "monoscope-secrets not found; run 'make k8s-apply-monoscope' first" && exit 1)
308+
@echo "Note: --reset-values clears any stale monoscope-related values"
309+
@echo "from prior overlay revisions; the chart's vanilla defaults plus"
310+
@echo "monoscope-k8s/otel-demo-overlay.yaml become the new state."
311+
helm upgrade otel-demo open-telemetry/opentelemetry-demo \
312+
--namespace $(K8S_NAMESPACE) --reset-values \
313+
--values monoscope-k8s/otel-demo-overlay.yaml
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Overlay applied on top of the otel-demo chart values to fan the bundled
2+
# otel-collector's traces / metrics / logs out to the in-cluster
3+
# monoscope-agent collector — which is the component that holds the API
4+
# key secret and forwards to monoscope.tech. The bundled collector itself
5+
# stays vanilla: no secrets, no x-api-key, no auth concerns.
6+
#
7+
# Apply:
8+
# helm upgrade otel-demo open-telemetry/opentelemetry-demo \
9+
# --reset-values --values monoscope-k8s/otel-demo-overlay.yaml
10+
#
11+
# (--reset-values clears any previous user-supplied values so the bundled
12+
# collector returns to chart defaults plus only what's added here.)
13+
14+
opentelemetry-collector:
15+
# Run the bundled collector as a singleton Deployment instead of the chart's
16+
# default DaemonSet. The chart-default daemonset binds host ports (jaeger
17+
# receivers on 6831/14250/14268) that would collide with the monoscope-agent
18+
# daemonset. A singleton has no host-level needs for this demo.
19+
mode: deployment
20+
21+
config:
22+
exporters:
23+
# In-cluster forward to the monoscope-agent DaemonSet. The agent has
24+
# internalTrafficPolicy: Local, so OTLP requests stay on-node when
25+
# possible. The agent attaches x-api-key and exports to monoscope.tech.
26+
otlp/monoscope-agent:
27+
endpoint: monoscope-agent-opentelemetry-collector.default.svc.cluster.local:4317
28+
tls:
29+
insecure: true
30+
31+
service:
32+
pipelines:
33+
# Append otlp/monoscope-agent to each pipeline's existing exporters.
34+
# The chart merges receivers/processors but replaces pipeline arrays,
35+
# so we re-list the chart-default exporters here verbatim. If the
36+
# chart updates its defaults, this list must be re-synced (check
37+
# `helm show values open-telemetry/opentelemetry-demo`).
38+
traces:
39+
exporters: [otlp/jaeger, debug, spanmetrics, otlp/monoscope-agent]
40+
metrics:
41+
exporters: [otlphttp/prometheus, debug, otlp/monoscope-agent]
42+
# Logs intentionally NOT forwarded to monoscope-agent here — the agent
43+
# already captures every container's stdout via filelog from
44+
# /var/log/pods. Forwarding OTLP logs too would double-count any app
45+
# that uses both stdout and the OTel logger SDK (e.g. cart).
46+
logs:
47+
exporters: [opensearch, debug]

monoscope-k8s/values-agent.yaml

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,37 @@
11
mode: daemonset
22

3+
# Daemonset mode skips a ClusterIP Service by default (each node runs its own
4+
# pod). Enable it so other in-cluster collectors / apps can forward OTLP to a
5+
# stable DNS name. internalTrafficPolicy: Local keeps requests on the same
6+
# node when possible (saves cross-node hops for app-to-agent traffic).
7+
service:
8+
enabled: true
9+
internalTrafficPolicy: Local
10+
311
image:
412
repository: ghcr.io/open-telemetry/opentelemetry-collector-releases/opentelemetry-collector-k8s
513
tag: "0.149.0"
614

15+
# Pod-level limits — required so the chart's GOMEMLIMIT helper activates.
16+
# Without limits.memory, GOMEMLIMIT is silently disabled and the Go runtime
17+
# can spike past memory_limiter under burst load. Tune for your workload.
18+
resources:
19+
requests:
20+
cpu: 100m
21+
memory: 256Mi
22+
limits:
23+
memory: 512Mi
24+
725
presets:
826
logsCollection:
927
enabled: true
1028
kubeletMetrics:
1129
enabled: true
1230
kubernetesAttributes:
13-
enabled: true
31+
enabled: true # Provides RBAC + a rich metadata extractor (workload kinds,
32+
# container.image.*, k8s.cluster.uid, service.* from annotations).
33+
# Pipelines reference it as `k8sattributes` (the chart still uses
34+
# the deprecated alias internally — known chart noise, harmless).
1435

1536
extraEnvs:
1637
- name: MONOSCOPE_API_KEY
@@ -38,17 +59,6 @@ config:
3859
check_interval: 1s
3960
limit_mib: 4000
4061
spike_limit_mib: 800
41-
k8s_attributes:
42-
auth_type: serviceAccount
43-
passthrough: false
44-
extract:
45-
metadata:
46-
- k8s.pod.name
47-
- k8s.pod.uid
48-
- k8s.deployment.name
49-
- k8s.namespace.name
50-
- k8s.node.name
51-
- k8s.container.name
5262
resource:
5363
attributes:
5464
- key: x-api-key
@@ -66,13 +76,13 @@ config:
6676
pipelines:
6777
traces:
6878
receivers: [otlp]
69-
processors: [k8s_attributes, memory_limiter, batch, resource]
79+
processors: [k8sattributes, memory_limiter, batch, resource]
7080
exporters: [otlp_grpc]
7181
metrics:
7282
receivers: [otlp, kubeletstats]
73-
processors: [k8s_attributes, memory_limiter, batch, resource]
83+
processors: [k8sattributes, memory_limiter, batch, resource]
7484
exporters: [otlp_grpc]
7585
logs:
7686
receivers: [otlp, filelog]
77-
processors: [k8s_attributes, memory_limiter, batch, resource]
87+
processors: [k8sattributes, memory_limiter, batch, resource]
7888
exporters: [otlp_grpc]

monoscope-k8s/values-cluster.yaml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
mode: deployment
2+
# Must stay 1 — k8s_events and k8s_cluster don't leader-elect, so >1 replica
3+
# produces duplicate events and cluster metrics.
24
replicaCount: 1
35

46
image:
57
repository: ghcr.io/open-telemetry/opentelemetry-collector-releases/opentelemetry-collector-k8s
68
tag: "0.149.0"
79

10+
# See agent values for the GOMEMLIMIT linkage.
11+
resources:
12+
requests:
13+
cpu: 50m
14+
memory: 128Mi
15+
limits:
16+
memory: 256Mi
17+
818
presets:
919
clusterMetrics:
1020
enabled: true
1121
kubernetesEvents:
1222
enabled: true
1323
kubernetesAttributes:
14-
enabled: true
24+
enabled: true # See agent values for the rationale.
1525

1626
extraEnvs:
1727
- name: MONOSCOPE_API_KEY
@@ -37,9 +47,6 @@ config:
3747
check_interval: 1s
3848
limit_mib: 1000
3949
spike_limit_mib: 200
40-
k8s_attributes:
41-
auth_type: serviceAccount
42-
passthrough: false
4350
resource:
4451
attributes:
4552
- key: x-api-key
@@ -57,9 +64,9 @@ config:
5764
pipelines:
5865
metrics:
5966
receivers: [k8s_cluster]
60-
processors: [k8s_attributes, memory_limiter, batch, resource]
67+
processors: [k8sattributes, memory_limiter, batch, resource]
6168
exporters: [otlp_grpc]
6269
logs:
6370
receivers: [k8s_events]
64-
processors: [k8s_attributes, memory_limiter, batch, resource]
71+
processors: [k8sattributes, memory_limiter, batch, resource]
6572
exporters: [otlp_grpc]

0 commit comments

Comments
 (0)