Skip to content

Commit 166c60c

Browse files
authored
Create exclude_hostname option (#20094)
* exclude_hostname * Changelog * Sync
1 parent a1be4d6 commit 166c60c

File tree

13 files changed

+26
-6
lines changed

13 files changed

+26
-6
lines changed

mysql/changelog.d/20094.added

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Create exclude_hostname option for Postgres, MySQL, and SQLServer

mysql/datadog_checks/mysql/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class MySQLConfig(object):
1313
def __init__(self, instance, init_config):
1414
self.log = get_check_logger()
1515
self.database_identifier = instance.get('database_identifier', {})
16-
self.empty_default_hostname = instance.get("empty_default_hostname", False)
16+
self.exclude_hostname = instance.get("exclude_hostname", False)
1717
self.host = instance.get('host', instance.get('server', ''))
1818
self.port = int(instance.get('port', 0))
1919
self.reported_hostname = instance.get('reported_hostname', '')

mysql/datadog_checks/mysql/mysql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def _send_metadata(self):
163163
@property
164164
def reported_hostname(self):
165165
# type: () -> str
166-
if self._config.empty_default_hostname:
166+
if self._config.exclude_hostname:
167167
return None
168168
return self.resolved_hostname
169169

postgres/changelog.d/20094.added

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Create exclude_hostname option for Postgres, MySQL, and SQLServer

postgres/datadog_checks/postgres/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class PostgresConfig:
2929
MONOTONIC = AgentCheck.monotonic_count
3030

3131
def __init__(self, instance, init_config, check):
32-
self.empty_default_hostname = instance.get("empty_default_hostname", False)
32+
self.exclude_hostname = instance.get("exclude_hostname", False)
3333
self.database_identifier = instance.get('database_identifier', {})
3434
self.init_config = init_config
3535
self.host = instance.get('host', '')

postgres/datadog_checks/postgres/postgres.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ def initialize_is_aurora(self):
476476
@property
477477
def reported_hostname(self):
478478
# type: () -> str
479-
if self._config.empty_default_hostname:
479+
if self._config.exclude_hostname:
480480
return None
481481
return self.resolved_hostname
482482

sqlserver/assets/configuration/spec.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ files:
7171
and can be useful to set a custom hostname when connecting to a remote database through a proxy.
7272
value:
7373
type: string
74+
- name: exclude_hostname
75+
description: |
76+
Omit the hostname from tags and events. This is useful when the database host is not monitored by an agent.
77+
value:
78+
type: boolean
79+
example: false
80+
default: false
7481
- name: database_identifier
7582
description: |
7683
Controls how the database is identified. The default value is the resolved hostname for the instance,

sqlserver/changelog.d/20094.added

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Create exclude_hostname option for Postgres, MySQL, and SQLServer

sqlserver/datadog_checks/sqlserver/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __init__(self, init_config, instance, log):
2424
propagate_agent_tags=self._should_propagate_agent_tags(instance, init_config),
2525
additional_tags=[],
2626
)
27-
self.empty_default_hostname = instance.get("empty_default_hostname", False)
27+
self.exclude_hostname = instance.get("exclude_hostname", False)
2828
self.reported_hostname: str = instance.get('reported_hostname')
2929
self.autodiscovery: bool = is_affirmative(instance.get('database_autodiscovery'))
3030
self.autodiscovery_include: list[str] = instance.get('autodiscovery_include', ['.*']) or ['.*']

sqlserver/datadog_checks/sqlserver/config_models/defaults.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ def instance_empty_default_hostname():
6060
return False
6161

6262

63+
def instance_exclude_hostname():
64+
return False
65+
66+
6367
def instance_ignore_missing_database():
6468
return False
6569

sqlserver/datadog_checks/sqlserver/config_models/instance.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ class InstanceConfig(BaseModel):
379379
driver: Optional[str] = None
380380
dsn: Optional[str] = None
381381
empty_default_hostname: Optional[bool] = None
382+
exclude_hostname: Optional[bool] = None
382383
gcp: Optional[Gcp] = None
383384
host: str
384385
ignore_missing_database: Optional[bool] = None

sqlserver/datadog_checks/sqlserver/data/conf.yaml.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ instances:
8080
#
8181
# reported_hostname: <REPORTED_HOSTNAME>
8282

83+
## @param exclude_hostname - boolean - optional - default: false
84+
## Omit the hostname from tags and events. This is useful when the database host is not monitored by an agent.
85+
#
86+
# exclude_hostname: false
87+
8388
## Controls how the database is identified. The default value is the resolved hostname for the instance,
8489
## which respects the `reported_hostname` option.
8590
##

sqlserver/datadog_checks/sqlserver/sqlserver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def resolve_db_host(self):
276276
@property
277277
def reported_hostname(self):
278278
# type: () -> str
279-
if self._config.empty_default_hostname:
279+
if self._config.exclude_hostname:
280280
return None
281281
return self.resolved_hostname
282282

0 commit comments

Comments
 (0)