-
Notifications
You must be signed in to change notification settings - Fork 412
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(tracer): add dataclass for tracer flare RC configs (#8969)
## Overview Adds two dataclasses: `FlarePrepRequest` and `FlareSendRequest` that get ingested by the `Flare.prep()` and `Flare.send()` methods, ensuring that we always get a valid RC config when these methods are called. ## 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] Risks are described (performance impact, potential for breakage, maintainability) - [x] Change is maintainable (easy to change, telemetry, documentation) - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed or label `changelog/no-changelog` is set - [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)) - [x] If this PR changes the public interface, I've notified `@DataDog/apm-tees`. ## Reviewer Checklist - [ ] Title is accurate - [ ] All changes are related to the pull request's stated goal - [ ] Description motivates each change - [ ] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - [ ] Testing strategy adequately addresses listed risks - [ ] Change is maintainable (easy to change, telemetry, documentation) - [ ] Release note makes sense to a user of the library - [ ] 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)
- Loading branch information
1 parent
52e3175
commit c46f79b
Showing
2 changed files
with
86 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,26 +11,17 @@ | |
from ddtrace.internal.flare import TRACER_FLARE_DIRECTORY | ||
from ddtrace.internal.flare import TRACER_FLARE_FILE_HANDLER_NAME | ||
from ddtrace.internal.flare import Flare | ||
from ddtrace.internal.flare import FlareSendRequest | ||
from ddtrace.internal.logger import get_logger | ||
|
||
|
||
DEBUG_LEVEL_INT = logging.DEBUG | ||
|
||
|
||
class TracerFlareTests(unittest.TestCase): | ||
mock_agent_config = [{"name": "flare-log-level", "config": {"log_level": "DEBUG"}}] | ||
mock_agent_task = [ | ||
False, | ||
{ | ||
"args": { | ||
"case_id": "1111111", | ||
"hostname": "myhostname", | ||
"user_handle": "[email protected]", | ||
}, | ||
"task_type": "tracer_flare", | ||
"uuid": "d53fc8a4-8820-47a2-aa7d-d565582feb81", | ||
}, | ||
] | ||
mock_flare_send_request = FlareSendRequest( | ||
case_id="1111111", hostname="myhostname", email="[email protected]" | ||
) | ||
|
||
def setUp(self): | ||
self.flare_uuid = uuid.uuid4() | ||
|
@@ -57,7 +48,7 @@ def test_single_process_success(self): | |
""" | ||
ddlogger = get_logger("ddtrace") | ||
|
||
self.flare.prepare(self.mock_agent_config) | ||
self.flare.prepare("DEBUG") | ||
|
||
file_handler = self._get_handler() | ||
valid_logger_level = self.flare._get_valid_logger_level(DEBUG_LEVEL_INT) | ||
|
@@ -70,7 +61,7 @@ def test_single_process_success(self): | |
|
||
# Sends request to testagent | ||
# This just validates the request params | ||
self.flare.send(self.mock_agent_task) | ||
self.flare.send(self.mock_flare_send_request) | ||
|
||
def test_single_process_partial_failure(self): | ||
""" | ||
|
@@ -83,7 +74,7 @@ def test_single_process_partial_failure(self): | |
# Mock the partial failure | ||
with mock.patch("json.dump") as mock_json: | ||
mock_json.side_effect = Exception("file issue happened") | ||
self.flare.prepare(self.mock_agent_config) | ||
self.flare.prepare("DEBUG") | ||
|
||
file_handler = self._get_handler() | ||
assert file_handler is not None | ||
|
@@ -93,7 +84,7 @@ def test_single_process_partial_failure(self): | |
assert os.path.exists(self.flare_file_path) | ||
assert not os.path.exists(self.config_file_path) | ||
|
||
self.flare.send(self.mock_agent_task) | ||
self.flare.send(self.mock_flare_send_request) | ||
|
||
def test_multiple_process_success(self): | ||
""" | ||
|
@@ -103,10 +94,10 @@ def test_multiple_process_success(self): | |
num_processes = 3 | ||
|
||
def handle_agent_config(): | ||
self.flare.prepare(self.mock_agent_config) | ||
self.flare.prepare("DEBUG") | ||
|
||
def handle_agent_task(): | ||
self.flare.send(self.mock_agent_task) | ||
self.flare.send(self.mock_flare_send_request) | ||
|
||
# Create multiple processes | ||
for _ in range(num_processes): | ||
|
@@ -134,19 +125,19 @@ def test_multiple_process_partial_failure(self): | |
""" | ||
processes = [] | ||
|
||
def do_tracer_flare(agent_config, agent_task): | ||
self.flare.prepare(agent_config) | ||
def do_tracer_flare(prep_request, send_request): | ||
self.flare.prepare(prep_request) | ||
# Assert that only one process wrote its file successfully | ||
# We check for 2 files because it will generate a log file and a config file | ||
assert 2 == len(os.listdir(self.flare_dir)) | ||
self.flare.send(agent_task) | ||
self.flare.send(send_request) | ||
|
||
# Create successful process | ||
p = multiprocessing.Process(target=do_tracer_flare, args=(self.mock_agent_config, self.mock_agent_task)) | ||
p = multiprocessing.Process(target=do_tracer_flare, args=("DEBUG", self.mock_flare_send_request)) | ||
processes.append(p) | ||
p.start() | ||
# Create failing process | ||
p = multiprocessing.Process(target=do_tracer_flare, args=(None, self.mock_agent_task)) | ||
p = multiprocessing.Process(target=do_tracer_flare, args=(None, self.mock_flare_send_request)) | ||
processes.append(p) | ||
p.start() | ||
for p in processes: | ||
|
@@ -158,7 +149,7 @@ def test_no_app_logs(self): | |
file, just the tracer logs | ||
""" | ||
app_logger = Logger(name="my-app", level=DEBUG_LEVEL_INT) | ||
self.flare.prepare(self.mock_agent_config) | ||
self.flare.prepare("DEBUG") | ||
|
||
app_log_line = "this is an app log" | ||
app_logger.debug(app_log_line) | ||
|