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
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions postgres/changelog.d/20310.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Check for aws extensions before querying aurora_version()
32 changes: 18 additions & 14 deletions postgres/datadog_checks/postgres/version_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
class VersionUtils(object):
def __init__(self):
self.log = get_check_logger()
self._seen_aurora_exception = False
self._is_aurora = None

@staticmethod
def get_raw_version(db):
Expand All @@ -38,21 +38,25 @@ def get_raw_version(db):
return raw_version

def is_aurora(self, db):
if self._seen_aurora_exception:
return False
if self._is_aurora is not None:
return self._is_aurora
with db as conn:
with conn.cursor(cursor_factory=CommenterCursor) as cursor:
# This query will pollute PG logs in non aurora versions,
# but is the only reliable way to detect aurora
try:
cursor.execute('select AURORA_VERSION();')
return True
except Exception as e:
self.log.debug(
"Captured exception %s while determining if the DB is aurora. Assuming is not", str(e)
)
self._seen_aurora_exception = True
return False
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

# This query will pollute PG logs in non aurora versions,
# but is the only reliable way to detect aurora.
# Since we found aurora extensions, this should exist.
try:
cursor.execute('select AURORA_VERSION();')
self._is_aurora = True
return self._is_aurora
except Exception as e:
self.log.debug(
"Captured exception %s while determining if the DB is aurora. Assuming is not", str(e)
)
self._is_aurora = False
return self._is_aurora

@staticmethod
def parse_version(raw_version):
Expand Down
Loading