-
Notifications
You must be signed in to change notification settings - Fork 57
feat: Send upload size to upload request and cli version with API requests #702
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,6 @@ | |
| import json | ||
| import logging | ||
| import typing | ||
| import sys | ||
| import zlib | ||
| from typing import Any, Dict | ||
|
|
||
|
|
@@ -92,11 +91,14 @@ def send_upload_data( | |
| commit_sha, | ||
| report_code, | ||
| upload_coverage, | ||
| file_not_found=file_not_found, | ||
| ) | ||
| # Data that goes to storage | ||
| reports_payload = self._generate_payload( | ||
| upload_data, env_vars, report_type | ||
| ) | ||
| reports_payload_size = len(reports_payload) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. have you compared this to what comes out of |
||
| data["report_payload_bytes"] = reports_payload_size | ||
|
|
||
| with sentry_sdk.start_span(name="upload_sender_storage_request"): | ||
| logger.debug("Sending upload request to Codecov") | ||
|
|
@@ -126,9 +128,8 @@ def send_upload_data( | |
| put_url = resp_json_obj["raw_upload_location"] | ||
|
|
||
| with sentry_sdk.start_span(name="upload_sender_storage") as storage_span: | ||
| payload_size = sys.getsizeof(reports_payload) | ||
| storage_span.set_data("payload_size", payload_size) | ||
| logger.info(f"Sending upload ({payload_size} bytes) to storage") | ||
| storage_span.set_data("payload_size", reports_payload_size) | ||
| logger.info(f"Sending upload ({reports_payload_size} bytes) to storage") | ||
| resp_from_storage = send_put_request(put_url, data=reports_payload) | ||
|
|
||
| return resp_from_storage | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,19 +52,51 @@ | |
| "ci_service": "ci_service", | ||
| "git_service": "github", | ||
| } | ||
|
|
||
|
|
||
| def _upload_ingest_post_json_base(*, file_not_found: bool) -> dict: | ||
| return { | ||
| "ci_service": "ci_service", | ||
| "ci_url": "build_url", | ||
| "cli_args": None, | ||
| "env": {}, | ||
| "flags": "flags", | ||
| "job_code": "job_code", | ||
| "name": "name", | ||
| "version": codecov_cli_version, | ||
| "file_not_found": file_not_found, | ||
| } | ||
|
|
||
|
|
||
| _report_payload_bytes_coverage = len( | ||
| UploadSender()._generate_payload( | ||
| upload_collection, {}, ReportType.COVERAGE | ||
| ) | ||
| ) | ||
|
|
||
| request_data = { | ||
| "ci_service": "ci_service", | ||
| "ci_url": "build_url", | ||
| "cli_args": None, | ||
| "env": {}, | ||
| "flags": "flags", | ||
| "job_code": "job_code", | ||
| "name": "name", | ||
| "version": codecov_cli_version, | ||
| "file_not_found": False, | ||
| **_upload_ingest_post_json_base(file_not_found=False), | ||
| "report_payload_bytes": _report_payload_bytes_coverage, | ||
| } | ||
|
|
||
|
|
||
| def _test_results_ingest_post_json( | ||
| upload_data: UploadCollectionResult, *, file_not_found: bool | ||
| ) -> dict: | ||
| return { | ||
| **_upload_ingest_post_json_base(file_not_found=file_not_found), | ||
| "slug": encode_slug("org/repo"), | ||
| "branch": "branch", | ||
| "commit": random_sha, | ||
| "service": "github", | ||
| "report_payload_bytes": len( | ||
| UploadSender()._generate_payload( | ||
| upload_data, {}, ReportType.TEST_RESULTS | ||
| ) | ||
| ), | ||
| } | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mocked_responses(): | ||
| with responses.RequestsMock() as rsps: | ||
|
|
@@ -266,18 +298,22 @@ def test_upload_sender_post_called_with_right_parameters_test_results( | |
| ): | ||
| headers = {"Authorization": f"token {random_token}"} | ||
|
|
||
| mocked_legacy_upload_endpoint.match = [ | ||
| matchers.json_params_matcher(request_data), | ||
| matchers.header_matcher(headers), | ||
| ] | ||
|
|
||
|
Comment on lines
-269
to
-273
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like it was incorrectly using the mocked_legacy_upload_endpoint even though this is a different endpoint. I think we want the mocked_test_results_endpoint (newly added below) which would match with the argument at line 295 and with the url designated in this function |
||
| ta_upload_collection = deepcopy(upload_collection) | ||
|
|
||
| test_path = tmp_path / "test_results.xml" | ||
| test_path.write_bytes(b"test_data") | ||
|
|
||
| ta_upload_collection.files = [UploadCollectionResultFile(test_path)] | ||
|
|
||
| mocked_test_results_endpoint.match = [ | ||
| matchers.json_params_matcher( | ||
| _test_results_ingest_post_json( | ||
| ta_upload_collection, file_not_found=False | ||
| ) | ||
| ), | ||
| matchers.header_matcher(headers), | ||
| ] | ||
|
|
||
| sending_result = UploadSender().send_upload_data( | ||
| ta_upload_collection, | ||
| random_sha, | ||
|
|
@@ -309,10 +345,11 @@ def test_upload_sender_post_called_with_right_parameters_test_results_file_not_f | |
| ): | ||
| headers = {"Authorization": f"token {random_token}"} | ||
|
|
||
| req_data = deepcopy(request_data) | ||
| req_data["file_not_found"] = True | ||
| req_data = _test_results_ingest_post_json( | ||
| upload_collection, file_not_found=True | ||
| ) | ||
|
|
||
| mocked_legacy_upload_endpoint.match = [ | ||
| mocked_test_results_endpoint_file_not_found.match = [ | ||
| matchers.json_params_matcher(req_data), | ||
| matchers.header_matcher(headers), | ||
| ] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seemed like a missed line from before. We weren't passing in the file_not_found value that is defined higher up at line 59/61 and self.get_url_and_possibly_update_data() takes it in with a default value of "False" so it would always just set `data['file_not_found'] to False
Please review this in particular