Skip to content

Commit e529a0b

Browse files
authored
[DBMON-6589] Eliminate reference cycle in Postgres diagnose (DataDog#23647)
* Eliminate reference cycle in diagnose * Add changelog
1 parent 772b9c9 commit e529a0b

3 files changed

Lines changed: 8 additions & 18 deletions

File tree

postgres/changelog.d/23647.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Eliminate reference cycle in diagnostic instrumentation

postgres/datadog_checks/postgres/diagnose.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
RECOMMENDED_TRACK_ACTIVITY_QUERY_SIZE = 4096
3333

3434

35+
def run_diagnostics(check):
36+
"""Entry point for ``Diagnosis.register()``; creates a short-lived worker per invocation."""
37+
PostgresDiagnose(check)._run()
38+
39+
3540
class PostgresDiagnose:
3641
"""Explicit pre-flight diagnostics for `datadog-agent diagnose`."""
3742

@@ -42,21 +47,6 @@ def __init__(self, check):
4247
# when shared_preload_libraries is empty). Reset at the top of the first orchestrator.
4348
self._failed = set()
4449

45-
# -- registration ---------------------------------------------------------
46-
47-
def register(self):
48-
"""Register the diagnostic entry point with the check's Diagnosis object.
49-
50-
Idempotent: re-invoking `register` on the same Diagnosis object is a no-op.
51-
``Diagnosis.register`` extends an internal list, so without this guard a
52-
repeated call would stack the entry point and produce N× the diagnostics.
53-
"""
54-
d = self._check.diagnosis
55-
if getattr(d, '_postgres_diagnostics_registered', False):
56-
return
57-
d._postgres_diagnostics_registered = True
58-
d.register(self._run)
59-
6050
# -- orchestrator ---------------------------------------------------------
6151

6252
def _run(self):

postgres/datadog_checks/postgres/postgres.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
from .__about__ import __version__
4949
from .config import build_config, sanitize
50-
from .diagnose import PostgresDiagnose
50+
from .diagnose import run_diagnostics
5151
from .util import (
5252
ANALYZE_PROGRESS_METRICS,
5353
AWS_RDS_HOSTNAME_SUFFIX,
@@ -191,8 +191,7 @@ def __init__(self, name, init_config, instances):
191191
ttl=self._config.database_instance_collection_interval,
192192
) # type: TTLCache
193193

194-
# Register explicit pre-flight diagnostics for `datadog-agent diagnose`.
195-
PostgresDiagnose(self).register()
194+
self.diagnosis.register(functools.partial(run_diagnostics, self))
196195

197196
def _submit_initialization_health_event(self):
198197
try:

0 commit comments

Comments
 (0)