Skip to content

Commit

Permalink
adopted oto the activity pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
kozlovb committed Aug 8, 2024
1 parent 12d2ee9 commit 8196b9a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 11 additions & 5 deletions sqlserver/datadog_checks/sqlserver/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from datadog_checks.sqlserver.const import STATIC_INFO_ENGINE_EDITION, STATIC_INFO_VERSION
from datadog_checks.sqlserver.utils import extract_sql_comments_and_procedure_name
from datadog_checks.sqlserver.deadlocks import Deadlocks

import pdb
try:
import datadog_agent
except ImportError:
Expand Down Expand Up @@ -250,9 +250,14 @@ def run_job(self):
@tracked_method(agent_check_getter=agent_check_getter)
def _collect_deadlocks(self):
deadlock_xmls = self._deadlocks.collect_deadlocks()
deadlocks_event = self._create_deadlock_event(deadlock_xmls)
payload = json.dumps(deadlocks_event, default=default_json_event_encoding)
self._check.database_monitoring_deadlocks(payload)
#deadlocks_event = self._create_deadlock_event(deadlock_xmls)
#payload = json.dumps(deadlocks_event, default=default_json_event_encoding)
#self._check.database_monitoring_deadlocks(payload)


deadlocks_event_activity = self._create_activity_event([], [], deadlock_xmls)
payload = json.dumps(deadlocks_event_activity, default=default_json_event_encoding)
self._check.database_monitoring_query_activity(payload)

@tracked_method(agent_check_getter=agent_check_getter)
def _get_active_connections(self, cursor):
Expand Down Expand Up @@ -415,7 +420,7 @@ def _sanitize_row(row, obfuscated_statement=None):
def _get_estimated_row_size_bytes(row):
return len(str(row))

def _create_activity_event(self, active_sessions, active_connections):
def _create_activity_event(self, active_sessions, active_connections, deadlocks = []):
event = {
"host": self._check.resolved_hostname,
"ddagentversion": datadog_agent.get_version(),
Expand All @@ -429,6 +434,7 @@ def _create_activity_event(self, active_sessions, active_connections):
"cloud_metadata": self._config.cloud_metadata,
"sqlserver_activity": active_sessions,
"sqlserver_connections": active_connections,
"sqlserver_deadlocks": deadlocks,
}
return event

Expand Down
2 changes: 0 additions & 2 deletions sqlserver/datadog_checks/sqlserver/deadlocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def obfuscate_no_except_wrapper(self, sql_text):

def obfuscate_xml(self, root):
# TODO put exception here if not found as this would signal in a format change
pdb.set_trace()
process_list = root.find(".//process-list")
for process in process_list.findall('process'):
inputbuf = process.find('inputbuf')
Expand All @@ -49,7 +48,6 @@ def obfuscate_xml(self, root):
frame.text = self.obfuscate_no_except_wrapper(frame.text)

def collect_deadlocks(self):
pdb.set_trace()
with self._check.connection.open_managed_default_connection(key_prefix=self._conn_key_prefix):
with self._check.connection.get_managed_cursor(key_prefix=self._conn_key_prefix) as cursor:
cursor.execute(DETECT_DEADLOCK_QUERY, (self._max_deadlocks, self._last_deadlock_timestamp))
Expand Down

0 comments on commit 8196b9a

Please sign in to comment.