Skip to content

Only query aurora_version() if aurora postgres extensions are available #20310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 16, 2025

Conversation

eric-weaver
Copy link
Contributor

What does this PR do?

Currently the Postgres integration always calls aurora_version() to check if the database is running on AWS Aurora. If it's not, the query fails with a function not found error. This leads to query errors in database logs. To avoid calling a function that won't exist outside of AWS Aurora environment, we will now lookup available postgres extensions. If aurora related extensions are available, we can assume we're running in AWS and will verify by querying the aurora_version(). Changes were made to the VersionUtils.is_aurora() to cache the results of the first execution as this shouldn't change over the lifetime of the connection.

Running this query on Aurora Postgres will return the following extensions

SELECT * FROM pg_available_extension_versions WHERE name ILIKE '%aurora%' OR comment ILIKE '%aurora%';
       name        | version | installed | superuser | relocatable |    schema     | requires |                              comment                              
-------------------+---------+-----------+-----------+-------------+---------------+----------+-------------------------------------------------------------------
 rds_tools         | 1.0     | f         | t         | f           | rds_tools     |          | miscellaneous administrative functions for Aurora PostgreSQL
 aurora_stat_utils | 1.0     | f         | t         | f           |               |          | Statistics utility functions
 apg_plan_mgmt     | 2.1     | f         | t         | f           | apg_plan_mgmt |          | Amazon Aurora with PostgreSQL compatibility Query Plan Management
 apg_plan_mgmt     | 1.0.1   | f         | t         | f           | apg_plan_mgmt |          | Amazon Aurora with PostgreSQL compatibility Query Plan Management
 apg_plan_mgmt     | 1.0     | f         | t         | f           | apg_plan_mgmt |          | Amazon Aurora with PostgreSQL compatibility Query Plan Management
 apg_plan_mgmt     | 2.0     | f         | t         | f           | apg_plan_mgmt |          | Amazon Aurora with PostgreSQL compatibility Query Plan Management

Running it on non Aurora Postgres instances will return zero rows.

Motivation

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Add the qa/skip-qa label if the PR doesn't need to be tested during QA.
  • 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

Comment on lines 45 to 46
cursor.execute("SELECT * FROM pg_available_extension_versions WHERE name ILIKE '%aurora%' OR comment ILIKE '%aurora%';")
if len(cursor.fetchall()) > 0:
Copy link
Contributor

@nenadnoveljic nenadnoveljic May 16, 2025

Choose a reason for hiding this comment

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

How to speed up the test (minor nitpick):

  • Use LIMIT 1 to stop scanning after the first row — enough to confirm it’s Aurora.
  • Use fetchone instead of fetchall.
  • Replace SELECT * with SELECT 1.

Not a blocker - approving the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call! Needed to fix linting errors on this anyway, so applied the suggested improvements and validated its working correctly on and off Aurora

nenadnoveljic
nenadnoveljic previously approved these changes May 16, 2025
lu-zhengda
lu-zhengda previously approved these changes May 16, 2025
@temporal-github-worker-1 temporal-github-worker-1 bot dismissed stale reviews from nenadnoveljic and lu-zhengda May 16, 2025 15:24

Review from nenadnoveljic is dismissed. Related teams and files:

  • database-monitoring-agent
    • postgres/datadog_checks/postgres/version_utils.py

Review from lu-zhengda is dismissed. Related teams and files:

  • database-monitoring-agent
    • postgres/datadog_checks/postgres/version_utils.py
Copy link

codecov bot commented May 16, 2025

Codecov Report

Attention: Patch coverage is 30.76923% with 9 lines in your changes missing coverage. Please review.

Project coverage is 90.33%. Comparing base (40e4f36) to head (e37ec05).
Report is 4 commits behind head on master.

Additional details and impacted files
Flag Coverage Δ
activemq ?
cassandra ?
confluent_platform ?
hive ?
hivemq ?
hudi ?
ignite ?
jboss_wildfly ?
kafka ?
postgres 93.18% <30.76%> (+3.50%) ⬆️
presto ?
solr ?
tomcat ?
weblogic ?

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@eric-weaver eric-weaver added this pull request to the merge queue May 16, 2025
Merged via the queue into master with commit eb1a43c May 16, 2025
32 checks passed
@eric-weaver eric-weaver deleted the eric.weaver/SDBM-1736 branch May 16, 2025 16:51
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.

3 participants