Skip to content

Commit 9c1159c

Browse files
P403n1x87majorgreys
authored andcommitted
chore(debugging): general coding improvements (#6931)
We improve some of the coding in the debugging area to make the logic easier to follow and to remove some unnecessary complexity. ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed. If no release note is required, add label `changelog/no-changelog`. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [ ] Title is accurate. - [ ] No unnecessary changes are introduced. - [ ] Description motivates each change. - [ ] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [ ] Testing strategy adequately addresses listed risk(s). - [ ] Change is maintainable (easy to change, telemetry, documentation). - [ ] Release note makes sense to a user of the library. - [ ] Reviewer has explicitly acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment. - [ ] Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) - [ ] If this PR touches code that signs or publishes builds or packages, or handles credentials of any kind, I've requested a review from `@DataDog/security-design-and-guidance`. - [ ] This PR doesn't touch any of that.
1 parent a027b1f commit 9c1159c

File tree

4 files changed

+29
-25
lines changed

4 files changed

+29
-25
lines changed

ddtrace/debugging/_debugger.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,9 @@ def _inject_probes(self, probes):
489489
# type: (List[LineProbe]) -> None
490490
for probe in probes:
491491
if probe not in self._probe_registry:
492+
if len(self._probe_registry) >= di_config.max_probes:
493+
log.warning("Too many active probes. Ignoring new ones.")
494+
return
492495
log.debug("[%s][P: %s] Received new %s.", os.getpid(), os.getppid(), probe)
493496
self._probe_registry.register(probe)
494497

@@ -609,6 +612,10 @@ def _probe_wrapping_hook(self, module):
609612
def _wrap_functions(self, probes):
610613
# type: (List[FunctionProbe]) -> None
611614
for probe in probes:
615+
if len(self._probe_registry) >= di_config.max_probes:
616+
log.warning("Too many active probes. Ignoring new ones.")
617+
return
618+
612619
self._probe_registry.register(probe)
613620
try:
614621
assert probe.module is not None # nosec
@@ -662,9 +669,6 @@ def _unwrap_functions(self, probes):
662669
def _on_configuration(self, event, probes):
663670
# type: (ProbePollerEventType, Iterable[Probe]) -> None
664671
log.debug("[%s][P: %s] Received poller event %r with probes %r", os.getpid(), os.getppid(), event, probes)
665-
if len(list(probes)) + len(self._probe_registry) > di_config.max_probes:
666-
log.warning("Too many active probes. Ignoring new ones.")
667-
return
668672

669673
if event == ProbePollerEvent.STATUS_UPDATE:
670674
self._probe_registry.log_probes_status()

ddtrace/debugging/_probe/remoteconfig.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -328,27 +328,30 @@ def _exec_callback(self, data, test_tracer=None):
328328
self._send_status_update()
329329
self._status_timestamp = next(self._status_timestamp_sequence)
330330

331-
if data:
332-
metadatas = data["metadata"]
333-
rc_configs = data["config"]
334-
# DEV: We emit a status update event here to avoid having to spawn a
335-
# separate thread for this.
336-
log.debug("[%s][P: %s] Dynamic Instrumentation Updated", os.getpid(), os.getppid())
337-
for idx in range(len(rc_configs)):
338-
if metadatas[idx] is None:
339-
log.debug("[%s][P: %s] Dynamic Instrumentation, no RCM metadata", os.getpid(), os.getppid())
340-
return
341-
342-
self._update_probes_for_config(metadatas[idx]["id"], rc_configs[idx])
331+
if not data:
332+
# Nothing else to do.
333+
return
334+
335+
log.debug("[%s][P: %s] Dynamic Instrumentation Updated", os.getpid(), os.getppid())
336+
for metadata, config in zip(data["metadata"], data["config"]):
337+
if metadata is None:
338+
log.debug(
339+
"[%s][P: %s] Dynamic Instrumentation: no RCM metadata for configuration; skipping",
340+
os.getpid(),
341+
os.getppid(),
342+
)
343+
continue
344+
345+
self._update_probes_for_config(metadata["id"], config)
343346

