Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jmeunier28 committed Aug 7, 2023
1 parent 77656e3 commit 375fe2e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions postgres/datadog_checks/postgres/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def _terminate_connection_unsafe(self, dbname: str):
return False
return True

def get_main_db(self):
def _get_main_db(self):
"""
Returns a memoized, persistent psycopg connection to `self.dbname`.
Utilizes the db connection pool, and is meant to be shared across multiple threads.
Expand All @@ -241,18 +241,17 @@ def execute_main_db_safe(self, query, params=None, row_format=None):
with self._query_lock:
self._log.debug("Running query [{}] {}".format(query, params))
if row_format:
with self.get_main_db().cursor(row_factory=row_format) as cursor:
with self._get_main_db().cursor(row_factory=row_format) as cursor:
cursor.execute(query, params)
return cursor.fetchall()
else:
with self.get_main_db().cursor() as cursor:
with self._get_main_db().cursor() as cursor:
cursor.execute(query, params)
return cursor.fetchall()

def get_main_db_columns_safe(self, query, params):
with self._query_lock:
with self.get_main_db().cursor() as cursor:
with self._get_main_db().cursor() as cursor:
self._log.debug("Running query [%s] %s", query, params)
cursor.execute(query, params)
return [desc[0] for desc in cursor.description] if cursor.description else []

4 changes: 2 additions & 2 deletions postgres/tests/test_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -1359,10 +1359,10 @@ def test_pg_settings_caching(aggregator, integration_check, dbm_instance):
check = integration_check(dbm_instance)
assert not check.pg_settings, "pg_settings should not have been initialized yet"
check._connect()
check.db_pool.get_main_db()
check.db_pool._get_main_db()
assert "track_activity_query_size" in check.pg_settings
check.pg_settings["test_key"] = True
check.db_pool.get_main_db()
check.db_pool._get_main_db()
assert (
"test_key" in check.pg_settings
), "key should not have been blown away. If it was then pg_settings was not cached correctly"
Expand Down

0 comments on commit 375fe2e

Please sign in to comment.