From 28930fcaf34fb28f7b97db3bbb8291ed6d924fa6 Mon Sep 17 00:00:00 2001 From: Lucas Barros Date: Thu, 12 Nov 2026 21:08:45 -0300 Subject: [PATCH] fix(helm): disable tracing when otel.tracing.enabled is false The chart passed otel.tracing.enabled as OTEL_TRACING_ENABLED, which the server never reads; it reads OTEL_SDK_DISABLED. With the default values tracing stayed on and the gRPC exporter kept dialing host.docker.internal:4317, logging export timeouts. Set OTEL_SDK_DISABLED from the value and only pass the exporter settings when tracing is on. Also drop the env vars nothing reads: OTEL_EXPORTER_OTLP_TRACES_TIMEOUT (the exporter timeout is fixed in code), PROMETHEUS_USERNAME, PROMETHEUS_PASSWORD, GRAFANA_URL, GRAFANA_API_KEY and KAGENT_NAMESPACE, with their values and README entries. Fixes #92 Signed-off-by: Lucas Barros --- DEVELOPMENT.md | 2 - README.md | 3 -- helm/kagent-tools/templates/deployment.yaml | 21 ++------ helm/kagent-tools/tests/deployment_test.yaml | 55 ++++++++++++++++++++ helm/kagent-tools/values.yaml | 7 +-- 5 files changed, 60 insertions(+), 28 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index c2ab987..4ab8b27 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -298,8 +298,6 @@ The application respects these environment variables: - `KUBECONFIG` - Kubernetes configuration file path - `PROMETHEUS_URL` - Prometheus server URL -- `GRAFANA_URL` - Grafana server URL -- `GRAFANA_API_KEY` - Grafana API authentication key - `LOG_LEVEL` - Logging level (debug, info, warn, error); unset or invalid values fall back to info ### Configuration Files diff --git a/README.md b/README.md index 1ad9d66..791c703 100644 --- a/README.md +++ b/README.md @@ -226,7 +226,6 @@ Tools respect existing authentication and configuration: - Kubernetes tools use the default kubeconfig or `KUBECONFIG` environment variable - Helm tools use Helm's default configuration - Prometheus tools accept custom Prometheus server URLs -- Grafana tools support API key and basic authentication ### Command Execution The tools use a common `runCommand` function that: @@ -263,8 +262,6 @@ This Go implementation provides feature parity with the original Python tools wh Tools can be configured through environment variables: - `KUBECONFIG`: Kubernetes configuration file path - `PROMETHEUS_URL`: Default Prometheus server URL -- `GRAFANA_URL`: Default Grafana server URL -- `GRAFANA_API_KEY`: Default Grafana API key ## Observability diff --git a/helm/kagent-tools/templates/deployment.yaml b/helm/kagent-tools/templates/deployment.yaml index 5a81ca9..bef181b 100644 --- a/helm/kagent-tools/templates/deployment.yaml +++ b/helm/kagent-tools/templates/deployment.yaml @@ -70,37 +70,24 @@ spec: resources: {{- toYaml .Values.tools.resources | nindent 12 }} env: - - name: KAGENT_NAMESPACE - valueFrom: - fieldRef: - apiVersion: v1 - fieldPath: metadata.namespace - name: OPENAI_API_KEY valueFrom: secretKeyRef: name: {{ include "kagent-tools.fullname" . }}-openai key: OPENAI_API_KEY optional: true - - name: OTEL_TRACING_ENABLED - value: {{ .Values.otel.tracing.enabled | quote }} + - name: OTEL_SDK_DISABLED + value: {{ not .Values.otel.tracing.enabled | quote }} + {{- if .Values.otel.tracing.enabled }} - name: OTEL_EXPORTER_OTLP_ENDPOINT value: {{ .Values.otel.tracing.exporter.otlp.endpoint | quote }} - - name: OTEL_EXPORTER_OTLP_TRACES_TIMEOUT - value: {{ .Values.otel.tracing.exporter.otlp.timeout | quote }} - name: OTEL_EXPORTER_OTLP_TRACES_INSECURE value: {{ .Values.otel.tracing.exporter.otlp.insecure | quote }} + {{- end }} - name: TOKEN_PASSTHROUGH value: {{ (index .Values.tools "k8s" | default dict).tokenPassthrough | default false | quote }} - name: PROMETHEUS_URL value: {{ .Values.tools.prometheus.url | quote }} - - name: PROMETHEUS_USERNAME - value: {{ .Values.tools.prometheus.username | quote }} - - name: PROMETHEUS_PASSWORD - value: {{ .Values.tools.prometheus.password | quote }} - - name: GRAFANA_URL - value: {{ .Values.tools.grafana.url | quote }} - - name: GRAFANA_API_KEY - value: {{ .Values.tools.grafana.apiKey | quote }} {{- with .Values.tools.env }} {{- toYaml . | nindent 12 }} {{- end }} diff --git a/helm/kagent-tools/tests/deployment_test.yaml b/helm/kagent-tools/tests/deployment_test.yaml index 84bdaae..04d4203 100644 --- a/helm/kagent-tools/tests/deployment_test.yaml +++ b/helm/kagent-tools/tests/deployment_test.yaml @@ -173,3 +173,58 @@ tests: value: app.kubernetes.io/name: RELEASE-NAME app.kubernetes.io/instance: RELEASE-NAME + + - it: should disable the OpenTelemetry SDK when tracing is off + template: deployment.yaml + asserts: + - contains: + path: spec.template.spec.containers[0].env + content: + name: OTEL_SDK_DISABLED + value: "true" + - notContains: + path: spec.template.spec.containers[0].env + content: + name: OTEL_EXPORTER_OTLP_ENDPOINT + value: http://host.docker.internal:4317 + any: true + + - it: should export traces to the configured endpoint when tracing is on + template: deployment.yaml + set: + otel: + tracing: + enabled: true + exporter: + otlp: + endpoint: http://otel-collector.observability:4317 + asserts: + - contains: + path: spec.template.spec.containers[0].env + content: + name: OTEL_SDK_DISABLED + value: "false" + - contains: + path: spec.template.spec.containers[0].env + content: + name: OTEL_EXPORTER_OTLP_ENDPOINT + value: http://otel-collector.observability:4317 + + - it: should only set env vars the server reads + template: deployment.yaml + asserts: + - notContains: + path: spec.template.spec.containers[0].env + content: + name: OTEL_TRACING_ENABLED + any: true + - notContains: + path: spec.template.spec.containers[0].env + content: + name: PROMETHEUS_PASSWORD + any: true + - notContains: + path: spec.template.spec.containers[0].env + content: + name: GRAFANA_API_KEY + any: true diff --git a/helm/kagent-tools/values.yaml b/helm/kagent-tools/values.yaml index 45755f3..6842a34 100644 --- a/helm/kagent-tools/values.yaml +++ b/helm/kagent-tools/values.yaml @@ -60,11 +60,6 @@ tools: tokenPassthrough: false prometheus: url: "prometheus.kagent.svc.cluster.local:9090" - username: "" - password: "" - grafana: # kubectl port-forward svc/grafana 3000:3000 - url: "http://grafana.kagent.svc.cluster.local:3000" - apiKey: "" service: type: ClusterIP @@ -142,9 +137,9 @@ rbac: otel: tracing: + # When false, OTEL_SDK_DISABLED=true is set and no spans are exported or printed. enabled: false exporter: otlp: endpoint: http://host.docker.internal:4317 - timeout: 15 insecure: true