From 3977baddef9855ec317d2b4eee1d6ae722b917f6 Mon Sep 17 00:00:00 2001 From: erikayasuda <153395705+erikayasuda@users.noreply.github.com> Date: Mon, 5 Aug 2024 10:31:11 -0400 Subject: [PATCH] fix: use zip instead of tar for the tracer flare (#10019) System tests require the flare to be a zip, not a tar file. ## 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 - [x] 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 26682f8bcdb2eed604699b30c93dba64b6eabe94) --- ddtrace/internal/flare/flare.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ddtrace/internal/flare/flare.py b/ddtrace/internal/flare/flare.py index 45a555c1a86..b37d6e8e013 100644 --- a/ddtrace/internal/flare/flare.py +++ b/ddtrace/internal/flare/flare.py @@ -7,10 +7,10 @@ import os import pathlib import shutil -import tarfile from typing import Dict from typing import Optional from typing import Tuple +import zipfile from ddtrace._logger import _add_file_handler from ddtrace.internal.logger import get_logger @@ -18,7 +18,7 @@ TRACER_FLARE_DIRECTORY = "tracer_flare" -TRACER_FLARE_TAR = pathlib.Path("tracer_flare.tar") +TRACER_FLARE_ZIP = pathlib.Path("tracer_flare.zip") TRACER_FLARE_ENDPOINT = "/tracer_flare/v1" TRACER_FLARE_FILE_HANDLER_NAME = "tracer_flare_file_handler" TRACER_FLARE_LOCK = pathlib.Path("tracer_flare.lock") @@ -163,11 +163,11 @@ def revert_configs(self): ddlogger.setLevel(self.original_log_level) def _generate_payload(self, params: Dict[str, str]) -> Tuple[dict, bytes]: - tar_stream = io.BytesIO() - with tarfile.open(fileobj=tar_stream, mode="w") as tar: + zip_stream = io.BytesIO() + with zipfile.ZipFile(zip_stream, mode="w", compression=zipfile.ZIP_DEFLATED) as zipf: for flare_file_name in self.flare_dir.iterdir(): - tar.add(flare_file_name) - tar_stream.seek(0) + zipf.write(flare_file_name, arcname=flare_file_name.name) + zip_stream.seek(0) newline = b"\r\n" @@ -181,9 +181,9 @@ def _generate_payload(self, params: Dict[str, str]) -> Tuple[dict, bytes]: body.write(b"%s%s" % (encoded_value, newline)) body.write(b"--" + boundary + newline) - body.write((b'Content-Disposition: form-data; name="flare_file"; filename="flare.tar"%s' % newline)) + body.write((b'Content-Disposition: form-data; name="flare_file"; filename="flare.zip"%s' % newline)) body.write(b"Content-Type: application/octet-stream%s%s" % (newline, newline)) - body.write(tar_stream.getvalue() + newline) + body.write(zip_stream.getvalue() + newline) body.write(b"--" + boundary + b"--") headers = { "Content-Type": b"multipart/form-data; boundary=%s" % boundary,