Skip to content

Commit 97108bc

Browse files
authored
[DBMON-5380] Fix incorrect tag assertion in tests (#20354)
* Fix incorrect expected tags assertion in mysql * Fix incorrect expected tags in postgres * Fix incorrect expected tags in mongo * Fix incorrect expected tags assertion in sqlserver * Fix remaining mongo tests
1 parent 6d928d6 commit 97108bc

File tree

5 files changed

+57
-19
lines changed

5 files changed

+57
-19
lines changed

mongo/tests/test_integration.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def _assert_mongodb_instance_event(
4242
assert mongodb_instance_event['host'] == check._resolved_hostname
4343
assert mongodb_instance_event['host'] == check._resolved_hostname
4444
assert mongodb_instance_event['dbms'] == "mongo"
45-
assert mongodb_instance_event['tags'].sort() == expected_tags.sort()
45+
assert sorted(mongodb_instance_event['tags']) == sorted(expected_tags)
4646

4747
expected_instance_metadata = {
4848
"replset_name": replset_name,
@@ -112,7 +112,12 @@ def test_integration_mongos(instance_integration_cluster, aggregator, check, dd_
112112
)
113113
assert len(aggregator._events) == 0
114114

115-
expected_tags = ['server:mongodb://localhost:27017/', 'sharding_cluster_role:mongos', 'hosting_type:self-hosted']
115+
expected_tags = [
116+
'server:mongodb://testUser2:*****@localhost:27017/test',
117+
'sharding_cluster_role:mongos',
118+
'hosting_type:self-hosted',
119+
'clustername:my_cluster',
120+
]
116121
_assert_mongodb_instance_event(
117122
aggregator,
118123
mongos_check,
@@ -907,7 +912,7 @@ def test_standalone(instance_integration, aggregator, check, dd_run_check):
907912
)
908913
assert len(aggregator._events) == 0
909914

910-
expected_tags = [f'server:{mongo_check._config.clean_server_name}']
915+
expected_tags = [f'server:{mongo_check._config.clean_server_name}', 'hosting_type:self-hosted']
911916
_assert_mongodb_instance_event(
912917
aggregator,
913918
mongo_check,
@@ -1092,7 +1097,11 @@ def test_integration_reemit_mongodb_instance_on_deployment_change(
10921097
'hosting_type:self-hosted',
10931098
]
10941099

1095-
expected_tags = replica_tags + [f'server:{mongo_check._config.clean_server_name}']
1100+
expected_tags = replica_tags + [
1101+
f'server:{mongo_check._config.clean_server_name}',
1102+
'clustername:my_cluster',
1103+
'replset_me:mongo-mongodb-sharded-shard0-data-0.mongo-mongodb-sharded-headless.default.svc.cluster.local:27017',
1104+
]
10961105
_assert_mongodb_instance_event(
10971106
aggregator,
10981107
mongo_check,

mysql/tests/conftest.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def instance_basic():
8282
'username': common.USER,
8383
'password': common.PASS,
8484
'port': common.PORT,
85-
'disable_generic_tags': 'true',
85+
'disable_generic_tags': True,
8686
}
8787

8888

@@ -93,7 +93,7 @@ def instance_complex():
9393
'username': common.USER,
9494
'password': common.PASS,
9595
'port': common.PORT,
96-
'disable_generic_tags': 'true',
96+
'disable_generic_tags': True,
9797
'options': {
9898
'replication': True,
9999
'extra_status_metrics': True,
@@ -131,7 +131,7 @@ def instance_additional_status():
131131
'password': common.PASS,
132132
'port': common.PORT,
133133
'tags': tags.METRIC_TAGS,
134-
'disable_generic_tags': 'true',
134+
'disable_generic_tags': True,
135135
'additional_status': [
136136
{
137137
'name': "Innodb_rows_read",
@@ -179,7 +179,7 @@ def instance_status_already_queried():
179179
'password': common.PASS,
180180
'port': common.PORT,
181181
'tags': tags.METRIC_TAGS,
182-
'disable_generic_tags': 'true',
182+
'disable_generic_tags': True,
183183
'additional_status': [
184184
{
185185
'name': "Open_files",
@@ -198,7 +198,7 @@ def instance_var_already_queried():
198198
'password': common.PASS,
199199
'port': common.PORT,
200200
'tags': tags.METRIC_TAGS,
201-
'disable_generic_tags': 'true',
201+
'disable_generic_tags': True,
202202
'additional_variable': [
203203
{
204204
'name': "Key_buffer_size",
@@ -217,7 +217,7 @@ def instance_invalid_var():
217217
'password': common.PASS,
218218
'port': common.PORT,
219219
'tags': tags.METRIC_TAGS,
220-
'disable_generic_tags': 'true',
220+
'disable_generic_tags': True,
221221
'additional_status': [
222222
{
223223
'name': "longer_query_time",
@@ -241,7 +241,7 @@ def instance_custom_queries():
241241
'password': common.PASS,
242242
'port': common.PORT,
243243
'tags': tags.METRIC_TAGS,
244-
'disable_generic_tags': 'true',
244+
'disable_generic_tags': True,
245245
'custom_queries': [
246246
{
247247
'query': "SELECT name,age from testdb.users where name='Alice' limit 1;",

mysql/tests/test_mysql.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ def test_set_resources(aggregator, dd_run_check, instance_basic, cloud_metadata,
780780
(True, None),
781781
(False, None),
782782
(True, 'forced_hostname'),
783-
(True, 'forced_hostname'),
783+
(False, 'forced_hostname'),
784784
],
785785
)
786786
@pytest.mark.integration
@@ -793,18 +793,30 @@ def test_database_instance_metadata(aggregator, dd_run_check, instance_complex,
793793
instance_complex['query_activity'] = {'collection_interval': 0.1}
794794
instance_complex['query_samples'] = {'collection_interval': 0.1}
795795
instance_complex['query_metrics'] = {'collection_interval': 0.1}
796+
797+
expected_host = expected_database_hostname = expected_database_instance = "stubbed.hostname"
796798
if reported_hostname:
797799
instance_complex['reported_hostname'] = reported_hostname
798-
expected_host = reported_hostname if reported_hostname else 'stubbed.hostname'
800+
expected_host = reported_hostname
801+
expected_database_instance = reported_hostname
802+
803+
expected_tags = tags.METRIC_TAGS + [
804+
"database_hostname:{}".format(expected_database_hostname),
805+
"database_instance:{}".format(expected_database_instance),
806+
]
807+
799808
mysql_check = MySql(common.CHECK_NAME, {}, [instance_complex])
800809
dd_run_check(mysql_check)
801810

802811
dbm_metadata = aggregator.get_event_platform_events("dbm-metadata")
803812
event = next((e for e in dbm_metadata if e['kind'] == 'database_instance'), None)
813+
804814
assert event is not None
805815
assert event['host'] == expected_host
816+
assert event['database_instance'] == expected_database_instance
817+
assert event['database_hostname'] == expected_database_hostname
806818
assert event['dbms'] == "mysql"
807-
assert event['tags'].sort() == tags.METRIC_TAGS.sort()
819+
assert sorted(event['tags']) == sorted(expected_tags)
808820
assert event['integration_version'] == __version__
809821
assert event['collection_interval'] == 300
810822
assert event['metadata'] == {

postgres/tests/test_pg_integration.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -772,27 +772,44 @@ def test_correct_hostname(dbm_enabled, reported_hostname, expected_hostname, agg
772772
(True, None),
773773
(False, None),
774774
(True, 'forced_hostname'),
775-
(True, 'forced_hostname'),
775+
(False, 'forced_hostname'),
776776
],
777777
)
778778
def test_database_instance_metadata(aggregator, pg_instance, dbm_enabled, reported_hostname):
779779
pg_instance['dbm'] = dbm_enabled
780780
# this will block on cancel and wait for the coll interval of 600 seconds,
781781
# unless the collection_interval is set to a short amount of time
782782
pg_instance['collect_resources'] = {'collection_interval': 0.1}
783+
784+
expected_database_hostname = expected_database_instance = expected_host = "stubbed.hostname"
783785
if reported_hostname:
784786
pg_instance['reported_hostname'] = reported_hostname
785-
expected_host = reported_hostname if reported_hostname else 'stubbed.hostname'
786-
expected_tags = pg_instance['tags'] + ['port:{}'.format(pg_instance['port'])]
787+
expected_host = reported_hostname
788+
expected_database_instance = reported_hostname
789+
790+
expected_tags = pg_instance['tags'] + [
791+
'port:{}'.format(pg_instance['port']),
792+
'postgresql_cluster_name:primary',
793+
'replication_role:master',
794+
'database_hostname:{}'.format(expected_database_hostname),
795+
'database_instance:{}'.format(expected_database_instance),
796+
]
787797
check = PostgreSql('test_instance', {}, [pg_instance])
788798
run_one_check(check)
789799

800+
# These tags are a bit dynamic in value, so we get them from the check and ensure they are present
801+
expected_tags.append('postgresql_version:{}'.format(check.raw_version))
802+
expected_tags.append('system_identifier:{}'.format(check.system_identifier))
803+
790804
dbm_metadata = aggregator.get_event_platform_events("dbm-metadata")
791805
event = next((e for e in dbm_metadata if e['kind'] == 'database_instance'), None)
792806
assert event is not None
793807
assert event['host'] == expected_host
808+
assert event['database_instance'] == expected_database_instance
809+
assert event['database_hostname'] == expected_database_hostname
794810
assert event['dbms'] == "postgres"
795-
assert event['tags'].sort() == expected_tags.sort()
811+
812+
assert sorted(event['tags']) == sorted(expected_tags)
796813
assert event['integration_version'] == __version__
797814
assert event['collection_interval'] == 300
798815
assert event['metadata'] == {

sqlserver/tests/test_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def test_autodiscovery_db_service_checks(
269269
for c in sc:
270270
if c.status == SQLServer.CRITICAL:
271271
db_critical_exists = True
272-
assert c.tags.sort() == critical_tags.sort()
272+
assert sorted(c.tags) == sorted(critical_tags)
273273
if service_check_enabled:
274274
assert db_critical_exists
275275

0 commit comments

Comments
 (0)