Skip to content

Commit

Permalink
Merge branch 'master' into aerospike-agent-and-dashboards
Browse files Browse the repository at this point in the history
  • Loading branch information
mphanias authored Dec 19, 2024
2 parents 81011bf + ad8e988 commit 12c926a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
1 change: 1 addition & 0 deletions postgres/changelog.d/19271.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix check for Postgres collect query activity to avoid bugs with in-flight duration and missing blocking pids
13 changes: 6 additions & 7 deletions postgres/datadog_checks/postgres/statement_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,21 +248,19 @@ def _get_active_connections(self):
return [dict(row) for row in rows]

@tracked_method(agent_check_getter=agent_check_getter, track_result_length=True)
def _get_new_pg_stat_activity(self, available_activity_columns, activity_columns_mapping):
def _get_new_pg_stat_activity(self, available_activity_columns, activity_columns_mapping, collect_activity):
start_time = time.time()
extra_filters, params = self._get_extra_filters_and_params(filter_stale_idle_conn=True)
report_activity = self._report_activity_event()
cur_time_func = ""
blocking_func = ""
backend_type_predicate = ""
if self._check.version.compare(V10) >= 0:
backend_type_predicate = "backend_type != 'client backend' OR"
# minimum version for pg_blocking_pids function is v9.6
# only call pg_blocking_pids as often as we collect activity snapshots
if self._check.version >= V9_6 and report_activity:
if self._check.version >= V9_6 and collect_activity:
blocking_func = PG_BLOCKING_PIDS_FUNC
if report_activity:
cur_time_func = CURRENT_TIME_FUNC
cur_time_func = CURRENT_TIME_FUNC
activity_columns = [activity_columns_mapping.get(col, col) for col in available_activity_columns]
query = PG_STAT_ACTIVITY_QUERY.format(
backend_type_predicate=backend_type_predicate,
Expand Down Expand Up @@ -473,7 +471,8 @@ def _collect_statement_samples(self):
raw=True,
)
return
rows = self._get_new_pg_stat_activity(pg_activity_cols, PG_STAT_ACTIVITY_COLS_MAPPING)
collect_activity = self._report_activity_event()
rows = self._get_new_pg_stat_activity(pg_activity_cols, PG_STAT_ACTIVITY_COLS_MAPPING, collect_activity)
rows = self._filter_and_normalize_statement_rows(rows)
submitted_count = 0
if self._explain_plan_coll_enabled:
Expand All @@ -482,7 +481,7 @@ def _collect_statement_samples(self):
self._check.database_monitoring_query_sample(json.dumps(e, default=default_json_event_encoding))
submitted_count += 1

if self._report_activity_event():
if collect_activity:
active_connections = self._get_active_connections()
activity_event = self._create_activity_event(rows, active_connections)
self._check.database_monitoring_query_activity(
Expand Down

0 comments on commit 12c926a

Please sign in to comment.