Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 datadog_checks_base/changelog.d/24297.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a `DBMS` class attribute to `DatabaseCheck` so integrations can declare their DBM platform identifier explicitly. The `dbms` property now returns `DBMS` when set and only falls back to the deprecated class-name derivation (with a warning) when it is not.
22 changes: 22 additions & 0 deletions datadog_checks_base/datadog_checks/base/checks/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@


class DatabaseCheck(AgentCheck):
#: Authoritative DBM platform identifier for this integration.
#: Subclasses should set this explicitly; it is the value surfaced by
#: :attr:`dbms` and used across DBM payloads, metric name prefixes and async jobs.
DBMS: str | None = None

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._agent_hostname = None
self._database_identifier = None
self._dbms_fallback_warning_logged = False
self.tag_manager = TagManager()

def database_monitoring_query_sample(self, raw_event: str):
Expand Down Expand Up @@ -110,6 +116,22 @@ def agent_hostname(self) -> str:

@property
def dbms(self) -> str:
"""
The DBM platform identifier for this integration.

Returns the :attr:`DBMS` class attribute when set. Integrations that have not yet declared
``DBMS`` fall back to a deprecated derivation from the class name; that fallback is
unreliable (it only matches for some integrations) and will be removed in a future version.
"""
if self.DBMS is not None:
return self.DBMS
if not self._dbms_fallback_warning_logged:
self.log.warning(
"%s does not set the `DBMS` class attribute; falling back to a name-derived value. "
"This fallback is deprecated and will be removed; set `DBMS` explicitly.",
type(self).__name__,
)
self._dbms_fallback_warning_logged = True
return self.__class__.__name__.lower()

@property
Expand Down
Loading