Skip to content

Commit 8f8c0c3

Browse files
[DBMON-6789] Implement database_identifier hooks in clickhouse (#24276)
* [DBMON-6789] Implement database_identifier hooks in clickhouse Co-authored-by: Cursor <cursoragent@cursor.com> * Add changelog Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent ea872dc commit 8f8c0c3

2 files changed

Lines changed: 11 additions & 26 deletions

File tree

clickhouse/changelog.d/24276.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove duplicated database_identifier logic now provided by the DatabaseCheck base class.

clickhouse/datadog_checks/clickhouse/clickhouse.py

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# (C) Datadog, Inc. 2019-present
22
# All rights reserved
33
# Licensed under a 3-clause BSD style license (see LICENSE)
4-
from string import Template
54
from time import time
65

76
import clickhouse_connect
@@ -58,7 +57,6 @@ def __init__(self, name, init_config, instances):
5857
# DBM-related properties (computed lazily)
5958
self._resolved_hostname = None
6059
self._database_hostname = None
61-
self._database_identifier = None
6260
self._dbms_version = None
6361

6462
# Track last emission time for database instance metadata (rate limiting)
@@ -353,30 +351,16 @@ def database_hostname(self) -> str:
353351
return self._database_hostname
354352

355353
@property
356-
def database_identifier(self) -> str:
357-
"""
358-
Get a unique identifier for this database instance.
359-
Uses the database_identifier template from config, defaulting to "$server:$port:$db".
360-
"""
361-
if self._database_identifier is None:
362-
template = Template(self._config.database_identifier.template)
363-
tag_dict = {}
364-
tags = self.tags.copy()
365-
# Sort tags to ensure consistent ordering
366-
tags.sort()
367-
for t in tags:
368-
if ':' in t:
369-
key, value = t.split(':', 1)
370-
if key in tag_dict:
371-
tag_dict[key] += f",{value}"
372-
else:
373-
tag_dict[key] = value
374-
# Add connection parameters to the template variables
375-
tag_dict['server'] = str(self._config.server)
376-
tag_dict['port'] = str(self._config.port)
377-
tag_dict['db'] = str(self._config.db)
378-
self._database_identifier = template.safe_substitute(**tag_dict)
379-
return self._database_identifier
354+
def database_identifier_template(self) -> str:
355+
return self._config.database_identifier.template
356+
357+
@property
358+
def database_identifier_params(self) -> dict:
359+
return {
360+
"server": str(self._config.server),
361+
"port": str(self._config.port),
362+
"db": str(self._config.db),
363+
}
380364

381365
@property
382366
def dbms(self) -> str:

0 commit comments

Comments
 (0)