From cc109e75d6a658eb397d54de133fb87c64ce54df Mon Sep 17 00:00:00 2001 From: Zhengda Lu Date: Thu, 28 Sep 2023 09:49:42 -0400 Subject: [PATCH] =?UTF-8?q?Revise=20postgresql.replication=5Fdelay=20to=20?= =?UTF-8?q?Function=20with=20Archive=20WAL-driv=E2=80=A6=20(#15925)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Revise postgresql.replication_delay to Function with Archive WAL-driv… (#15629) * Revise postgresql.replication_delay to Function with Archive WAL-driven PostgreSQL Replica * modify query and also add changelog message * update master with branch * update master with branch * Add short hand for force env rebuild in test (#15716) * add short hand for force-env-rebuild * add changelog entry * styling * [Release] Update metadata (#15717) * [Release] Bumped postgres version to 14.2.1 (#15713) * Bump oracledb version (#15595) * Bump oracledb version * update reqs * update changelog * Mark one metric as optional (#15719) * Update the test environments (#15644) * Update the test environments * Apply suggestions from code review Co-authored-by: Ofek Lev * update metadata.csv --------- Co-authored-by: Ofek Lev * [DBM-2685] Fix explaining parameterized queries flood server logs (#15612) * check if query is parameterized before blindly explain then fail * update CHANGELOG * skip explain parameterized query test for pg version < 12 * fix rate limited activity collection test case (#15715) * [DBM-2734] fix test_snapshot_xmin for pg > 13 (#15718) * fix test_snapshot_xmin for pg > 13 * reorder the steps to first collect metrics * remove check.cancel() --------- Co-authored-by: Steven Yuen Co-authored-by: Andrew Zhang Co-authored-by: vivek-datadog <131680079+vivek-datadog@users.noreply.github.com> Co-authored-by: Florent Clarret Co-authored-by: Ofek Lev Co-authored-by: Zhengda Lu * update changelog * update changelog * update changelog * remove duplicate changelog entry * update changelog --------- Co-authored-by: boluwaji-deriv <97861462+boluwaji-deriv@users.noreply.github.com> Co-authored-by: Steven Yuen Co-authored-by: Andrew Zhang Co-authored-by: vivek-datadog <131680079+vivek-datadog@users.noreply.github.com> Co-authored-by: Florent Clarret Co-authored-by: Ofek Lev --- postgres/CHANGELOG.md | 2 +- postgres/datadog_checks/postgres/util.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/postgres/CHANGELOG.md b/postgres/CHANGELOG.md index 99143bc5bd48f..02a2d9e4d49bf 100644 --- a/postgres/CHANGELOG.md +++ b/postgres/CHANGELOG.md @@ -12,6 +12,7 @@ ***Fixed***: +* Revise `postgresql.replication_delay` to function with archive WAL-driven replica ([#15925](https://github.com/DataDog/integrations-core/pull/15925)) * Prevent Postgres integration from collecting WAL metrics from Aurora instances that cannot be collected ([#15896](https://github.com/DataDog/integrations-core/pull/15896)) * Set lower log level for relations metrics truncated ([#15903](https://github.com/DataDog/integrations-core/pull/15903)) @@ -47,7 +48,6 @@ ***Fixed***: -* Revise postgresql.replication_delay to Function with Archive WAL-driven PostgreSQL Replica ([#15629](https://github.com/DataDog/integrations-core/pull/15629)) * Pass timeout when connection pool closes ([#15724](https://github.com/DataDog/integrations-core/pull/15724)) ## 14.2.1 / 2023-08-29 diff --git a/postgres/datadog_checks/postgres/util.py b/postgres/datadog_checks/postgres/util.py index 27b8bda9a39c0..2e253421cc6bf 100644 --- a/postgres/datadog_checks/postgres/util.py +++ b/postgres/datadog_checks/postgres/util.py @@ -212,9 +212,10 @@ def payload_pg_version(version): } q1 = ( - 'CASE WHEN pg_last_wal_receive_lsn() IS NULL OR ' - 'pg_last_wal_receive_lsn() = pg_last_wal_replay_lsn() THEN 0 ELSE GREATEST ' - '(0, EXTRACT (EPOCH FROM now() - pg_last_xact_replay_timestamp())) END' + 'CASE WHEN exists(SELECT * FROM pg_stat_wal_receiver) ' + 'AND (pg_last_wal_receive_lsn() IS NULL ' + 'OR pg_last_wal_receive_lsn() = pg_last_wal_replay_lsn()) THEN 0 ' + 'ELSE GREATEST(0, EXTRACT (EPOCH FROM now() - pg_last_xact_replay_timestamp())) END' ) q2 = 'abs(pg_wal_lsn_diff(pg_last_wal_receive_lsn(), pg_last_wal_replay_lsn()))' REPLICATION_METRICS_10 = {