Skip to content

Commit

Permalink
fix(flare): fix tracer flare (#10985)
Browse files Browse the repository at this point in the history
Tracer flares were failing due to AGENT_CONFIG items possibly containing
pure booleans, and not just dictionaries. Example:
```
AGENT_CONFIG=[True, {...config...}, ...]
```
This would break the flare because it would be expecting only dicts.

## Checklist
- [x] PR author has checked that all the criteria below are met
- The PR description includes an overview of the change
- The PR description articulates the motivation for the change
- The change includes tests OR the PR description describes a testing
strategy
- The PR description notes risks associated with the change, if any
- Newly-added code is easy to change
- The change follows the [library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
- The change includes or references documentation updates if necessary
- Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))

## Reviewer Checklist
- [ ] Reviewer has checked that all the criteria below are met
- Title is accurate
- All changes are related to the pull request's stated goal
- Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- Testing strategy adequately addresses listed risks
- Newly-added code is easy to change
- Release note makes sense to a user of the library
- If necessary, author has 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)

(cherry picked from commit a482830)
  • Loading branch information
erikayasuda authored and github-actions[bot] committed Oct 17, 2024
1 parent f71f4f3 commit d1fe766
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
6 changes: 4 additions & 2 deletions ddtrace/internal/flare/_subscribers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def has_stale_flare(self) -> bool:
return flare_age >= stale_age
return False

def _get_data_from_connector_and_exec(self):
def _get_data_from_connector_and_exec(self, _=None):
if self.has_stale_flare():
log.info(
"Tracer flare request started at %s is stale, reverting "
Expand Down Expand Up @@ -67,6 +67,7 @@ def _get_data_from_connector_and_exec(self):
str(self.current_request_start),
)
continue
log.info("Preparing tracer flare")
if _prepare_tracer_flare(self.flare, configs):
self.current_request_start = datetime.now()
elif product_type == "AGENT_TASK":
Expand All @@ -75,7 +76,8 @@ def _get_data_from_connector_and_exec(self):
if self.current_request_start is None:
log.warning("There is no tracer flare job to complete. Skipping new request.")
continue
log.info("Generating and sending tracer flare")
if _generate_tracer_flare(self.flare, configs):
self.current_request_start = None
else:
log.debug("Received unexpected product type for tracer flare: {}", product_type)
log.warning("Received unexpected product type for tracer flare: {}", product_type)
1 change: 0 additions & 1 deletion ddtrace/internal/flare/flare.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ def send(self, flare_send_req: FlareSendRequest):
before sending the flare.
"""
self.revert_configs()

# We only want the flare to be sent once, even if there are
# multiple tracer instances
lock_path = self.flare_dir / TRACER_FLARE_LOCK
Expand Down
18 changes: 16 additions & 2 deletions ddtrace/internal/flare/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def __init__(self, callback: Callable, flare: Flare):

def _handle_tracer_flare(flare: Flare, data: dict, cleanup: bool = False):
if cleanup:
log.info("Reverting tracer flare configurations and cleaning up any generated files")
flare.revert_configs()
flare.clean_up_files()
return
Expand All @@ -51,7 +52,7 @@ def _handle_tracer_flare(flare: Flare, data: dict, cleanup: bool = False):
log.warning("Received unexpected tracer flare product type: %s", product_type)


def _prepare_tracer_flare(flare: Flare, configs: List[dict]) -> bool:
def _prepare_tracer_flare(flare: Flare, configs: List[Any]) -> bool:
"""
Update configurations to start sending tracer logs to a file
to be sent in a flare later.
Expand All @@ -60,7 +61,13 @@ def _prepare_tracer_flare(flare: Flare, configs: List[dict]) -> bool:
# AGENT_CONFIG is currently being used for multiple purposes
# We only want to prepare for a tracer flare if the config name
# starts with 'flare-log-level'
if not isinstance(c, dict):
log.debug("Config item is not type dict, received type %s instead. Skipping...", str(type(c)))
continue
if not c.get("name", "").startswith("flare-log-level"):
log.debug(
"Config item name does not start with flare-log-level, received %s instead. Skipping...", c.get("name")
)
continue

flare_log_level = c.get("config", {}).get("log_level").upper()
Expand All @@ -78,7 +85,14 @@ def _generate_tracer_flare(flare: Flare, configs: List[Any]) -> bool:
# AGENT_TASK is currently being used for multiple purposes
# We only want to generate the tracer flare if the task_type is
# 'tracer_flare'
if type(c) != dict or c.get("task_type") != "tracer_flare":
if not isinstance(c, dict):
log.debug("Config item is not type dict, received type %s instead. Skipping...", str(type(c)))
continue
if c.get("task_type") != "tracer_flare":
log.debug(
"Config item does not have the expected task_type. Expected [tracer_flare], received [%s]. Skipping...",
c.get("task_type"),
)
continue
args = c.get("args", {})
flare_request = FlareSendRequest(
Expand Down
5 changes: 5 additions & 0 deletions releasenotes/notes/fix-tracer-flare-e4003d01b434267a.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
tracing(flare): Resolves the issue where tracer flares would not be generated if unexpected
types were received in the AGENT_CONFIG remote configuration product.
2 changes: 1 addition & 1 deletion tests/internal/test_tracer_flare.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def write(self):


class TracerFlareSubscriberTests(TestCase):
agent_config = [{"name": "flare-log-level", "config": {"log_level": "DEBUG"}}]
agent_config = [False, {"name": "flare-log-level", "config": {"log_level": "DEBUG"}}]
agent_task = [
False,
{
Expand Down

0 comments on commit d1fe766

Please sign in to comment.