Skip to content

fix(collector): honor custom Postgres and PgBouncer ports in OTel metrics configs - #4535

Open
andrewlecuyer wants to merge 1 commit into
CrunchyData:mainfrom
andrewlecuyer:fix-otel-custom-pg-port
Open

fix(collector): honor custom Postgres and PgBouncer ports in OTel metrics configs#4535
andrewlecuyer wants to merge 1 commit into
CrunchyData:mainfrom
andrewlecuyer:fix-otel-custom-pg-port

Conversation

@andrewlecuyer

Copy link
Copy Markdown
Collaborator

Replaces hardcoded port=5432 in the generated OpenTelemetry collector receivers with the actual configured ports from the cluster spec for both Postgres and PgBouncer metrics. Also updates the server static attribute in Postgres metric queries to reflect the configured Postgres port, and adds tests covering custom ports.

Checklist:

  • Have you added an explanation of what your changes do and why you'd like them to be included?
  • Have you updated or added documentation for the change, as applicable?
  • Have you tested your changes on all related environments with successful results, as applicable?
    • Have you added automated tests?

Type of Changes:

  • New feature
  • Bug fix
  • Documentation
  • Testing enhancement
  • Other

What is the current behavior (link to any open issues here)?

OTel metrics collection does not honor custom PG or PgBouncer ports.

What is the new behavior (if this is a feature change)?

  • Breaking change (fix or feature that would cause existing functionality to change)

OTel metrics collection honors custom PG or PgBouncer ports.

Other Information:

…rics configs

Replaces hardcoded `port=5432` in the generated OpenTelemetry collector
receivers with the actual configured ports from the cluster spec for both
Postgres and PgBouncer metrics. Also updates the `server` static
attribute in Postgres metric queries to reflect the configured Postgres
port, and adds tests covering custom ports.
@andrewlecuyer
andrewlecuyer marked this pull request as ready for review August 12, 2026 01:05
@ValClarkson

Copy link
Copy Markdown
Contributor

Nice, focused fix. The four hardcoded port=5432 values and the localhost:5432 in Postgres metric static_attributes.server are correctly threaded through from spec.port / spec.proxy.pgBouncer.port, and the added updateServerAttribute runs after appendToJSONArray, so the version-specific fast-metrics files get rewritten too. Tests pass locally.

A few notes:

  • The nil-dereferences of *Spec.Port and *Spec.Proxy.PGBouncer.Port are safe on the reconcile path (cluster.Default() runs first, and NewConfigForPgBouncerPod guards Proxy/PGBouncer), and it matches how we deref Spec.Port everywhere else. Fine.
  • updateServerAttribute now runs on every reconcile even without customizations — small perf hit, not worth conditionalizing.
  • If any of the three json.Unmarshal calls fail, *MetricsArr stays nil and we end up marshaling null into queries. Same shape as before, so not a regression, but worth a follow-up.
  • Test coverage: CustomPort only asserts on sqlquery/5s and the pgBouncer sqlquery. Would be good to also cover sqlquery/300s, a custom-query add, and a per-DB target since those receivers are all touched.
    cmp.Contains(datasource, "port=5433") would match port=54331 — tightening to port=5433 user= is more precise.

Nits: the // Sets Port to 5432 comments in tests will go stale if defaults change; and updateServerAttribute could note the port arg is spec.port.
The three red CI checks are unrelated: vulnerabilities is x/net@v0.55.0 / x/crypto/openpgp, and the kuttl failures are the usual pgBackRest stanza-create / namespace-teardown flakes — nothing OTel or port related.

Optional follow-up: the generated JSON still ships "server": "localhost:5432", which reads misleadingly now that it's always rewritten. Could either use a placeholder or just inject the attribute in updateServerAttribute.

@ValClarkson ValClarkson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment

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.

3 participants