Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent hostname evaluating to None in sqlserver check #18237

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sqlserver/changelog.d/18237.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prevent hostname evaluating to None in sqlserver check
10 changes: 7 additions & 3 deletions sqlserver/datadog_checks/sqlserver/sqlserver.py
lu-zhengda marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def set_resource_tags(self):
elif AWS_RDS_HOSTNAME_SUFFIX in self._resolved_hostname:
# allow for detecting if the host is an RDS host, and emit
# the resource properly even if the `aws` config is unset
self.tags.append("dd.internal.resource:aws_rds_instance:{}".format(self._resolved_hostname))
self.tags.append("dd.internal.resource:aws_rds_instance:{}".format(self.resolved_hostname))
if self._config.cloud_metadata.get("azure") is not None:
deployment_type = self._config.cloud_metadata.get("azure")["deployment_type"]
name = self._config.cloud_metadata.get("azure")["name"]
Expand All @@ -226,7 +226,7 @@ def set_resource_tags(self):
# 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
db_instance = self.resolved_hostname
# 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 All @@ -237,7 +237,7 @@ def set_resource_tags(self):
# finally, emit a `database_instance` resource for this instance
self.tags.append(
"dd.internal.resource:database_instance:{}".format(
self._resolved_hostname,
self.resolved_hostname,
)
)

Expand Down Expand Up @@ -275,6 +275,10 @@ def set_resolved_hostname(self):

@property
def resolved_hostname(self):
# ensure _resolved_hostname is never None when referenced by other parts
# of this check. If it falls back to None, this will result in gaps in data
if self._resolved_hostname is None:
self.set_resolved_hostname()
return self._resolved_hostname

def load_static_information(self):
Expand Down
Loading