Skip to content

Commit

Permalink
Fix duplicate deadlock events (#19139)
Browse files Browse the repository at this point in the history
* Fix duplicate deadlock events

* relnote

* linter

* Update sqlserver/datadog_checks/sqlserver/deadlocks.py

Co-authored-by: Naji Astier <[email protected]>

---------

Co-authored-by: Naji Astier <[email protected]>
  • Loading branch information
nenadnoveljic and na-ji authored Nov 27, 2024
1 parent 1b0d18e commit 26d24ec
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions sqlserver/changelog.d/19139.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix duplicate deadlock events
7 changes: 4 additions & 3 deletions sqlserver/datadog_checks/sqlserver/deadlocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
3 changes: 2 additions & 1 deletion sqlserver/datadog_checks/sqlserver/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
;"""

0 comments on commit 26d24ec

Please sign in to comment.