Skip to content

Add DBM Postgres setup module and extract configure_connection - #24052

Draft
sangeetashivaji wants to merge 3 commits into
masterfrom
sangeeta/dbm-setup-postgres-connection-layer
Draft

Add DBM Postgres setup module and extract configure_connection#24052
sangeetashivaji wants to merge 3 commits into
masterfrom
sangeeta/dbm-setup-postgres-connection-layer

Conversation

@sangeetashivaji

@sangeetashivaji sangeetashivaji commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Hosts the DBM Postgres setup logic in the integration so the
datadog-agent integration setup postgres CLI can tunnel into it
(python -m datadog_checks.postgres.setup) rather than shipping a standalone
copy in the agent.

  • Adds datadog_checks/postgres/setup.py — the Detect → Plan → Apply logic that
    idempotently configures a Postgres instance for DBM (user, grants, server
    settings, per-database extension/schema/helper functions). Reads a JSON config
    from stdin and writes a JSON result to stdout.
  • Extracts configure_connection out of LRUConnectionPoolManager._configure_connection
    into a module-level function so setup configures connections exactly like the
    running check (autocommit, SQL_ASCII decoding, CommenterCursor) without a pool
    instance. The pool manager now delegates to it; behavior is unchanged.
  • Setup reuses the integration's building blocks instead of duplicating them:
    configure_connection, AUTODISCOVERY_QUERY (database navigation for
    --all-databases), and parse_shared_preload_libraries.
  • Keeps the canonical datadog.* helper-function SQL as constants alongside
    tests/compose/resources/03_setup.sh, giving a single source of truth in this
    repo (resolves the SQL-drift risk).
  • On RDS/Aurora re-runs, skips the parameter-group manual step once the value
    already matches, so an already-configured instance verifies cleanly instead of
    reporting manual steps forever.

Motivation

Review feedback on DataDog/datadog-agent#51751: the setup logic belongs in the
Python integration where the connection-management and database-navigation code
already lives, with the Go agent acting only as the tunnel to it.

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Add qa/required if this PR needs QA validation, or qa/skip-qa if it does not. Exactly one of the two is required.
  • If you need to backport this PR to another branch, you can add the backport/<branch-name> label to the PR and it will automatically open a backport PR once this one is merged

…le-level function

Moves the connection configuration logic out of LRUConnectionPoolManager._configure_connection
into a public module-level configure_connection() so it can be shared with the
integration-setup CLI (datadog-agent integration setup postgres) without requiring
a pool instance or duplicating the logic.

LRUConnectionPoolManager._configure_connection now delegates to it, preserving
identical behavior for all existing callers.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sangeetashivaji
sangeetashivaji requested review from a team as code owners June 15, 2026 19:24
@sangeetashivaji sangeetashivaji changed the title refactor(postgres): extract configure_connection as a standalone modu… refactor(postgres): extract configure_connection as a standalone function Jun 15, 2026
@datadog-prod-us1-4

datadog-prod-us1-4 Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Tests  Code Coverage

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 70.35%
Overall Coverage: 93.39%

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: c984e05 | Docs | Datadog PR Page | Give us feedback!

Host the Detect/Plan/Apply setup logic in datadog_checks.postgres.setup so the
datadog-agent integration-setup CLI can tunnel into it (python -m ...) instead of
shipping a standalone copy. Reuses configure_connection, AUTODISCOVERY_QUERY, and
parse_shared_preload_libraries, and keeps the canonical datadog helper-function
SQL alongside the test compose resources. Skips AWS parameter-group manual steps
on re-runs once the value already matches, fixing the non-idempotent exit code.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@sangeetashivaji sangeetashivaji changed the title refactor(postgres): extract configure_connection as a standalone function Add DBM Postgres setup module and extract configure_connection Jun 30, 2026
@sangeetashivaji
sangeetashivaji marked this pull request as draft June 30, 2026 15:58
@sangeetashivaji sangeetashivaji added the qa/required QA is required for this PR and will generate a QA card label Jul 14, 2026
Integration tests that run the setup module end-to-end against the live
containerized Postgres across the hatch version matrix (9.6 -> 18): dry-run
detect/plan, version-specific grant branch, the stdin/stdout CLI contract, and
a real apply that verifies idempotency on re-runs.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@dd-octo-sts

dd-octo-sts Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Validation Report

All 21 validations passed.

Show details
Validation Description Status
agent-reqs Verify check versions match the Agent requirements file
ci Validate CI configuration and code coverage settings
codeowners Validate every integration has a CODEOWNERS entry
config Validate default configuration files against spec.yaml
dep Verify dependency pins are consistent and Agent-compatible
http Validate integrations use the HTTP wrapper correctly
imports Validate check imports do not use deprecated modules
integration-style Validate check code style conventions
jmx-metrics Validate JMX metrics definition files and config
labeler Validate PR labeler config matches integration directories
legacy-signature Validate no integration uses the legacy Agent check signature
license-headers Validate Python files have proper license headers
licenses Validate third-party license attribution list
metadata Validate metadata.csv metric definitions
models Validate configuration data models match spec.yaml
openmetrics Validate OpenMetrics integrations disable the metric limit
package Validate Python package metadata and naming
qa-label Validate the pull request declares whether it needs QA for the next Agent release
readmes Validate README files have required sections
saved-views Validate saved view JSON file structure and fields
version Validate version consistency between package and changelog

View full run

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant