Skip to content

Commit

Permalink
[sqlserver] fix azure_sql_server_database resource (#19014)
Browse files Browse the repository at this point in the history
* fix azure_sql_server_database resource

* add changelog
  • Loading branch information
lu-zhengda authored Nov 8, 2024
1 parent a85476a commit 79d345a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
1 change: 1 addition & 0 deletions sqlserver/changelog.d/19014.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix `azure_sql_server_database` resource tag to use Azure SQL Database `{fully_qualified_doman_name}/{database_name}`.
8 changes: 4 additions & 4 deletions sqlserver/datadog_checks/sqlserver/sqlserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@ def set_resource_tags(self):
name = self._config.cloud_metadata.get("azure")["name"]
db_instance = None
if "sql_database" in deployment_type and self._config.dbm_enabled:
# azure sql databases have a special format, which is set for DBM
# customers in the resolved_hostname.
# If user is not DBM customer, the resource_name should just be set to the `name`
db_instance = self._resolved_hostname
# azure_sql_server_database resource should be set to {fully_qualified_server_name}/{database_name}
# for correct resource aliasing
dbname = self.instance.get("database", "master")
db_instance = f"{name}/{dbname}"
# some `deployment_type`s map to multiple `resource_type`s
resource_types = AZURE_DEPLOYMENT_TYPE_TO_RESOURCE_TYPES.get(deployment_type).split(",")
for r_type in resource_types:
Expand Down
18 changes: 9 additions & 9 deletions sqlserver/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,12 +601,12 @@ def test_file_space_usage_metrics(aggregator, dd_run_check, instance_docker, dat
{
'azure': {
'deployment_type': 'sql_database',
'name': 'my-instance',
'name': 'my-instance.database.windows.net',
},
},
[
"dd.internal.resource:azure_sql_server_database:forced_hostname",
"dd.internal.resource:azure_sql_server:my-instance",
"dd.internal.resource:azure_sql_server_database:my-instance.database.windows.net/datadog_test-1",
"dd.internal.resource:azure_sql_server:my-instance.database.windows.net",
],
),
(
Expand All @@ -618,12 +618,12 @@ def test_file_space_usage_metrics(aggregator, dd_run_check, instance_docker, dat
{
'azure': {
'deployment_type': 'sql_database',
'name': 'my-instance',
'name': 'my-instance.database.windows.net',
},
},
[
"dd.internal.resource:azure_sql_server_database:localhost/datadog_test-1",
"dd.internal.resource:azure_sql_server:my-instance",
"dd.internal.resource:azure_sql_server_database:my-instance.database.windows.net/datadog_test-1",
"dd.internal.resource:azure_sql_server:my-instance.database.windows.net",
],
),
(
Expand Down Expand Up @@ -656,13 +656,13 @@ def test_file_space_usage_metrics(aggregator, dd_run_check, instance_docker, dat
},
'azure': {
'deployment_type': 'sql_database',
'name': 'my-instance',
'name': 'my-instance.database.windows.net',
},
},
[
"dd.internal.resource:aws_rds_instance:foo.aws.com",
"dd.internal.resource:azure_sql_server_database:my-instance",
"dd.internal.resource:azure_sql_server:my-instance",
"dd.internal.resource:azure_sql_server_database:my-instance.database.windows.net",
"dd.internal.resource:azure_sql_server:my-instance.database.windows.net",
],
),
(
Expand Down

0 comments on commit 79d345a

Please sign in to comment.