344347
def _send_status_update(self):
345348
log.debug(
346-
"[%s][P: %s] Dynamic Instrumentation,Emitting probe status log messages",
349+
"[%s][P: %s] Dynamic Instrumentation: emitting probe status log messages",
347350
os.getpid(),
348351
os.getppid(),
349352
)
350-
probes = [probe for config in self._configs.values() for probe in config.values()]
351-
self._callback(ProbePollerEvent.STATUS_UPDATE, probes)
353+
354+
self._callback(ProbePollerEvent.STATUS_UPDATE, [])
352355

353356
def _dispatch_probe_events(self, prev_probes, next_probes):
354357
# type: (Dict[str, Probe], Dict[str, Probe]) -> None

tests/debugging/exception/test_auto_instrument.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ def c(foo=42):
121121
assert len(d.test_queue) == 3
122122

123123
snapshots = {str(s.uuid): s for s in d.test_queue}
124-
print(snapshots.keys())
125124

126125
if PY < (3, 0):
127126
stacks = [["c", "b_chain"], ["b_chain"], ["a"]]
@@ -137,8 +136,6 @@ def c(foo=42):
137136

138137
info = {k: v for k, v in enumerate(stacks[n], start=1)}
139138

140-
print(span._meta["error.stack"], info)
141-
142139
for i in range(1, len(info) + 1):
143140
fn = info[i]
144141

tests/debugging/probe/test_remoteconfig.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ def callback(e, ps, *args, **kwargs):
339339
(ProbePollerEvent.NEW_PROBES, frozenset(["probe4", "probe1", "probe2", "probe3"])),
340340
(ProbePollerEvent.DELETED_PROBES, frozenset(["probe1"])),
341341
(ProbePollerEvent.NEW_PROBES, frozenset(["probe5"])),
342-
(ProbePollerEvent.STATUS_UPDATE, frozenset(["probe4", "probe2", "probe3", "probe5"])),
342+
(ProbePollerEvent.STATUS_UPDATE, frozenset()),
343343
}, events
344344
finally:
345345
di_config.diagnostics_interval = old_interval
@@ -427,7 +427,7 @@ def cb(e, ps):
427427
(ProbePollerEvent.NEW_PROBES, frozenset({"probe1"})),
428428
(ProbePollerEvent.NEW_PROBES, frozenset({"probe2"})),
429429
(ProbePollerEvent.NEW_PROBES, frozenset({"probe3"})),
430-
(ProbePollerEvent.STATUS_UPDATE, frozenset({"probe1", "probe2", "probe3"})),
430+
(ProbePollerEvent.STATUS_UPDATE, frozenset()),
431431
}
432432

433433
# remove configuration
@@ -438,7 +438,7 @@ def cb(e, ps):
438438
(ProbePollerEvent.NEW_PROBES, frozenset({"probe1"})),
439439
(ProbePollerEvent.NEW_PROBES, frozenset({"probe2"})),
440440
(ProbePollerEvent.NEW_PROBES, frozenset({"probe3"})),
441-
(ProbePollerEvent.STATUS_UPDATE, frozenset({"probe1", "probe2", "probe3"})),
441+
(ProbePollerEvent.STATUS_UPDATE, frozenset()),
442442
(ProbePollerEvent.DELETED_PROBES, frozenset({"probe2"})),
443443
}
444444

@@ -579,7 +579,7 @@ def cb(e, ps):
579579
(ProbePollerEvent.STATUS_UPDATE, frozenset()),
580580
(ProbePollerEvent.NEW_PROBES, frozenset(["probe1"])),
581581
(ProbePollerEvent.MODIFIED_PROBES, frozenset(["probe1"])),
582-
(ProbePollerEvent.STATUS_UPDATE, frozenset(["probe1"])),
582+
(ProbePollerEvent.STATUS_UPDATE, frozenset()),
583583
]
584584
finally:
585585
di_config.diagnostics_interval = old_interval

0 commit comments

Comments
 (0)