Skip to content

Add standalone pgsql-exporter for external databases - #969

Open
marcleblanc2 wants to merge 2 commits into
mainfrom
marc/external-db-exporters
Open

marcleblanc2 wants to merge 2 commits into
mainfrom
marc/external-db-exporters

Conversation

@marcleblanc2

Copy link
Copy Markdown
Contributor

Closes #388

Checklist

What

Adds <database>.postgresExporter.standalone (default false) for pgsql, codeIntelDB and codeInsightsDB. When a database is external (<database>.enabled: false) and the toggle is set, the chart deploys pgsql-exporter as its own Deployment + Service, so the Postgres panels in the Grafana dashboards work against managed databases such as AWS RDS.

pgsql:
  enabled: false
  auth:
    host: pgsql.abc.us-east-1.rds.amazonaws.com
    sslmode: require
  postgresExporter:
    standalone: true
  • sourcegraph.dataSource now builds DATA_SOURCE_URI from the auth secret's host and sslmode keys when the database is external. The sidecar on internal databases still renders localhost:...?sslmode=disable, unchanged.
  • The Service carries app: <database name>, which the Prometheus relabel config maps to the job label the dashboards group by (job="codeinsights-db" is matched literally in the dashboard queries).
  • The Deployment reuses the database's podSecurityContext, nodeSelector, affinity, tolerations, priorityClassName, serviceAccount, podLabels/podAnnotations and postgresExporter.env, plus the global postgresExporter.image / resources.
  • When sourcegraph.disableKubernetesSecrets is true, no DATA_SOURCE_* env is rendered; supply the DSN via postgresExporter.env.
  • The external-databases example README listed the secret key as pgsslmode; the chart reads sslmode (already required by the application containers), so it's corrected.

Test plan

  • helm lint charts/sourcegraph/: clean
  • helm unittest charts/sourcegraph: 202 passed, including new tests/postgresExporterStandalone_test.yaml (no render by default, no render for internal DB with toggle on, no render for external DB with toggle off, one Deployment+Service per enabled DB, env wiring with existingSecret, Service labels/annotations, sidecar DSN unchanged)
  • helm template with default values diffed against origin/main: identical
  • helm template with all three databases external and standalone: true: three Deployments and Services render as expected (see charts/sourcegraph/examples/external-databases/override.yaml)
  • ./scripts/helm-docs.sh: README regenerated, tree clean

Adds <database>.postgresExporter.standalone (default false) for pgsql,
codeIntelDB and codeInsightsDB. When the database is external
(<database>.enabled: false) and the toggle is set, the chart deploys
pgsql-exporter as its own Deployment and Service, so the Postgres
panels in the Grafana dashboards work against e.g. AWS RDS.

The exporter connects with the database's auth credentials; the
sourcegraph.dataSource helper now builds DATA_SOURCE_URI from the
secret's host and sslmode keys when the database is external, and is
unchanged for the sidecar on internal databases. The Service carries
app: <database name>, which Prometheus maps to the job label the
dashboards group by.

Also corrects the external-databases example README, which named the
secret key pgsslmode; the chart reads sslmode.

Closes #388

Amp-Thread-ID: https://ampcode.com/threads/T-01a1572d-c025-75ec-bf69-eaddc520e31c
Co-authored-by: Amp <amp@ampcode.com>
@github-actions

Copy link
Copy Markdown

Comment thread charts/sourcegraph/tests/postgresExporterStandalone_test.yaml Fixed
…positive

helm-unittest v1.0.2 short-circuits containsDocument with any: true when
run with -q, as CI does, so assert by documentIndex instead. Both
templates now iterate the databases in the same list order, so the
indexes are predictable. Use the same existingSecret value as
pgsqlAuth_test.yaml, since Checkov flagged the previous one as a secret.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1572d-c025-75ec-bf69-eaddc520e31c
Co-authored-by: Amp <amp@ampcode.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add toggle to deploy db exporters for external databases

2 participants