Skip to content

Commit

Permalink
fix: use zip instead of tar for the tracer flare (#10019)
Browse files Browse the repository at this point in the history
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 26682f8)
  • Loading branch information
erikayasuda authored and taegyunkim committed Aug 5, 2024
1 parent a554900 commit 3977bad
Showing 1 changed file with 8 additions and 8 deletions.
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

0 comments on commit 3977bad

Please sign in to comment.