Skip to content

Commit

Permalink
Fix missing appended SQL comments (#18958)
Browse files Browse the repository at this point in the history
* Fix missing appended SQL comments

* ficed changelog

* linter

* changelog
  • Loading branch information
nenadnoveljic authored Nov 1, 2024
1 parent b39ad8a commit 6f492f9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions sqlserver/changelog.d/18958.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix missing appended SQL comments.
13 changes: 12 additions & 1 deletion sqlserver/datadog_checks/sqlserver/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from datadog_checks.base.utils.tracking import tracked_method
from datadog_checks.sqlserver.config import SQLServerConfig
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.utils import extract_sql_comments, extract_sql_comments_and_procedure_name

try:
import datadog_agent
Expand All @@ -24,6 +24,8 @@
DEFAULT_COLLECTION_INTERVAL = 10
MAX_PAYLOAD_BYTES = 19e6

TAIL_TEXT_SIZE = 200

CONNECTIONS_QUERY = """\
SELECT
login_name AS user_name,
Expand Down Expand Up @@ -59,6 +61,10 @@
ELSE req.statement_end_offset END
- req.statement_start_offset) / 2) + 1) AS statement_text,
SUBSTRING(qt.text, 1, {proc_char_limit}) as text,
CASE
WHEN LEN(qt.text) > {proc_char_limit} THEN RIGHT(qt.text, {tail_text_size})
ELSE ''
END AS tail_text,
c.client_tcp_port as client_port,
c.client_net_address as client_address,
sess.host_name as host_name,
Expand Down Expand Up @@ -213,6 +219,7 @@ def _get_activity(self, cursor, exec_request_columns):
query = ACTIVITY_QUERY.format(
exec_request_columns=', '.join(['req.{}'.format(r) for r in exec_request_columns]),
proc_char_limit=self._config.stored_procedure_characters_limit,
tail_text_size=TAIL_TEXT_SIZE,
)
self.log.debug("Running query [%s]", query)
cursor.execute(query)
Expand Down Expand Up @@ -286,6 +293,10 @@ def _obfuscate_and_sanitize_row(self, row):
)
# sqlserver doesn't have a boolean data type so convert integer to boolean
comments, row['is_proc'], procedure_name = extract_sql_comments_and_procedure_name(row['text'])
if 'tail_text' in row:
appended_comments, _ = extract_sql_comments(row['tail_text'])
if appended_comments:
comments = list(set(comments + appended_comments))
if row['is_proc'] and 'text' in row:
try:
procedure_statement = obfuscate_sql_with_metadata(
Expand Down

0 comments on commit 6f492f9

Please sign in to comment.