Skip to content
This repository was archived by the owner on May 29, 2026. It is now read-only.

Commit 092c1a7

Browse files
feat: Send upload size to upload request and cli version with API requests
1 parent 45e518e commit 092c1a7

7 files changed

Lines changed: 67 additions & 23 deletions

File tree

codecov-cli/codecov_cli/services/commit/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import typing
44

5+
from codecov_cli import __version__ as codecov_cli_version
56
from codecov_cli.helpers.config import CODECOV_INGEST_URL
67
from codecov_cli.helpers.encoder import encode_slug
78
from codecov_cli.helpers.request import (
@@ -75,6 +76,7 @@ def send_commit_data(
7576
"commitid": commit_sha,
7677
"parent_commit_id": parent_sha,
7778
"pullid": pr,
79+
"version": codecov_cli_version,
7880
}
7981

8082
upload_url = enterprise_url or CODECOV_INGEST_URL

codecov-cli/codecov_cli/services/empty_upload/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import logging
33

4+
from codecov_cli import __version__ as codecov_cli_version
45
from codecov_cli.helpers.config import CODECOV_API_URL
56
from codecov_cli.helpers.encoder import encode_slug
67
from codecov_cli.helpers.request import (
@@ -32,6 +33,7 @@ def empty_upload_logic(
3233
data={
3334
"cli_args": args,
3435
"should_force": should_force,
36+
"version": codecov_cli_version,
3537
},
3638
)
3739
log_warnings_and_errors_if_any(sending_result, "Empty Upload", fail_on_error)

codecov-cli/codecov_cli/services/report/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
import time
44
import typing
55

6-
import requests
7-
6+
from codecov_cli import __version__ as codecov_cli_version
87
from codecov_cli.helpers import request
98
from codecov_cli.helpers.config import CODECOV_API_URL, CODECOV_INGEST_URL
109
from codecov_cli.helpers.encoder import encode_slug
@@ -58,6 +57,7 @@ def send_create_report_request(
5857
data = {
5958
"cli_args": args,
6059
"code": code,
60+
"version": codecov_cli_version,
6161
}
6262
headers = get_token_header(token)
6363
upload_url = enterprise_url or CODECOV_INGEST_URL
@@ -103,6 +103,7 @@ def send_reports_result_request(
103103
):
104104
data = {
105105
"cli_args": args,
106+
"version": codecov_cli_version,
106107
}
107108
headers = get_token_header(token)
108109
upload_url = enterprise_url or CODECOV_API_URL

codecov-cli/codecov_cli/services/upload/upload_sender.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import json
33
import logging
44
import typing
5-
import sys
65
import zlib
76
from typing import Any, Dict
87

@@ -97,6 +96,8 @@ def send_upload_data(
9796
reports_payload = self._generate_payload(
9897
upload_data, env_vars, report_type
9998
)
99+
reports_payload_size = len(reports_payload)
100+
data["report_payload_bytes"] = reports_payload_size
100101

101102
with sentry_sdk.start_span(name="upload_sender_storage_request"):
102103
logger.debug("Sending upload request to Codecov")
@@ -126,9 +127,8 @@ def send_upload_data(
126127
put_url = resp_json_obj["raw_upload_location"]
127128

128129
with sentry_sdk.start_span(name="upload_sender_storage") as storage_span:
129-
payload_size = sys.getsizeof(reports_payload)
130-
storage_span.set_data("payload_size", payload_size)
131-
logger.info(f"Sending upload ({payload_size} bytes) to storage")
130+
storage_span.set_data("payload_size", reports_payload_size)
131+
logger.info(f"Sending upload ({reports_payload_size} bytes) to storage")
132132
resp_from_storage = send_put_request(put_url, data=reports_payload)
133133

134134
return resp_from_storage

codecov-cli/codecov_cli/services/upload_completion/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import logging
33

4+
from codecov_cli import __version__ as codecov_cli_version
45
from codecov_cli.helpers.config import CODECOV_API_URL
56
from codecov_cli.helpers.encoder import encode_slug
67
from codecov_cli.helpers.request import (
@@ -27,6 +28,7 @@ def upload_completion_logic(
2728
url = f"{upload_url}/upload/{git_service}/{encoded_slug}/commits/{commit_sha}/upload-complete"
2829
data = {
2930
"cli_args": args,
31+
"version": codecov_cli_version,
3032
}
3133
sending_result = send_post_request(url=url, data=data, headers=headers)
3234
log_warnings_and_errors_if_any(

codecov-cli/tests/helpers/test_upload_sender.py

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,51 @@
5252
"ci_service": "ci_service",
5353
"git_service": "github",
5454
}
55+
56+
57+
def _upload_ingest_post_json_base(*, file_not_found: bool) -> dict:
58+
return {
59+
"ci_service": "ci_service",
60+
"ci_url": "build_url",
61+
"cli_args": None,
62+
"env": {},
63+
"flags": "flags",
64+
"job_code": "job_code",
65+
"name": "name",
66+
"version": codecov_cli_version,
67+
"file_not_found": file_not_found,
68+
}
69+
70+
71+
_report_payload_bytes_coverage = len(
72+
UploadSender()._generate_payload(
73+
upload_collection, {}, ReportType.COVERAGE
74+
)
75+
)
76+
5577
request_data = {
56-
"ci_service": "ci_service",
57-
"ci_url": "build_url",
58-
"cli_args": None,
59-
"env": {},
60-
"flags": "flags",
61-
"job_code": "job_code",
62-
"name": "name",
63-
"version": codecov_cli_version,
64-
"file_not_found": False,
78+
**_upload_ingest_post_json_base(file_not_found=False),
79+
"report_payload_bytes": _report_payload_bytes_coverage,
6580
}
6681

6782

83+
def _test_results_ingest_post_json(upload_data: UploadCollectionResult) -> dict:
84+
# get_url_and_possibly_update_data always sets data["file_not_found"] from its
85+
# default (False), overwriting the value set earlier when no test files exist.
86+
return {
87+
**_upload_ingest_post_json_base(file_not_found=False),
88+
"slug": encode_slug("org/repo"),
89+
"branch": "branch",
90+
"commit": random_sha,
91+
"service": "github",
92+
"report_payload_bytes": len(
93+
UploadSender()._generate_payload(
94+
upload_data, {}, ReportType.TEST_RESULTS
95+
)
96+
),
97+
}
98+
99+
68100
@pytest.fixture
69101
def mocked_responses():
70102
with responses.RequestsMock() as rsps:
@@ -266,18 +298,20 @@ def test_upload_sender_post_called_with_right_parameters_test_results(
266298
):
267299
headers = {"Authorization": f"token {random_token}"}
268300

269-
mocked_legacy_upload_endpoint.match = [
270-
matchers.json_params_matcher(request_data),
271-
matchers.header_matcher(headers),
272-
]
273-
274301
ta_upload_collection = deepcopy(upload_collection)
275302

276303
test_path = tmp_path / "test_results.xml"
277304
test_path.write_bytes(b"test_data")
278305

279306
ta_upload_collection.files = [UploadCollectionResultFile(test_path)]
280307

308+
mocked_test_results_endpoint.match = [
309+
matchers.json_params_matcher(
310+
_test_results_ingest_post_json(ta_upload_collection)
311+
),
312+
matchers.header_matcher(headers),
313+
]
314+
281315
sending_result = UploadSender().send_upload_data(
282316
ta_upload_collection,
283317
random_sha,
@@ -309,10 +343,9 @@ def test_upload_sender_post_called_with_right_parameters_test_results_file_not_f
309343
):
310344
headers = {"Authorization": f"token {random_token}"}
311345

312-
req_data = deepcopy(request_data)
313-
req_data["file_not_found"] = True
346+
req_data = _test_results_ingest_post_json(upload_collection)
314347

315-
mocked_legacy_upload_endpoint.match = [
348+
mocked_test_results_endpoint_file_not_found.match = [
316349
matchers.json_params_matcher(req_data),
317350
matchers.header_matcher(headers),
318351
]

codecov-cli/tests/services/commit/test_commit_service.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from click.testing import CliRunner
44

5+
from codecov_cli import __version__ as codecov_cli_version
56
from codecov_cli.services.commit import create_commit_logic, send_commit_data
67
from codecov_cli.types import RequestError, RequestResult, RequestResultWarning
78
from tests.test_helpers import parse_outstreams_into_log_lines
@@ -171,6 +172,7 @@ def test_commit_sender_with_forked_repo(mocker):
171172
"commitid": "commit_sha",
172173
"parent_commit_id": "parent_sha",
173174
"pullid": "1",
175+
"version": codecov_cli_version,
174176
},
175177
headers=None,
176178
)
@@ -201,6 +203,7 @@ def test_commit_without_token(mocker):
201203
"commitid": "commit_sha",
202204
"parent_commit_id": "parent_sha",
203205
"pullid": "1",
206+
"version": codecov_cli_version,
204207
},
205208
headers=None,
206209
)
@@ -232,6 +235,7 @@ def test_commit_sender_with_forked_repo_bad_branch(mocker):
232235
"commitid": "commit_sha",
233236
"parent_commit_id": "parent_sha",
234237
"pullid": "1",
238+
"version": codecov_cli_version,
235239
},
236240
headers=None,
237241
)

0 commit comments

Comments
 (0)