Skip to content

Commit

Permalink
change query signature struct
Browse files Browse the repository at this point in the history
  • Loading branch information
nenadnoveljic committed Sep 19, 2024
1 parent d6eed3e commit c75fdc1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions sqlserver/datadog_checks/sqlserver/deadlocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _obfuscate_xml(self, root):
process_list = root.find(".//process-list")
if process_list is None:
raise Exception("process-list element not found. The deadlock XML is in an unexpected format.")
query_signatures = dict()
query_signatures = []
for process in process_list.findall('process'):
for inputbuf in process.findall('.//inputbuf'):
if inputbuf.text is not None:
Expand All @@ -83,7 +83,7 @@ def _obfuscate_xml(self, root):
if spid is not None:
if spid in query_signatures:
continue
query_signatures[spid] = compute_sql_signature(inputbuf.text)
query_signatures.append({"spid": spid, "signature": compute_sql_signature(inputbuf.text)})
else:
self._log.error("spid not found in process element. Skipping query signature computation.")
for frame in process.findall('.//frame'):
Expand Down
5 changes: 4 additions & 1 deletion sqlserver/tests/test_deadlocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,7 @@ def test__create_deadlock_rows():
with patch.object(Deadlocks, '_query_deadlocks', return_value=[["date placeholder", xml]]):
rows = deadlocks_obj._create_deadlock_rows()
assert len(rows) == 1, "Should have created one deadlock row"
assert len(rows[0]["query_signatures"]) == 2, "Should have two query signatures"
row = rows[0]
query_signatures = row["query_signatures"]
assert len(query_signatures) == 2, "Should have two query signatures"
assert "spid" in query_signatures[0], "Should have spid in query signatures"

0 comments on commit c75fdc1

Please sign in to comment.