From 018603a77894edf6a29bf3e34047bb196b4bb249 Mon Sep 17 00:00:00 2001 From: Marc LeBlanc <7050295+marcleblanc2@users.noreply.github.com> Date: Tue, 24 Nov 2026 17:50:42 -0500 Subject: [PATCH 1/6] otel-collector: label the Service with its app The otel-collector Service had no app label, unlike every other scraped Service, so its metrics had no app and job labels and the dashboard's up{app=~".*otel-collector"} panel and alert had no data. Co-authored-by: Amp Amp-Thread-ID: https://ampcode.com/threads/T-01a1effc-8aa2-756b-b724-e1218ffff085 --- charts/sourcegraph/CHANGELOG.md | 1 + .../templates/otel-collector/otel-collector.Service.yaml | 2 +- charts/sourcegraph/tests/allObjectLabels_test.yaml | 9 +++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/charts/sourcegraph/CHANGELOG.md b/charts/sourcegraph/CHANGELOG.md index 999de7af..6af8d92f 100644 --- a/charts/sourcegraph/CHANGELOG.md +++ b/charts/sourcegraph/CHANGELOG.md @@ -10,6 +10,7 @@ Use `**BREAKING**:` to denote a breaking change - Added `frontend.internalServiceAnnotations` and `frontend.internalServiceLabels` for the `sourcegraph-frontend-internal` Service. That Service no longer renders `frontend.serviceAnnotations` and `frontend.serviceLabels`, which now apply to the `sourcegraph-frontend` Service only, so load balancer annotations or a service mesh label set for the external Service no longer land on the internal one. If you relied on them on the internal Service, set the new values. - The `correct-data-dir-permissions` init containers of `pgsql`, `codeintel-db`, and `codeinsights-db` now run the database's own image instead of `sourcegraph/alpine-3.14`, which was based on an end-of-life Alpine release. The chart no longer pulls `alpine-3.14`, so private registries no longer need to mirror it. `alpine.image` has been removed and is ignored if set; `alpine.containerSecurityContext`, `alpine.resources`, and `codeInsightsDB.init.containerSecurityContext` still apply. +- Fixed the `otel-collector` Service missing the `app` label that every other scraped Service has. Its metrics had no `app` and `job` labels, so the "pods available" panel and alert of the OpenTelemetry Collector dashboard, which query `up{app=~".*otel-collector"}`, had no data. Its metrics now have `app="otel-collector"` and `job="otel-collector"`. - Every object the chart creates now has the `deploy` and `app.kubernetes.io/component` labels. PodDisruptionBudgets get the component of their workload, PriorityClasses get `priority-class`, the StorageClass gets `storage` and keeps `deploy: sourcegraph-storage`, and the `sg-test-connection` Pod gets `test-connection`. `extraResources` get `deploy: sourcegraph` unless they set their own; set `app.kubernetes.io/component` on them yourself. The `jaeger` ConfigMap, Deployment, and Services gain `app.kubernetes.io/instance` and keep `app.kubernetes.io/name: jaeger`, which their selectors use. Labels on these objects can be changed in place; the `jaeger` pod restarts once, because its `checksum/jaeger-config` annotation covers the ConfigMap's labels. - `.labels` is now also rendered on the component's ConfigMaps, Secrets, and PodDisruptionBudget, not only on its workload, so releases that set it gain these labels on upgrade. Added `storageClass.labels` and a `labels` field on each `priorityClasses` entry. - Fixed `redisStore.serviceAccount.annotations` being ignored, so the `redis-store` ServiceAccount was created without them, e.g. without a workload identity annotation. They are now rendered, as on every other ServiceAccount. diff --git a/charts/sourcegraph/templates/otel-collector/otel-collector.Service.yaml b/charts/sourcegraph/templates/otel-collector/otel-collector.Service.yaml index be064d0b..f171a091 100644 --- a/charts/sourcegraph/templates/otel-collector/otel-collector.Service.yaml +++ b/charts/sourcegraph/templates/otel-collector/otel-collector.Service.yaml @@ -9,7 +9,7 @@ metadata: {{- toYaml .Values.openTelemetry.gateway.serviceAnnotations | nindent 4 }} {{- end }} labels: - {{- include "sourcegraph.mergedLabels" (list . .Values.openTelemetry.gateway.serviceLabels (dict "deploy" "sourcegraph" "app.kubernetes.io/component" "otel-collector")) | nindent 4 }} + {{- include "sourcegraph.mergedLabels" (list . (dict "app" "otel-collector") .Values.openTelemetry.gateway.serviceLabels (dict "deploy" "sourcegraph" "app.kubernetes.io/component" "otel-collector")) | nindent 4 }} name: otel-collector spec: ports: diff --git a/charts/sourcegraph/tests/allObjectLabels_test.yaml b/charts/sourcegraph/tests/allObjectLabels_test.yaml index 2321a4ad..1c72351d 100644 --- a/charts/sourcegraph/tests/allObjectLabels_test.yaml +++ b/charts/sourcegraph/tests/allObjectLabels_test.yaml @@ -323,6 +323,15 @@ tests: example.com/project: extra example.com/release: sourcegraph deploy: sourcegraph + +# Prometheus derives the `app` and `job` labels of a Service's metrics from its +# `app` label, and the "pods available" alert queries `up{app=~".*otel-collector"}`. +- it: should label the otel-collector Service with its app, like every other scraped Service + template: otel-collector/otel-collector.Service.yaml + asserts: + - equal: + path: metadata.labels.app + value: otel-collector --- suite: sourcegraph.labels on the objects that replace others release: From c50481ed0e71bb6e4adf0b7eb5c832e062f901ad Mon Sep 17 00:00:00 2001 From: Marc LeBlanc <7050295+marcleblanc2@users.noreply.github.com> Date: Wed, 11 Nov 2026 19:59:02 +0000 Subject: [PATCH 2/6] otel-collector: serve the collector's own metrics on all interfaces The image's logging.yaml, and the ConfigMap the chart renders for custom exporters, left the collector's metrics on 127.0.0.1:8888, where Prometheus cannot scrape them. With the app label the Service gained, up was 0 and the pods available alert fired instead of showing no data. Pass the telemetry readers setting as a second --config to the default command, and add it to the rendered ConfigMap. jaeger.yaml already has it. Amp-Thread-ID: https://ampcode.com/threads/T-c7c725c9-ed68-48e2-9f2d-0b8c31e76050 Co-authored-by: Amp --- charts/sourcegraph/CHANGELOG.md | 2 +- .../templates/_helpers/_otelCollector.tpl | 12 ++++++++++++ .../otel-collector/otel-collector.ConfigMap.yaml | 5 +++++ .../otel-collector/otel-collector.Deployment.yaml | 2 ++ .../sourcegraph/tests/otelCollectorJaeger_test.yaml | 12 +++++++++++- 5 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 charts/sourcegraph/templates/_helpers/_otelCollector.tpl diff --git a/charts/sourcegraph/CHANGELOG.md b/charts/sourcegraph/CHANGELOG.md index 6af8d92f..b77521ab 100644 --- a/charts/sourcegraph/CHANGELOG.md +++ b/charts/sourcegraph/CHANGELOG.md @@ -10,7 +10,7 @@ Use `**BREAKING**:` to denote a breaking change - Added `frontend.internalServiceAnnotations` and `frontend.internalServiceLabels` for the `sourcegraph-frontend-internal` Service. That Service no longer renders `frontend.serviceAnnotations` and `frontend.serviceLabels`, which now apply to the `sourcegraph-frontend` Service only, so load balancer annotations or a service mesh label set for the external Service no longer land on the internal one. If you relied on them on the internal Service, set the new values. - The `correct-data-dir-permissions` init containers of `pgsql`, `codeintel-db`, and `codeinsights-db` now run the database's own image instead of `sourcegraph/alpine-3.14`, which was based on an end-of-life Alpine release. The chart no longer pulls `alpine-3.14`, so private registries no longer need to mirror it. `alpine.image` has been removed and is ignored if set; `alpine.containerSecurityContext`, `alpine.resources`, and `codeInsightsDB.init.containerSecurityContext` still apply. -- Fixed the `otel-collector` Service missing the `app` label that every other scraped Service has. Its metrics had no `app` and `job` labels, so the "pods available" panel and alert of the OpenTelemetry Collector dashboard, which query `up{app=~".*otel-collector"}`, had no data. Its metrics now have `app="otel-collector"` and `job="otel-collector"`. +- Fixed the "pods available" panel and alert of the OpenTelemetry Collector dashboard, which query `up{app=~".*otel-collector"}`, having no data. The `otel-collector` Service was missing the `app` label that every other scraped Service has, so its metrics had no `app` and `job` labels. They now have `app="otel-collector"` and `job="otel-collector"`. The collector also served its own metrics on 127.0.0.1 only, unless `jaeger.enabled` was set, so Prometheus could not scrape them. It now serves them on all interfaces, port 8888: the default command passes the setting as a second `--config` argument, which restarts the `otel-collector` pod once, and the ConfigMap rendered for `openTelemetry.gateway.config.traces.exporters` includes it. The pod does not restart when only that ConfigMap changes, so restart the `otel-collector` Deployment after an upgrade that does not replace its pod. If you set `openTelemetry.gateway.command` with your own configuration file, add `service.telemetry.metrics.readers` to it, as in the chart's `otel-collector` ConfigMap. Until the metrics can be scraped, the alert fires. - Every object the chart creates now has the `deploy` and `app.kubernetes.io/component` labels. PodDisruptionBudgets get the component of their workload, PriorityClasses get `priority-class`, the StorageClass gets `storage` and keeps `deploy: sourcegraph-storage`, and the `sg-test-connection` Pod gets `test-connection`. `extraResources` get `deploy: sourcegraph` unless they set their own; set `app.kubernetes.io/component` on them yourself. The `jaeger` ConfigMap, Deployment, and Services gain `app.kubernetes.io/instance` and keep `app.kubernetes.io/name: jaeger`, which their selectors use. Labels on these objects can be changed in place; the `jaeger` pod restarts once, because its `checksum/jaeger-config` annotation covers the ConfigMap's labels. - `.labels` is now also rendered on the component's ConfigMaps, Secrets, and PodDisruptionBudget, not only on its workload, so releases that set it gain these labels on upgrade. Added `storageClass.labels` and a `labels` field on each `priorityClasses` entry. - Fixed `redisStore.serviceAccount.annotations` being ignored, so the `redis-store` ServiceAccount was created without them, e.g. without a workload identity annotation. They are now rendered, as on every other ServiceAccount. diff --git a/charts/sourcegraph/templates/_helpers/_otelCollector.tpl b/charts/sourcegraph/templates/_helpers/_otelCollector.tpl new file mode 100644 index 00000000..4bc828b6 --- /dev/null +++ b/charts/sourcegraph/templates/_helpers/_otelCollector.tpl @@ -0,0 +1,12 @@ +{{/* +The `service.telemetry.metrics.readers` setting of `otel-collector`, as a YAML +flow sequence. It serves the collector's own metrics on all interfaces, port +8888, where Prometheus scrapes them. The collector defaults to 127.0.0.1, which +other pods cannot reach. Without the type and unit suffixes the metric names are +the ones the bundled dashboard queries, e.g. `otelcol_receiver_accepted_spans`. + +The image's `jaeger.yaml` already has this setting. Its `logging.yaml` does not. +*/}} +{{- define "sourcegraph.otelCollector.metricsReaders" -}} +[{pull: {exporter: {prometheus: {host: "0.0.0.0", port: 8888, without_type_suffix: true, without_units: true}}}}] +{{- end }} diff --git a/charts/sourcegraph/templates/otel-collector/otel-collector.ConfigMap.yaml b/charts/sourcegraph/templates/otel-collector/otel-collector.ConfigMap.yaml index d85f1f53..02bdb4a9 100644 --- a/charts/sourcegraph/templates/otel-collector/otel-collector.ConfigMap.yaml +++ b/charts/sourcegraph/templates/otel-collector/otel-collector.ConfigMap.yaml @@ -34,6 +34,11 @@ data: endpoint: "localhost:55679" service: + telemetry: + metrics: + # Serve the collector's own metrics on all interfaces, for Prometheus to scrape. + # The collector defaults to 127.0.0.1. + readers: {{ include "sourcegraph.otelCollector.metricsReaders" . }} extensions: - health_check - zpages diff --git a/charts/sourcegraph/templates/otel-collector/otel-collector.Deployment.yaml b/charts/sourcegraph/templates/otel-collector/otel-collector.Deployment.yaml index 0805e604..94634e9b 100644 --- a/charts/sourcegraph/templates/otel-collector/otel-collector.Deployment.yaml +++ b/charts/sourcegraph/templates/otel-collector/otel-collector.Deployment.yaml @@ -43,6 +43,8 @@ spec: - "/bin/otelcol-sourcegraph" {{- if and (not .Values.openTelemetry.gateway.config.traces.exporters) (not .Values.jaeger.enabled) }} # default config: enable logging exporter - "--config=/etc/otel-collector/configs/logging.yaml" + # logging.yaml serves the collector's own metrics on 127.0.0.1 only, where Prometheus cannot scrape them. + - {{ printf "--config=yaml:service::telemetry::metrics::readers: %s" (include "sourcegraph.otelCollector.metricsReaders" .) | quote }} {{- else if .Values.jaeger.enabled }} # use bundled config to connect to bundled jaeger - "--config=/etc/otel-collector/configs/jaeger.yaml" {{- else }} # use config defined by customer in values.yaml diff --git a/charts/sourcegraph/tests/otelCollectorJaeger_test.yaml b/charts/sourcegraph/tests/otelCollectorJaeger_test.yaml index a9ae2a3c..fddcbbba 100644 --- a/charts/sourcegraph/tests/otelCollectorJaeger_test.yaml +++ b/charts/sourcegraph/tests/otelCollectorJaeger_test.yaml @@ -4,9 +4,14 @@ tests: - it: should use the logging exporter when Jaeger is disabled and no exporter has been set template: otel-collector/otel-collector.Deployment.yaml asserts: + # The second --config serves the collector's own metrics on all interfaces: logging.yaml + # leaves them on 127.0.0.1, where Prometheus cannot scrape them. - equal: path: spec.template.spec.containers[0].command - value: [ "/bin/otelcol-sourcegraph", "--config=/etc/otel-collector/configs/logging.yaml" ] + value: + - "/bin/otelcol-sourcegraph" + - "--config=/etc/otel-collector/configs/logging.yaml" + - '--config=yaml:service::telemetry::metrics::readers: [{pull: {exporter: {prometheus: {host: "0.0.0.0", port: 8888, without_type_suffix: true, without_units: true}}}}]' - isEmpty: path: spec.template.spec.containers[0].volumeMounts - isEmpty: @@ -68,6 +73,11 @@ tests: path: data["config.yaml"] pattern: "endpoint: otlp.service.com:443" # check if element of config is substituted correctly template: otel-collector/otel-collector.ConfigMap.yaml + - matchRegex: + path: data["config.yaml"] + # the collector's own metrics are served on all interfaces, for Prometheus to scrape + pattern: 'service:\n telemetry:\n metrics:\n(\s*#.*\n)*\s*readers: \[\{pull: \{exporter: \{prometheus: \{host: "0\.0\.0\.0", port: 8888, ' + template: otel-collector/otel-collector.ConfigMap.yaml - it: should fail if a configuration is provided and jaeger is enabled template: otel-collector/otel-collector.ConfigMap.yaml set: From 21e6b1b9a4f2069a90972024d63ebe42b6b4fba0 Mon Sep 17 00:00:00 2001 From: Marc LeBlanc <7050295+marcleblanc2@users.noreply.github.com> Date: Wed, 11 Nov 2026 20:21:55 +0000 Subject: [PATCH 3/6] otel-collector: document what a replacement command needs for its metrics to be scraped openTelemetry.gateway.command replaces the default command, so it does not get the argument that serves the collector's metrics on all interfaces. Amp-Thread-ID: https://ampcode.com/threads/T-c7c725c9-ed68-48e2-9f2d-0b8c31e76050 Co-authored-by: Amp --- charts/sourcegraph/CHANGELOG.md | 2 +- charts/sourcegraph/README.md | 2 +- charts/sourcegraph/values.yaml | 7 +++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/charts/sourcegraph/CHANGELOG.md b/charts/sourcegraph/CHANGELOG.md index b77521ab..91b8267d 100644 --- a/charts/sourcegraph/CHANGELOG.md +++ b/charts/sourcegraph/CHANGELOG.md @@ -10,7 +10,7 @@ Use `**BREAKING**:` to denote a breaking change - Added `frontend.internalServiceAnnotations` and `frontend.internalServiceLabels` for the `sourcegraph-frontend-internal` Service. That Service no longer renders `frontend.serviceAnnotations` and `frontend.serviceLabels`, which now apply to the `sourcegraph-frontend` Service only, so load balancer annotations or a service mesh label set for the external Service no longer land on the internal one. If you relied on them on the internal Service, set the new values. - The `correct-data-dir-permissions` init containers of `pgsql`, `codeintel-db`, and `codeinsights-db` now run the database's own image instead of `sourcegraph/alpine-3.14`, which was based on an end-of-life Alpine release. The chart no longer pulls `alpine-3.14`, so private registries no longer need to mirror it. `alpine.image` has been removed and is ignored if set; `alpine.containerSecurityContext`, `alpine.resources`, and `codeInsightsDB.init.containerSecurityContext` still apply. -- Fixed the "pods available" panel and alert of the OpenTelemetry Collector dashboard, which query `up{app=~".*otel-collector"}`, having no data. The `otel-collector` Service was missing the `app` label that every other scraped Service has, so its metrics had no `app` and `job` labels. They now have `app="otel-collector"` and `job="otel-collector"`. The collector also served its own metrics on 127.0.0.1 only, unless `jaeger.enabled` was set, so Prometheus could not scrape them. It now serves them on all interfaces, port 8888: the default command passes the setting as a second `--config` argument, which restarts the `otel-collector` pod once, and the ConfigMap rendered for `openTelemetry.gateway.config.traces.exporters` includes it. The pod does not restart when only that ConfigMap changes, so restart the `otel-collector` Deployment after an upgrade that does not replace its pod. If you set `openTelemetry.gateway.command` with your own configuration file, add `service.telemetry.metrics.readers` to it, as in the chart's `otel-collector` ConfigMap. Until the metrics can be scraped, the alert fires. +- Fixed the "pods available" panel and alert of the OpenTelemetry Collector dashboard, which query `up{app=~".*otel-collector"}`, having no data. The `otel-collector` Service was missing the `app` label that every other scraped Service has, so its metrics had no `app` and `job` labels. They now have `app="otel-collector"` and `job="otel-collector"`. The collector also served its own metrics on 127.0.0.1 only, unless `jaeger.enabled` was set, so Prometheus could not scrape them. It now serves them on all interfaces, port 8888: the default command passes the setting as a second `--config` argument, which restarts the `otel-collector` pod once, and the ConfigMap rendered for `openTelemetry.gateway.config.traces.exporters` includes it. The pod does not restart when only that ConfigMap changes, so restart the `otel-collector` Deployment after an upgrade that does not replace its pod. A command set in `openTelemetry.gateway.command` replaces the default one, so it does not get the argument. If it runs `/etc/otel-collector/config.yaml` or the image's `jaeger.yaml`, it needs no change. If it runs the image's `logging.yaml`, add the argument `--config=yaml:service::telemetry::metrics::readers: [{pull: {exporter: {prometheus: {host: "0.0.0.0", port: 8888, without_type_suffix: true, without_units: true}}}}]` after its `--config`. If it runs your own configuration file, set `service.telemetry.metrics.readers` to that list in the file. Until the metrics can be scraped, the alert fires. - Every object the chart creates now has the `deploy` and `app.kubernetes.io/component` labels. PodDisruptionBudgets get the component of their workload, PriorityClasses get `priority-class`, the StorageClass gets `storage` and keeps `deploy: sourcegraph-storage`, and the `sg-test-connection` Pod gets `test-connection`. `extraResources` get `deploy: sourcegraph` unless they set their own; set `app.kubernetes.io/component` on them yourself. The `jaeger` ConfigMap, Deployment, and Services gain `app.kubernetes.io/instance` and keep `app.kubernetes.io/name: jaeger`, which their selectors use. Labels on these objects can be changed in place; the `jaeger` pod restarts once, because its `checksum/jaeger-config` annotation covers the ConfigMap's labels. - `.labels` is now also rendered on the component's ConfigMaps, Secrets, and PodDisruptionBudget, not only on its workload, so releases that set it gain these labels on upgrade. Added `storageClass.labels` and a `labels` field on each `priorityClasses` entry. - Fixed `redisStore.serviceAccount.annotations` being ignored, so the `redis-store` ServiceAccount was created without them, e.g. without a workload identity annotation. They are now rendered, as on every other ServiceAccount. diff --git a/charts/sourcegraph/README.md b/charts/sourcegraph/README.md index 3beb012a..116e75a1 100644 --- a/charts/sourcegraph/README.md +++ b/charts/sourcegraph/README.md @@ -401,7 +401,7 @@ In addition to the documented values, all services also support the following va | openTelemetry.agent.serviceAccount.create | bool | `false` | Enable creation of ServiceAccount for `otel-agent` | | openTelemetry.agent.serviceAccount.name | string | `""` | Name of the ServiceAccount to be created or an existing ServiceAccount | | openTelemetry.enabled | bool | `true` | | -| openTelemetry.gateway.command | list | `[]` | Command for the `otel-collector` container, as a list, replacing the chart's `/bin/otelcol-sourcegraph --config=` command, including the `--config` flag the chart selects, e.g. a shell wrapper that exports an exporter API key read from a mounted file. `openTelemetry.gateway.args` is still passed as the arguments. | +| openTelemetry.gateway.command | list | `[]` | Command for the `otel-collector` container, as a list, replacing the chart's `/bin/otelcol-sourcegraph --config=` command, including the `--config` flag the chart selects, e.g. a shell wrapper that exports an exporter API key read from a mounted file. `openTelemetry.gateway.args` is still passed as the arguments. The default command makes the collector serve its own metrics on all interfaces, where Prometheus scrapes them. A command that runs `/etc/otel-collector/config.yaml`, rendered from `config.traces.exporters`, or the image's `jaeger.yaml` does too. A command that runs the image's `logging.yaml` must also pass the second argument of the default command, `--config=yaml:service::telemetry::metrics::readers: [{pull: {exporter: {prometheus: {host: "0.0.0.0", port: 8888, without_type_suffix: true, without_units: true}}}}]`, and your own configuration file must set `service.telemetry.metrics.readers` to that list. Otherwise Prometheus cannot scrape the collector and its "pods available" alert fires. | | 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) | | 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) | | openTelemetry.gateway.config.traces.processors | object | `{}` | Define trace processors. Read how to configure sampling in the [OpenTelemetry documentation](https://docs.sourcegraph.com/admin/observability/opentelemetry#sampling-traces) | diff --git a/charts/sourcegraph/values.yaml b/charts/sourcegraph/values.yaml index dfd5ae7d..2e85ba70 100644 --- a/charts/sourcegraph/values.yaml +++ b/charts/sourcegraph/values.yaml @@ -762,6 +762,13 @@ openTelemetry: # `/bin/otelcol-sourcegraph --config=` command, including the `--config` flag the chart # selects, e.g. a shell wrapper that exports an exporter API key read from a mounted file. # `openTelemetry.gateway.args` is still passed as the arguments. + # The default command makes the collector serve its own metrics on all interfaces, where Prometheus + # scrapes them. A command that runs `/etc/otel-collector/config.yaml`, rendered from + # `config.traces.exporters`, or the image's `jaeger.yaml` does too. A command that runs the image's + # `logging.yaml` must also pass the second argument of the default command, + # `--config=yaml:service::telemetry::metrics::readers: [{pull: {exporter: {prometheus: {host: "0.0.0.0", port: 8888, without_type_suffix: true, without_units: true}}}}]`, + # and your own configuration file must set `service.telemetry.metrics.readers` to that list. + # Otherwise Prometheus cannot scrape the collector and its "pods available" alert fires. command: [] # -- Resource requests & limits for the `otel-collector` container, # learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/) From 7b69e86ac954c845004b8c4e0f2e9477272d2fa9 Mon Sep 17 00:00:00 2001 From: Marc LeBlanc <7050295+marcleblanc2@users.noreply.github.com> Date: Wed, 11 Nov 2026 16:12:15 -0600 Subject: [PATCH 4/6] otel-collector: pass the metrics setting as an argument The setting that serves the collector's own metrics on all interfaces was part of the default command, so a command set in `openTelemetry.gateway.command` did not get it, and Prometheus could not scrape the collector. It is now always the last container argument, after `openTelemetry.gateway.args`, so a replacement command gets it too. Last, so that it is `$0` of a `sh -c` command whose script is the first argument. Amp-Thread-ID: https://ampcode.com/threads/T-01a1cc03-93a7-7445-8f1f-3dd7123272bf Co-authored-by: Amp --- charts/sourcegraph/CHANGELOG.md | 2 +- charts/sourcegraph/README.md | 2 +- .../otel-collector/otel-collector.Deployment.yaml | 14 ++++++++------ charts/sourcegraph/tests/command_test.yaml | 3 ++- .../tests/otelCollectorJaeger_test.yaml | 9 +++++---- charts/sourcegraph/values.yaml | 9 ++------- 6 files changed, 19 insertions(+), 20 deletions(-) diff --git a/charts/sourcegraph/CHANGELOG.md b/charts/sourcegraph/CHANGELOG.md index 91b8267d..4406dc5d 100644 --- a/charts/sourcegraph/CHANGELOG.md +++ b/charts/sourcegraph/CHANGELOG.md @@ -10,7 +10,7 @@ Use `**BREAKING**:` to denote a breaking change - Added `frontend.internalServiceAnnotations` and `frontend.internalServiceLabels` for the `sourcegraph-frontend-internal` Service. That Service no longer renders `frontend.serviceAnnotations` and `frontend.serviceLabels`, which now apply to the `sourcegraph-frontend` Service only, so load balancer annotations or a service mesh label set for the external Service no longer land on the internal one. If you relied on them on the internal Service, set the new values. - The `correct-data-dir-permissions` init containers of `pgsql`, `codeintel-db`, and `codeinsights-db` now run the database's own image instead of `sourcegraph/alpine-3.14`, which was based on an end-of-life Alpine release. The chart no longer pulls `alpine-3.14`, so private registries no longer need to mirror it. `alpine.image` has been removed and is ignored if set; `alpine.containerSecurityContext`, `alpine.resources`, and `codeInsightsDB.init.containerSecurityContext` still apply. -- Fixed the "pods available" panel and alert of the OpenTelemetry Collector dashboard, which query `up{app=~".*otel-collector"}`, having no data. The `otel-collector` Service was missing the `app` label that every other scraped Service has, so its metrics had no `app` and `job` labels. They now have `app="otel-collector"` and `job="otel-collector"`. The collector also served its own metrics on 127.0.0.1 only, unless `jaeger.enabled` was set, so Prometheus could not scrape them. It now serves them on all interfaces, port 8888: the default command passes the setting as a second `--config` argument, which restarts the `otel-collector` pod once, and the ConfigMap rendered for `openTelemetry.gateway.config.traces.exporters` includes it. The pod does not restart when only that ConfigMap changes, so restart the `otel-collector` Deployment after an upgrade that does not replace its pod. A command set in `openTelemetry.gateway.command` replaces the default one, so it does not get the argument. If it runs `/etc/otel-collector/config.yaml` or the image's `jaeger.yaml`, it needs no change. If it runs the image's `logging.yaml`, add the argument `--config=yaml:service::telemetry::metrics::readers: [{pull: {exporter: {prometheus: {host: "0.0.0.0", port: 8888, without_type_suffix: true, without_units: true}}}}]` after its `--config`. If it runs your own configuration file, set `service.telemetry.metrics.readers` to that list in the file. Until the metrics can be scraped, the alert fires. +- Fixed the "pods available" panel and alert of the OpenTelemetry Collector dashboard, which query `up{app=~".*otel-collector"}`, having no data. The `otel-collector` Service was missing the `app` label that every other scraped Service has, so its metrics had no `app` and `job` labels. They now have `app="otel-collector"` and `job="otel-collector"`. The collector also served its own metrics on 127.0.0.1 only, unless `jaeger.enabled` was set, so Prometheus could not scrape them. The chart now always passes the container one argument, after `openTelemetry.gateway.args`, that serves them on all interfaces, port 8888. A command set in `openTelemetry.gateway.command` gets the argument too, so a shell wrapper must pass its arguments on to the collector (`"$@"`). The argument replaces `service.telemetry.metrics.readers` of the configuration files the command loads. - Every object the chart creates now has the `deploy` and `app.kubernetes.io/component` labels. PodDisruptionBudgets get the component of their workload, PriorityClasses get `priority-class`, the StorageClass gets `storage` and keeps `deploy: sourcegraph-storage`, and the `sg-test-connection` Pod gets `test-connection`. `extraResources` get `deploy: sourcegraph` unless they set their own; set `app.kubernetes.io/component` on them yourself. The `jaeger` ConfigMap, Deployment, and Services gain `app.kubernetes.io/instance` and keep `app.kubernetes.io/name: jaeger`, which their selectors use. Labels on these objects can be changed in place; the `jaeger` pod restarts once, because its `checksum/jaeger-config` annotation covers the ConfigMap's labels. - `.labels` is now also rendered on the component's ConfigMaps, Secrets, and PodDisruptionBudget, not only on its workload, so releases that set it gain these labels on upgrade. Added `storageClass.labels` and a `labels` field on each `priorityClasses` entry. - Fixed `redisStore.serviceAccount.annotations` being ignored, so the `redis-store` ServiceAccount was created without them, e.g. without a workload identity annotation. They are now rendered, as on every other ServiceAccount. diff --git a/charts/sourcegraph/README.md b/charts/sourcegraph/README.md index 116e75a1..272630eb 100644 --- a/charts/sourcegraph/README.md +++ b/charts/sourcegraph/README.md @@ -401,7 +401,7 @@ In addition to the documented values, all services also support the following va | openTelemetry.agent.serviceAccount.create | bool | `false` | Enable creation of ServiceAccount for `otel-agent` | | openTelemetry.agent.serviceAccount.name | string | `""` | Name of the ServiceAccount to be created or an existing ServiceAccount | | openTelemetry.enabled | bool | `true` | | -| openTelemetry.gateway.command | list | `[]` | Command for the `otel-collector` container, as a list, replacing the chart's `/bin/otelcol-sourcegraph --config=` command, including the `--config` flag the chart selects, e.g. a shell wrapper that exports an exporter API key read from a mounted file. `openTelemetry.gateway.args` is still passed as the arguments. The default command makes the collector serve its own metrics on all interfaces, where Prometheus scrapes them. A command that runs `/etc/otel-collector/config.yaml`, rendered from `config.traces.exporters`, or the image's `jaeger.yaml` does too. A command that runs the image's `logging.yaml` must also pass the second argument of the default command, `--config=yaml:service::telemetry::metrics::readers: [{pull: {exporter: {prometheus: {host: "0.0.0.0", port: 8888, without_type_suffix: true, without_units: true}}}}]`, and your own configuration file must set `service.telemetry.metrics.readers` to that list. Otherwise Prometheus cannot scrape the collector and its "pods available" alert fires. | +| openTelemetry.gateway.command | list | `[]` | Command for the `otel-collector` container, as a list, replacing the chart's `/bin/otelcol-sourcegraph --config=` command, including the `--config` flag the chart selects, e.g. a shell wrapper that exports an exporter API key read from a mounted file. `openTelemetry.gateway.args` is still passed as the arguments. The chart always passes one argument that makes the collector serve its own metrics on all interfaces, where Prometheus scrapes them, so a shell wrapper must pass its arguments on (`"$@"`). | | 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) | | 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) | | openTelemetry.gateway.config.traces.processors | object | `{}` | Define trace processors. Read how to configure sampling in the [OpenTelemetry documentation](https://docs.sourcegraph.com/admin/observability/opentelemetry#sampling-traces) | diff --git a/charts/sourcegraph/templates/otel-collector/otel-collector.Deployment.yaml b/charts/sourcegraph/templates/otel-collector/otel-collector.Deployment.yaml index 94634e9b..7142131f 100644 --- a/charts/sourcegraph/templates/otel-collector/otel-collector.Deployment.yaml +++ b/charts/sourcegraph/templates/otel-collector/otel-collector.Deployment.yaml @@ -43,18 +43,20 @@ spec: - "/bin/otelcol-sourcegraph" {{- if and (not .Values.openTelemetry.gateway.config.traces.exporters) (not .Values.jaeger.enabled) }} # default config: enable logging exporter - "--config=/etc/otel-collector/configs/logging.yaml" - # logging.yaml serves the collector's own metrics on 127.0.0.1 only, where Prometheus cannot scrape them. - - {{ printf "--config=yaml:service::telemetry::metrics::readers: %s" (include "sourcegraph.otelCollector.metricsReaders" .) | quote }} {{- else if .Values.jaeger.enabled }} # use bundled config to connect to bundled jaeger - "--config=/etc/otel-collector/configs/jaeger.yaml" {{- else }} # use config defined by customer in values.yaml - "--config=/etc/otel-collector/config.yaml" {{- end }} - {{- end -}} - {{- with .Values.openTelemetry.gateway.args }} + {{- end }} args: - {{- toYaml . | nindent 8 }} - {{- end }} + {{- with .Values.openTelemetry.gateway.args }} + {{- toYaml . | nindent 10 }} + {{- end }} + # The image's logging.yaml serves the collector's own metrics on 127.0.0.1 only, where Prometheus cannot + # scrape them. An argument, so that a command set in `openTelemetry.gateway.command` gets it too, and the + # last one, so that it is `$0` of a `sh -c` command whose script is the first argument. + - {{ printf "--config=yaml:service::telemetry::metrics::readers: %s" (include "sourcegraph.otelCollector.metricsReaders" .) | quote }} terminationMessagePolicy: FallbackToLogsOnError env: {{- if .Values.jaeger.enabled }} diff --git a/charts/sourcegraph/tests/command_test.yaml b/charts/sourcegraph/tests/command_test.yaml index 2446952a..7a552971 100644 --- a/charts/sourcegraph/tests/command_test.yaml +++ b/charts/sourcegraph/tests/command_test.yaml @@ -56,7 +56,7 @@ tests: path: spec.template.spec.initContainers[0].command value: ["sh", "-c", "/migrator up"] -- it: should replace the otel-collector command, and keep args, when gateway.command is set +- it: should replace the otel-collector command, and keep args before the chart's own argument, when gateway.command is set template: otel-collector/otel-collector.Deployment.yaml set: openTelemetry.gateway.command: ["/bin/sh", "-c"] @@ -70,3 +70,4 @@ tests: path: spec.template.spec.containers[0].args value: - API_KEY=$(cat /secrets/api-key) /bin/otelcol-sourcegraph --config=/etc/otel-collector/config.yaml + - '--config=yaml:service::telemetry::metrics::readers: [{pull: {exporter: {prometheus: {host: "0.0.0.0", port: 8888, without_type_suffix: true, without_units: true}}}}]' diff --git a/charts/sourcegraph/tests/otelCollectorJaeger_test.yaml b/charts/sourcegraph/tests/otelCollectorJaeger_test.yaml index fddcbbba..e1919a6c 100644 --- a/charts/sourcegraph/tests/otelCollectorJaeger_test.yaml +++ b/charts/sourcegraph/tests/otelCollectorJaeger_test.yaml @@ -4,13 +4,14 @@ tests: - it: should use the logging exporter when Jaeger is disabled and no exporter has been set template: otel-collector/otel-collector.Deployment.yaml asserts: - # The second --config serves the collector's own metrics on all interfaces: logging.yaml - # leaves them on 127.0.0.1, where Prometheus cannot scrape them. - equal: path: spec.template.spec.containers[0].command + value: [ "/bin/otelcol-sourcegraph", "--config=/etc/otel-collector/configs/logging.yaml" ] + # The argument serves the collector's own metrics on all interfaces: logging.yaml + # leaves them on 127.0.0.1, where Prometheus cannot scrape them. + - equal: + path: spec.template.spec.containers[0].args value: - - "/bin/otelcol-sourcegraph" - - "--config=/etc/otel-collector/configs/logging.yaml" - '--config=yaml:service::telemetry::metrics::readers: [{pull: {exporter: {prometheus: {host: "0.0.0.0", port: 8888, without_type_suffix: true, without_units: true}}}}]' - isEmpty: path: spec.template.spec.containers[0].volumeMounts diff --git a/charts/sourcegraph/values.yaml b/charts/sourcegraph/values.yaml index 2e85ba70..4c756caa 100644 --- a/charts/sourcegraph/values.yaml +++ b/charts/sourcegraph/values.yaml @@ -762,13 +762,8 @@ openTelemetry: # `/bin/otelcol-sourcegraph --config=` command, including the `--config` flag the chart # selects, e.g. a shell wrapper that exports an exporter API key read from a mounted file. # `openTelemetry.gateway.args` is still passed as the arguments. - # The default command makes the collector serve its own metrics on all interfaces, where Prometheus - # scrapes them. A command that runs `/etc/otel-collector/config.yaml`, rendered from - # `config.traces.exporters`, or the image's `jaeger.yaml` does too. A command that runs the image's - # `logging.yaml` must also pass the second argument of the default command, - # `--config=yaml:service::telemetry::metrics::readers: [{pull: {exporter: {prometheus: {host: "0.0.0.0", port: 8888, without_type_suffix: true, without_units: true}}}}]`, - # and your own configuration file must set `service.telemetry.metrics.readers` to that list. - # Otherwise Prometheus cannot scrape the collector and its "pods available" alert fires. + # The chart always passes one argument that makes the collector serve its own metrics on all + # interfaces, where Prometheus scrapes them, so a shell wrapper must pass its arguments on (`"$@"`). command: [] # -- Resource requests & limits for the `otel-collector` container, # learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/) From 46450d93c66f265f0572a59973d024f979609b26 Mon Sep 17 00:00:00 2001 From: Marc LeBlanc <7050295+marcleblanc2@users.noreply.github.com> Date: Wed, 11 Nov 2026 16:43:25 -0600 Subject: [PATCH 5/6] otel-collector: restart when its configuration changes The collector does not reload a changed ConfigMap by itself, so a change to openTelemetry.gateway.config.traces took effect only at the pod's next restart. The pod template now has a checksum/otel-collector-config annotation over those values, which are all the ConfigMap's data is rendered from. It is set only when the chart renders the ConfigMap, so the default install does not change. Amp-Thread-ID: https://ampcode.com/threads/T-01a1cc03-93a7-7445-8f1f-3dd7123272bf Co-authored-by: Amp --- charts/sourcegraph/CHANGELOG.md | 1 + .../otel-collector/otel-collector.Deployment.yaml | 4 ++++ .../sourcegraph/tests/otelCollectorJaeger_test.yaml | 11 +++++++++++ 3 files changed, 16 insertions(+) diff --git a/charts/sourcegraph/CHANGELOG.md b/charts/sourcegraph/CHANGELOG.md index 4406dc5d..a1cdae33 100644 --- a/charts/sourcegraph/CHANGELOG.md +++ b/charts/sourcegraph/CHANGELOG.md @@ -16,6 +16,7 @@ Use `**BREAKING**:` to denote a breaking change - Fixed `redisStore.serviceAccount.annotations` being ignored, so the `redis-store` ServiceAccount was created without them, e.g. without a workload identity annotation. They are now rendered, as on every other ServiceAccount. - The `prometheus` pod now restarts when an upgrade changes the chart's `prometheus.yml`, through a `checksum/prometheus-config` pod annotation. Prometheus does not reload a changed ConfigMap by itself, so such a change took effect only at the pod's next restart. The annotation is not set with `prometheus.existingConfig`. - Fixed a label key set both in `sourcegraph.labels` and in a component's `labels`, `podLabels`, `serviceLabels`, or other label value being rendered twice on the same object, which Kustomize and `kubeconform -strict` reject. Each key is now rendered once, with the value that Kubernetes already applied: the later one in the template, so the component's value, and the labels the chart sets itself, such as `deploy` and `app`, win. Objects keep the same labels. +- The `otel-collector` pod now restarts when `openTelemetry.gateway.config.traces` changes, through a `checksum/otel-collector-config` pod annotation. The collector does not reload a changed ConfigMap by itself, so a changed exporter or processor took effect only at the pod's next restart. The annotation is set only with `openTelemetry.gateway.config.traces.exporters`, which is when the chart renders that ConfigMap, so the default install is not affected. - `sourcegraph.labels` and the chart's standard labels (`helm.sh/chart`, `app.kubernetes.io/name`, `app.kubernetes.io/instance`, `app.kubernetes.io/version`, `app.kubernetes.io/managed-by`) are now rendered on every object the chart creates: also on pods, Services, ConfigMaps, Secrets, the Ingress, PodDisruptionBudgets, PriorityClasses, and `extraResources`, so existing releases gain these labels on upgrade. Pods do not get `helm.sh/chart` and `app.kubernetes.io/version`, which change with every chart version and would restart every pod on every upgrade, and they also gain `app.kubernetes.io/component`. The per-pod scratch PersistentVolumeClaim of `preciseCodeIntel` and `syntacticCodeIntel`, created when `storageType` is `pvc`, gets all of these labels, so with that setting those pods restart whenever the chart version changes. Labels that an `extraResources` entry, `serviceLabels`, or `podLabels` set take precedence, except that `podLabels` cannot change a selector label. No object is recreated. Every pod restarts once, on this upgrade. Prometheus copies the labels of a Service or pod to the metrics it scrapes from it, so the bundled Prometheus configuration now drops the five standard labels and the keys of `sourcegraph.labels`. No bundled dashboard or alert queries them. Metrics lose `app_kubernetes_io_managed_by`, which Helm added to every Service, `otel-collector` metrics lose the other standard labels, which its Service already had, and `cadvisor` and `jaeger` metrics, scraped from pods, lose `app_kubernetes_io_name` and `app_kubernetes_io_instance` and gain `app_kubernetes_io_component`. To add a label to the metrics of a Service, set it in `.serviceLabels`, with a key that is not in `sourcegraph.labels`. If you set `prometheus.existingConfig`, add the same `labeldrop` rule after each `__meta_kubernetes_service_label_(.+)` and `__meta_kubernetes_pod_label_(.+)` `labelmap` rule in your `prometheus.yml`, as in the [k3s example](examples/prometheus/prometheus-override-k3s.ConfigMap.yaml), and append the keys of `sourcegraph.labels` to its regex. - Added `storageLabels` on `blobstore`, `codeInsightsDB`, `codeIntelDB`, `pgsql`, `prometheus`, `redisCache`, and `redisStore` to label each component's PersistentVolumeClaim, and `.serviceAccount.labels` to label a component's ServiceAccount and, for `frontend` and `prometheus`, its Role, RoleBinding, ClusterRole, and ClusterRoleBinding. Also added `storageLabels` on `preciseCodeIntel` and `syntacticCodeIntel`, to label the per-pod `/tmp` scratch PersistentVolumeClaim when `storageType` is `pvc`; they default to empty, so no pod restarts. `sourcegraph.labels` and the chart's standard labels (`helm.sh/chart`, `app.kubernetes.io/name`, `app.kubernetes.io/instance`, `app.kubernetes.io/version`, `app.kubernetes.io/managed-by`) are now also rendered on these PersistentVolumeClaims, on every ServiceAccount, and on the `prometheus` RBAC objects, as they already are on every workload and on the `frontend` Role and RoleBinding, so existing releases gain these labels on upgrade. Labels on these objects can be changed in place, so none is recreated. A key set in `sourcegraph.labels` and in one of these values is rendered once, with the component's value, and the labels the chart sets itself win over both, so Kustomize and `kubeconform -strict` accept the output. See [Adopting existing workloads](README.md#adopting-existing-workloads). - Fixed the `jaeger` ServiceAccount failing to render with `jaeger.serviceAccount.create: true`. Its name and annotations were read from a `tracing` value that does not exist, and are now read from `jaeger.serviceAccount`, as the `jaeger` Deployment's `serviceAccountName` already was. diff --git a/charts/sourcegraph/templates/otel-collector/otel-collector.Deployment.yaml b/charts/sourcegraph/templates/otel-collector/otel-collector.Deployment.yaml index 7142131f..675f6e9c 100644 --- a/charts/sourcegraph/templates/otel-collector/otel-collector.Deployment.yaml +++ b/charts/sourcegraph/templates/otel-collector/otel-collector.Deployment.yaml @@ -19,6 +19,10 @@ spec: metadata: annotations: kubectl.kubernetes.io/default-container: otel-collector + {{- if .Values.openTelemetry.gateway.config.traces.exporters }} + {{- /* The collector does not reload a changed ConfigMap by itself. Its data is rendered from these values only. */}} + checksum/otel-collector-config: {{ toJson .Values.openTelemetry.gateway.config.traces | sha256sum }} + {{- end }} {{- if .Values.sourcegraph.podAnnotations }} {{- toYaml .Values.sourcegraph.podAnnotations | nindent 8 }} {{- end }} diff --git a/charts/sourcegraph/tests/otelCollectorJaeger_test.yaml b/charts/sourcegraph/tests/otelCollectorJaeger_test.yaml index e1919a6c..c573f8d0 100644 --- a/charts/sourcegraph/tests/otelCollectorJaeger_test.yaml +++ b/charts/sourcegraph/tests/otelCollectorJaeger_test.yaml @@ -17,6 +17,8 @@ tests: path: spec.template.spec.containers[0].volumeMounts - isEmpty: path: spec.template.spec.volumes + - notExists: # no ConfigMap, so nothing to restart for + path: spec.template.metadata.annotations["checksum/otel-collector-config"] - hasDocuments: count: 0 # ConfigMap is not rendered template: otel-collector/otel-collector.ConfigMap.yaml @@ -33,6 +35,8 @@ tests: path: spec.template.spec.containers[0].volumeMounts - isEmpty: path: spec.template.spec.volumes + - notExists: # no ConfigMap, so nothing to restart for + path: spec.template.metadata.annotations["checksum/otel-collector-config"] - hasDocuments: count: 0 # ConfigMap is not rendered template: otel-collector/otel-collector.ConfigMap.yaml @@ -67,6 +71,13 @@ tests: items: - key: config.yaml path: config.yaml + # The collector does not reload a changed ConfigMap, so the pod restarts when the values it is rendered from change. + - matchRegex: + path: spec.template.metadata.annotations["checksum/otel-collector-config"] + pattern: ^[0-9a-f]{64}$ + - notEqual: # the hash of `null`, which is what a missing value would hash to + path: spec.template.metadata.annotations["checksum/otel-collector-config"] + value: 74234e98afe7498fb5daf1f36ac2d78acc339464f950703b8c019892f982b90b - hasDocuments: count: 1 # ConfigMap is rendered template: otel-collector/otel-collector.ConfigMap.yaml From ae63325fa9e1d03cf6e20ead9160f03278450da1 Mon Sep 17 00:00:00 2001 From: Marc LeBlanc <7050295+marcleblanc2@users.noreply.github.com> Date: Wed, 18 Nov 2026 12:05:24 -0600 Subject: [PATCH 6/6] otel-collector: say how each shell wrapper form passes the metrics argument on With the script as the first of openTelemetry.gateway.args after command: ["/bin/sh", "-c"], the chart's argument is $0 and "$@" is empty, so a wrapper that passes only "$@" drops it and the collector keeps serving its metrics on 127.0.0.1. Document "$0" "$@" for that form and "$@" for a script in command followed by a placeholder, and use the first in the test. Co-authored-by: Amp Amp-Thread-ID: https://ampcode.com/threads/T-01a1902b-ece9-725c-863d-3e2bba35ee1d --- charts/sourcegraph/CHANGELOG.md | 2 +- charts/sourcegraph/README.md | 2 +- charts/sourcegraph/tests/command_test.yaml | 4 ++-- charts/sourcegraph/values.yaml | 6 ++++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/charts/sourcegraph/CHANGELOG.md b/charts/sourcegraph/CHANGELOG.md index a1cdae33..cc12daef 100644 --- a/charts/sourcegraph/CHANGELOG.md +++ b/charts/sourcegraph/CHANGELOG.md @@ -10,7 +10,7 @@ Use `**BREAKING**:` to denote a breaking change - Added `frontend.internalServiceAnnotations` and `frontend.internalServiceLabels` for the `sourcegraph-frontend-internal` Service. That Service no longer renders `frontend.serviceAnnotations` and `frontend.serviceLabels`, which now apply to the `sourcegraph-frontend` Service only, so load balancer annotations or a service mesh label set for the external Service no longer land on the internal one. If you relied on them on the internal Service, set the new values. - The `correct-data-dir-permissions` init containers of `pgsql`, `codeintel-db`, and `codeinsights-db` now run the database's own image instead of `sourcegraph/alpine-3.14`, which was based on an end-of-life Alpine release. The chart no longer pulls `alpine-3.14`, so private registries no longer need to mirror it. `alpine.image` has been removed and is ignored if set; `alpine.containerSecurityContext`, `alpine.resources`, and `codeInsightsDB.init.containerSecurityContext` still apply. -- Fixed the "pods available" panel and alert of the OpenTelemetry Collector dashboard, which query `up{app=~".*otel-collector"}`, having no data. The `otel-collector` Service was missing the `app` label that every other scraped Service has, so its metrics had no `app` and `job` labels. They now have `app="otel-collector"` and `job="otel-collector"`. The collector also served its own metrics on 127.0.0.1 only, unless `jaeger.enabled` was set, so Prometheus could not scrape them. The chart now always passes the container one argument, after `openTelemetry.gateway.args`, that serves them on all interfaces, port 8888. A command set in `openTelemetry.gateway.command` gets the argument too, so a shell wrapper must pass its arguments on to the collector (`"$@"`). The argument replaces `service.telemetry.metrics.readers` of the configuration files the command loads. +- Fixed the "pods available" panel and alert of the OpenTelemetry Collector dashboard, which query `up{app=~".*otel-collector"}`, having no data. The `otel-collector` Service was missing the `app` label that every other scraped Service has, so its metrics had no `app` and `job` labels. They now have `app="otel-collector"` and `job="otel-collector"`. The collector also served its own metrics on 127.0.0.1 only, unless `jaeger.enabled` was set, so Prometheus could not scrape them. The chart now always passes the container one argument, after `openTelemetry.gateway.args`, that serves them on all interfaces, port 8888. A command set in `openTelemetry.gateway.command` gets the argument too, so a shell wrapper must pass it on to the collector: as `"$0" "$@"` when the script is the first of `openTelemetry.gateway.args` after `command: ["/bin/sh", "-c"]`, or as `"$@"` when the script is in `command`, followed by a placeholder for `$0`. The argument replaces `service.telemetry.metrics.readers` of the configuration files the command loads. - Every object the chart creates now has the `deploy` and `app.kubernetes.io/component` labels. PodDisruptionBudgets get the component of their workload, PriorityClasses get `priority-class`, the StorageClass gets `storage` and keeps `deploy: sourcegraph-storage`, and the `sg-test-connection` Pod gets `test-connection`. `extraResources` get `deploy: sourcegraph` unless they set their own; set `app.kubernetes.io/component` on them yourself. The `jaeger` ConfigMap, Deployment, and Services gain `app.kubernetes.io/instance` and keep `app.kubernetes.io/name: jaeger`, which their selectors use. Labels on these objects can be changed in place; the `jaeger` pod restarts once, because its `checksum/jaeger-config` annotation covers the ConfigMap's labels. - `.labels` is now also rendered on the component's ConfigMaps, Secrets, and PodDisruptionBudget, not only on its workload, so releases that set it gain these labels on upgrade. Added `storageClass.labels` and a `labels` field on each `priorityClasses` entry. - Fixed `redisStore.serviceAccount.annotations` being ignored, so the `redis-store` ServiceAccount was created without them, e.g. without a workload identity annotation. They are now rendered, as on every other ServiceAccount. diff --git a/charts/sourcegraph/README.md b/charts/sourcegraph/README.md index 272630eb..1cf2d0f1 100644 --- a/charts/sourcegraph/README.md +++ b/charts/sourcegraph/README.md @@ -401,7 +401,7 @@ In addition to the documented values, all services also support the following va | openTelemetry.agent.serviceAccount.create | bool | `false` | Enable creation of ServiceAccount for `otel-agent` | | openTelemetry.agent.serviceAccount.name | string | `""` | Name of the ServiceAccount to be created or an existing ServiceAccount | | openTelemetry.enabled | bool | `true` | | -| openTelemetry.gateway.command | list | `[]` | Command for the `otel-collector` container, as a list, replacing the chart's `/bin/otelcol-sourcegraph --config=` command, including the `--config` flag the chart selects, e.g. a shell wrapper that exports an exporter API key read from a mounted file. `openTelemetry.gateway.args` is still passed as the arguments. The chart always passes one argument that makes the collector serve its own metrics on all interfaces, where Prometheus scrapes them, so a shell wrapper must pass its arguments on (`"$@"`). | +| openTelemetry.gateway.command | list | `[]` | Command for the `otel-collector` container, as a list, replacing the chart's `/bin/otelcol-sourcegraph --config=` command, including the `--config` flag the chart selects, e.g. a shell wrapper that exports an exporter API key read from a mounted file. `openTelemetry.gateway.args` is still passed as the arguments. The chart always passes one last argument that makes the collector serve its own metrics on all interfaces, where Prometheus scrapes them, so a shell wrapper must pass it on: as `"$0" "$@"` when the script is the first of `openTelemetry.gateway.args` after `command: ["/bin/sh", "-c"]`, or as `"$@"` when the script is in `command`, followed by a placeholder for `$0`. | | 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) | | 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) | | openTelemetry.gateway.config.traces.processors | object | `{}` | Define trace processors. Read how to configure sampling in the [OpenTelemetry documentation](https://docs.sourcegraph.com/admin/observability/opentelemetry#sampling-traces) | diff --git a/charts/sourcegraph/tests/command_test.yaml b/charts/sourcegraph/tests/command_test.yaml index 7a552971..0c084119 100644 --- a/charts/sourcegraph/tests/command_test.yaml +++ b/charts/sourcegraph/tests/command_test.yaml @@ -61,7 +61,7 @@ tests: set: openTelemetry.gateway.command: ["/bin/sh", "-c"] openTelemetry.gateway.args: - - API_KEY=$(cat /secrets/api-key) /bin/otelcol-sourcegraph --config=/etc/otel-collector/config.yaml + - API_KEY=$(cat /secrets/api-key) /bin/otelcol-sourcegraph --config=/etc/otel-collector/config.yaml "$0" "$@" asserts: - equal: path: spec.template.spec.containers[0].command @@ -69,5 +69,5 @@ tests: - equal: path: spec.template.spec.containers[0].args value: - - API_KEY=$(cat /secrets/api-key) /bin/otelcol-sourcegraph --config=/etc/otel-collector/config.yaml + - API_KEY=$(cat /secrets/api-key) /bin/otelcol-sourcegraph --config=/etc/otel-collector/config.yaml "$0" "$@" - '--config=yaml:service::telemetry::metrics::readers: [{pull: {exporter: {prometheus: {host: "0.0.0.0", port: 8888, without_type_suffix: true, without_units: true}}}}]' diff --git a/charts/sourcegraph/values.yaml b/charts/sourcegraph/values.yaml index 4c756caa..a0cd7cc2 100644 --- a/charts/sourcegraph/values.yaml +++ b/charts/sourcegraph/values.yaml @@ -762,8 +762,10 @@ openTelemetry: # `/bin/otelcol-sourcegraph --config=` command, including the `--config` flag the chart # selects, e.g. a shell wrapper that exports an exporter API key read from a mounted file. # `openTelemetry.gateway.args` is still passed as the arguments. - # The chart always passes one argument that makes the collector serve its own metrics on all - # interfaces, where Prometheus scrapes them, so a shell wrapper must pass its arguments on (`"$@"`). + # The chart always passes one last argument that makes the collector serve its own metrics on all + # interfaces, where Prometheus scrapes them, so a shell wrapper must pass it on: as `"$0" "$@"` when the + # script is the first of `openTelemetry.gateway.args` after `command: ["/bin/sh", "-c"]`, or as `"$@"` + # when the script is in `command`, followed by a placeholder for `$0`. command: [] # -- Resource requests & limits for the `otel-collector` container, # learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/)