|
1 | 1 | # (C) Datadog, Inc. 2019-present |
2 | 2 | # All rights reserved |
3 | 3 | # Licensed under a 3-clause BSD style license (see LICENSE) |
4 | | -from string import Template |
5 | 4 | from time import time |
6 | 5 |
|
7 | 6 | import clickhouse_connect |
@@ -58,7 +57,6 @@ def __init__(self, name, init_config, instances): |
58 | 57 | # DBM-related properties (computed lazily) |
59 | 58 | self._resolved_hostname = None |
60 | 59 | self._database_hostname = None |
61 | | - self._database_identifier = None |
62 | 60 | self._dbms_version = None |
63 | 61 |
|
64 | 62 | # Track last emission time for database instance metadata (rate limiting) |
@@ -353,30 +351,16 @@ def database_hostname(self) -> str: |
353 | 351 | return self._database_hostname |
354 | 352 |
|
355 | 353 | @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 | + } |
380 | 364 |
|
381 | 365 | @property |
382 | 366 | def dbms(self) -> str: |
|
0 commit comments