Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use zip instead of tar for the tracer flare [backport 2.10] #10078

Merged
merged 5 commits into from
Sep 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions ddtrace/internal/flare/flare.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
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
from ddtrace.internal.utils.http import get_connection


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")
Expand Down Expand Up @@ -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"

Expand All @@ -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,
Expand Down
Loading