Skip to content

Commit 8228037

Browse files
committed
Fixes
1 parent 991052a commit 8228037

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

sqlserver/datadog_checks/sqlserver/sqlserver.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -833,12 +833,12 @@ def check(self, _):
833833
self._query_manager.compile_queries()
834834

835835
self._send_database_instance_metadata()
836-
836+
837837
if self._config.proc:
838838
self.do_stored_procedure_check()
839839
else:
840840
self.collect_metrics()
841-
841+
842842
self.log.error("[EG] I am right here!!!! blub")
843843
if self._config.autodiscovery and self._config.autodiscovery_db_service_check:
844844
self._check_database_conns()
@@ -976,14 +976,13 @@ def load_basic_metrics(self, cursor):
976976
else:
977977
metric.fetch_metric(rows, cols)
978978

979-
980979
def collect_metrics(self):
981980
"""Fetch the metrics from all the associated database tables."""
982981
with self.connection.open_managed_default_connection():
983982
if not self._config.only_custom_queries:
984983
with self.connection.get_managed_cursor() as cursor:
985984
self.load_basic_metrics(cursor)
986-
985+
987986
# Neither pyodbc nor adodbapi are able to read results of a query if the number of rows affected
988987
# statement are returned as part of the result set, so we disable for the entire connection
989988
# this is important mostly for custom_queries or the stored_procedure feature
@@ -999,7 +998,7 @@ def collect_metrics(self):
999998
for database_metric in self.database_metrics:
1000999
database_metric.execute()
10011000

1002-
# reuse the connection for custom queries
1001+
# reuse the connection for custom queries
10031002
self._query_manager.execute()
10041003
finally:
10051004
with self.connection.get_managed_cursor() as cursor:

sqlserver/tests/test_integration.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import logging
55
import re
66
from copy import copy, deepcopy
7-
from tkinter.constants import TRUE
87

98
import mock
109
import pytest
@@ -507,6 +506,34 @@ def test_custom_queries(aggregator, dd_run_check, instance_docker, custom_query,
507506
aggregator.assert_metric(metric_name, **kwargs)
508507

509508

509+
@pytest.mark.integration
510+
@pytest.mark.usefixtures('dd_environment')
511+
@pytest.mark.parametrize(
512+
"custom_query, assert_metrics",
513+
[
514+
(
515+
{
516+
'query': "SELECT letter, num FROM (VALUES (97, 'a'), (98, 'b')) AS t (num,letter)",
517+
'columns': [{'name': 'customtag', 'type': 'tag'}, {'name': 'num', 'type': 'gauge'}],
518+
'tags': ['query:custom'],
519+
},
520+
[
521+
("sqlserver.num", {"value": 97, "tags": ["customtag:a", "query:custom"]}),
522+
("sqlserver.num", {"value": 98, "tags": ["customtag:b", "query:custom"]}),
523+
],
524+
),
525+
(
526+
{
527+
'query': "EXEC exampleProcWithoutNocount",
528+
'columns': [{'name': 'value', 'type': 'gauge'}],
529+
'tags': ['hello:there'],
530+
},
531+
[
532+
("sqlserver.value", {"value": 1, "tags": ["hello:there"]}),
533+
],
534+
),
535+
],
536+
)
510537
def test_custom_queries_only(aggregator, dd_run_check, instance_docker, custom_query, assert_metrics):
511538
instance = copy(instance_docker)
512539
instance['custom_queries'] = [custom_query]
@@ -531,6 +558,7 @@ def test_custom_queries_only(aggregator, dd_run_check, instance_docker, custom_q
531558
)
532559
aggregator.assert_metric(metric_name, **kwargs)
533560

561+
534562
@pytest.mark.integration
535563
@pytest.mark.usefixtures('dd_environment')
536564
def test_load_static_information(aggregator, dd_run_check, instance_docker):

0 commit comments

Comments
 (0)