Skip to content

Commit f82f082

Browse files
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@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a1902b-ece9-725c-863d-3e2bba35ee1d
1 parent 524d9a6 commit f82f082

4 files changed

Lines changed: 8 additions & 6 deletions

File tree

‎charts/sourcegraph/CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Use `**BREAKING**:` to denote a breaking change
1010

1111
- 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.
1212
- 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.
13-
- 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.
13+
- 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.
1414
- 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.
1515
- `<serviceName>.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.
1616
- 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.

‎charts/sourcegraph/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ In addition to the documented values, all services also support the following va
401401
| openTelemetry.agent.serviceAccount.create | bool | `false` | Enable creation of ServiceAccount for `otel-agent` |
402402
| openTelemetry.agent.serviceAccount.name | string | `""` | Name of the ServiceAccount to be created or an existing ServiceAccount |
403403
| openTelemetry.enabled | bool | `true` | |
404-
| openTelemetry.gateway.command | list | `[]` | Command for the `otel-collector` container, as a list, replacing the chart's `/bin/otelcol-sourcegraph --config=<file>` 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 (`"$@"`). |
404+
| openTelemetry.gateway.command | list | `[]` | Command for the `otel-collector` container, as a list, replacing the chart's `/bin/otelcol-sourcegraph --config=<file>` 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`. |
405405
| 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) |
406406
| 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) |
407407
| 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) |

‎charts/sourcegraph/tests/command_test.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ tests:
6161
set:
6262
openTelemetry.gateway.command: ["/bin/sh", "-c"]
6363
openTelemetry.gateway.args:
64-
- API_KEY=$(cat /secrets/api-key) /bin/otelcol-sourcegraph --config=/etc/otel-collector/config.yaml
64+
- API_KEY=$(cat /secrets/api-key) /bin/otelcol-sourcegraph --config=/etc/otel-collector/config.yaml "$0" "$@"
6565
asserts:
6666
- equal:
6767
path: spec.template.spec.containers[0].command
6868
value: ["/bin/sh", "-c"]
6969
- equal:
7070
path: spec.template.spec.containers[0].args
7171
value:
72-
- API_KEY=$(cat /secrets/api-key) /bin/otelcol-sourcegraph --config=/etc/otel-collector/config.yaml
72+
- API_KEY=$(cat /secrets/api-key) /bin/otelcol-sourcegraph --config=/etc/otel-collector/config.yaml "$0" "$@"
7373
- '--config=yaml:service::telemetry::metrics::readers: [{pull: {exporter: {prometheus: {host: "0.0.0.0", port: 8888, without_type_suffix: true, without_units: true}}}}]'

‎charts/sourcegraph/values.yaml‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,8 +762,10 @@ openTelemetry:
762762
# `/bin/otelcol-sourcegraph --config=<file>` command, including the `--config` flag the chart
763763
# selects, e.g. a shell wrapper that exports an exporter API key read from a mounted file.
764764
# `openTelemetry.gateway.args` is still passed as the arguments.
765-
# The chart always passes one argument that makes the collector serve its own metrics on all
766-
# interfaces, where Prometheus scrapes them, so a shell wrapper must pass its arguments on (`"$@"`).
765+
# The chart always passes one last argument that makes the collector serve its own metrics on all
766+
# interfaces, where Prometheus scrapes them, so a shell wrapper must pass it on: as `"$0" "$@"` when the
767+
# script is the first of `openTelemetry.gateway.args` after `command: ["/bin/sh", "-c"]`, or as `"$@"`
768+
# when the script is in `command`, followed by a placeholder for `$0`.
767769
command: []
768770
# -- Resource requests & limits for the `otel-collector` container,
769771
# learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/)

0 commit comments

Comments
 (0)