diff --git a/sqlserver/assets/configuration/spec.yaml b/sqlserver/assets/configuration/spec.yaml index f7d8bee34c74c..95a64f9ac9657 100644 --- a/sqlserver/assets/configuration/spec.yaml +++ b/sqlserver/assets/configuration/spec.yaml @@ -225,6 +225,12 @@ files: type: boolean example: false - template: instances/default + overrides: + disable_generic_tags.hidden: False + disable_generic_tags.enabled: True + disable_generic_tags.description: | + Generic tags such as `host` are replaced by `sqlserver_host` to avoid + getting mixed with other integraton tags. - template: logs example: diff --git a/sqlserver/datadog_checks/sqlserver/data/conf.yaml.example b/sqlserver/datadog_checks/sqlserver/data/conf.yaml.example index 0a5c198196b6c..6cf32a97ef0f5 100644 --- a/sqlserver/datadog_checks/sqlserver/data/conf.yaml.example +++ b/sqlserver/datadog_checks/sqlserver/data/conf.yaml.example @@ -284,6 +284,12 @@ instances: # # empty_default_hostname: false + ## @param disable_generic_tags - boolean - optional - default: false + ## Generic tags such as `host` are replaced by `sqlserver_host` to avoid + ## getting mixed with other integraton tags. + # + disable_generic_tags: true + ## Log Section ## ## type - required - Type of log input source (tcp / udp / file / windows_event) diff --git a/sqlserver/datadog_checks/sqlserver/sqlserver.py b/sqlserver/datadog_checks/sqlserver/sqlserver.py index f07d30649188f..7cb329c11f1c3 100644 --- a/sqlserver/datadog_checks/sqlserver/sqlserver.py +++ b/sqlserver/datadog_checks/sqlserver/sqlserver.py @@ -137,10 +137,13 @@ def initialize_connection(self): def handle_service_check(self, status, host, database, message=None, is_default=True): custom_tags = self.instance.get("tags", []) + disable_generic_tags = self.instance.get('disable_generic_tags', False) if custom_tags is None: custom_tags = [] - - service_check_tags = ['host:{}'.format(host), 'db:{}'.format(database)] + if disable_generic_tags: + service_check_tags = ['sqlserver_host:{}'.format(host), 'db:{}'.format(database)] + else: + service_check_tags = ['host:{}'.format(host), 'sqlserver_host:{}'.format(host), 'db:{}'.format(database)] service_check_tags.extend(custom_tags) service_check_tags = list(set(service_check_tags)) diff --git a/sqlserver/setup.py b/sqlserver/setup.py index ab5d1e60a1558..dd46bba7c00a0 100644 --- a/sqlserver/setup.py +++ b/sqlserver/setup.py @@ -27,7 +27,7 @@ def get_dependencies(): return f.readlines() -CHECKS_BASE_REQ = 'datadog-checks-base>=16.7.0' +CHECKS_BASE_REQ = 'datadog-checks-base>=21.2.0' setup( name='datadog-sqlserver', diff --git a/sqlserver/tests/common.py b/sqlserver/tests/common.py index d9f4a7f15cd82..b99d7289ec3c7 100644 --- a/sqlserver/tests/common.py +++ b/sqlserver/tests/common.py @@ -82,6 +82,7 @@ def get_local_driver(): 'include_fci_metrics': True, 'include_ao_metrics': False, 'include_master_files_metrics': True, + 'disable_generic_tags': True, } INSTANCE_AO_DOCKER_SECONDARY = { @@ -92,6 +93,7 @@ def get_local_driver(): 'password': 'Password123', 'tags': ['optional:tag1'], 'include_ao_metrics': True, + 'disable_generic_tags': True, } CUSTOM_QUERY_A = { @@ -113,6 +115,7 @@ def get_local_driver(): 'host': LOCAL_SERVER, 'username': 'sa', 'password': 'Password12!', + 'disable_generic_tags': True, } INSTANCE_SQL2017 = INSTANCE_SQL2017_DEFAULTS.copy() INSTANCE_SQL2017.update( @@ -124,6 +127,7 @@ def get_local_driver(): 'include_fci_metrics': True, 'include_ao_metrics': False, 'include_master_files_metrics': True, + 'disable_generic_tags': True, } ) diff --git a/sqlserver/tests/test_integration.py b/sqlserver/tests/test_integration.py index 096ef8c5f750d..3578aa3cbfe24 100644 --- a/sqlserver/tests/test_integration.py +++ b/sqlserver/tests/test_integration.py @@ -32,7 +32,7 @@ def test_check_invalid_password(aggregator, dd_run_check, init_config, instance_ aggregator.assert_service_check( 'sqlserver.can_connect', status=sqlserver_check.CRITICAL, - tags=['host:localhost,1433', 'db:master', 'optional:tag1'], + tags=['sqlserver_host:localhost,1433', 'db:master', 'optional:tag1'], ) @@ -42,7 +42,10 @@ def test_check_invalid_password(aggregator, dd_run_check, init_config, instance_ def test_check_docker(aggregator, dd_run_check, init_config, instance_docker): sqlserver_check = SQLServer(CHECK_NAME, init_config, [instance_docker]) dd_run_check(sqlserver_check) - expected_tags = instance_docker.get('tags', []) + ['host:{}'.format(instance_docker.get('host')), 'db:master'] + expected_tags = instance_docker.get('tags', []) + [ + 'sqlserver_host:{}'.format(instance_docker.get('host')), + 'db:master', + ] assert_metrics(aggregator, expected_tags) @@ -230,14 +233,16 @@ def test_autodiscovery_db_service_checks(aggregator, dd_run_check, instance_auto # verify that the old status check returns OK aggregator.assert_service_check( - 'sqlserver.can_connect', tags=['db:master', 'optional:tag1', 'host:localhost,1433'], status=SQLServer.OK + 'sqlserver.can_connect', + tags=['db:master', 'optional:tag1', 'sqlserver_host:localhost,1433'], + status=SQLServer.OK, ) # verify all databses in autodiscovery have a service check for database in instance_autodiscovery['autodiscovery_include']: aggregator.assert_service_check( 'sqlserver.database.can_connect', - tags=['db:{}'.format(database), 'optional:tag1', 'host:localhost,1433'], + tags=['db:{}'.format(database), 'optional:tag1', 'sqlserver_host:localhost,1433'], status=SQLServer.OK, ) @@ -255,13 +260,13 @@ def test_autodiscovery_exclude_db_service_checks(aggregator, dd_run_check, insta # assert no connection is created for an excluded database aggregator.assert_service_check( 'sqlserver.database.can_connect', - tags=['db:msdb', 'optional:tag1', 'host:localhost,1433'], + tags=['db:msdb', 'optional:tag1', 'sqlserver_host:localhost,1433'], status=SQLServer.OK, count=0, ) aggregator.assert_service_check( 'sqlserver.database.can_connect', - tags=['db:master', 'optional:tag1', 'host:localhost,1433'], + tags=['db:master', 'optional:tag1', 'sqlserver_host:localhost,1433'], status=SQLServer.OK, ) diff --git a/sqlserver/tests/test_unit.py b/sqlserver/tests/test_unit.py index d38aad2c32e92..6b6997a39b86a 100644 --- a/sqlserver/tests/test_unit.py +++ b/sqlserver/tests/test_unit.py @@ -194,7 +194,7 @@ def test_set_default_driver_conf(): def test_check_local(aggregator, dd_run_check, init_config, instance_sql2017): sqlserver_check = SQLServer(CHECK_NAME, init_config, [instance_sql2017]) dd_run_check(sqlserver_check) - expected_tags = instance_sql2017.get('tags', []) + ['host:{}'.format(LOCAL_SERVER), 'db:master'] + expected_tags = instance_sql2017.get('tags', []) + ['sqlserver_host:{}'.format(LOCAL_SERVER), 'db:master'] assert_metrics(aggregator, expected_tags) @@ -206,5 +206,5 @@ def test_check_adoprovider(aggregator, dd_run_check, init_config, instance_sql20 sqlserver_check = SQLServer(CHECK_NAME, init_config, [instance]) dd_run_check(sqlserver_check) - expected_tags = instance.get('tags', []) + ['host:{}'.format(LOCAL_SERVER), 'db:master'] + expected_tags = instance.get('tags', []) + ['sqlserver_host:{}'.format(LOCAL_SERVER), 'db:master'] assert_metrics(aggregator, expected_tags) diff --git a/sqlserver/tox.ini b/sqlserver/tox.ini index a0a13965f05f1..cb49a8c0e86f8 100644 --- a/sqlserver/tox.ini +++ b/sqlserver/tox.ini @@ -25,7 +25,6 @@ commands = pip install -r requirements.in pytest -v {posargs} setenv = - DDEV_SKIP_GENERIC_TAGS_CHECK=true ODBCSYSINI = {toxinidir}/tests/odbc COMPOSE_FOLDER = compose ha: COMPOSE_FOLDER = compose-ha