From 26d24ec9da6b137504eb274daecc52163571bf68 Mon Sep 17 00:00:00 2001 From: Nenad Noveljic <18366081+nenadnoveljic@users.noreply.github.com> Date: Wed, 27 Nov 2024 09:19:38 +0100 Subject: [PATCH] Fix duplicate deadlock events (#19139) * Fix duplicate deadlock events * relnote * linter * Update sqlserver/datadog_checks/sqlserver/deadlocks.py Co-authored-by: Naji Astier <757637+na-ji@users.noreply.github.com> --------- Co-authored-by: Naji Astier <757637+na-ji@users.noreply.github.com> --- sqlserver/changelog.d/19139.fixed | 1 + sqlserver/datadog_checks/sqlserver/deadlocks.py | 7 ++++--- sqlserver/datadog_checks/sqlserver/queries.py | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 sqlserver/changelog.d/19139.fixed diff --git a/sqlserver/changelog.d/19139.fixed b/sqlserver/changelog.d/19139.fixed new file mode 100644 index 0000000000000..cec4e36064310 --- /dev/null +++ b/sqlserver/changelog.d/19139.fixed @@ -0,0 +1 @@ +Fix duplicate deadlock events diff --git a/sqlserver/datadog_checks/sqlserver/deadlocks.py b/sqlserver/datadog_checks/sqlserver/deadlocks.py index 088ae8f2126e2..f66766d392b57 100644 --- a/sqlserver/datadog_checks/sqlserver/deadlocks.py +++ b/sqlserver/datadog_checks/sqlserver/deadlocks.py @@ -151,14 +151,15 @@ def _query_deadlocks(self): query = get_deadlocks_query( convert_xml_to_str=convert_xml_to_str, xe_session_name=self._xe_session_name ) + lookback = self._get_lookback_seconds() self._log.debug( - "Running query [%s] with max deadlocks %s and timestamp %s", + "Running query %s with max deadlocks %s and lookback %s", query, self._max_deadlocks, - self._last_deadlock_timestamp, + lookback, ) try: - cursor.execute(query, (self._max_deadlocks, self._get_lookback_seconds())) + cursor.execute(query, (self._max_deadlocks, lookback)) except Exception as e: if "Data column of Unknown ADO type" in str(e): raise Exception(f"{str(e)} | cursor.description: {cursor.description} | query: {query}") diff --git a/sqlserver/datadog_checks/sqlserver/queries.py b/sqlserver/datadog_checks/sqlserver/queries.py index a8f32b36ab595..2b6d6adf6b883 100644 --- a/sqlserver/datadog_checks/sqlserver/queries.py +++ b/sqlserver/datadog_checks/sqlserver/queries.py @@ -171,5 +171,6 @@ def get_deadlocks_query(convert_xml_to_str=False, xe_session_name="datadog"): AND xt.target_name = N'ring_buffer' ) AS XML_Data CROSS APPLY Target_Data.nodes('RingBufferTarget/event[@name="xml_deadlock_report"]') AS XEventData(xdr) - WHERE xdr.value('@timestamp', 'datetime') >= DATEADD(SECOND, ?, GETDATE()) + WHERE xdr.value('@timestamp', 'datetime') + >= DATEADD(SECOND, ?, TODATETIMEOFFSET(GETDATE(), DATEPART(TZOFFSET, SYSDATETIMEOFFSET())) AT TIME ZONE 'UTC') ;"""