Skip to content

Commit

Permalink
chore: improve label analysis log if failed to calculate
Browse files Browse the repository at this point in the history
If Codecov fails to calculate label analysis (with an actual error),
the log line is borderline unusable, because it cointains too much text.

So these changes restrict the amount of info shown to include:
`head_commit`, `base_commit` and `external_id`. This info should allow
users to quickly check if the comparison is between the commits they expect,
and give them useful info to pass to the support team, so we can learn what happened.

Unfortunatelly at this points the errors are also useless. THey only state
"failed to calculate".
  • Loading branch information
giovanni-guidini committed Oct 17, 2023
1 parent 17bb885 commit 496d2e5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion codecov_cli/commands/labelanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,13 @@ def label_analysis(
if resp_json["state"] == "error":
logger.error(
"Request had problems calculating",
extra=dict(extra_log_attributes=dict(resp_json=resp_json)),
extra=dict(
extra_log_attributes=dict(
base_commit=resp_json["base_commit"],
head_commit=resp_json["head_commit"],
external_id=resp_json["external_id"],
)
),
)
_fallback_to_collected_labels(
collected_labels=requested_labels,
Expand Down
8 changes: 7 additions & 1 deletion tests/commands/test_invoke_labelanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,12 @@ def test_fallback_collected_labels_codecov_error_processing_label_analysis(
rsps.add(
responses.GET,
"https://api.codecov.io/labels/labels-analysis/label-analysis-request-id",
json={"state": "error"},
json={
"state": "error",
"external_id": "uuid4-external-id",
"base_commit": "BASE_COMMIT_SHA",
"head_commit": "HEAD_COMMIT_SHA",
},
)
cli_runner = CliRunner()
result = cli_runner.invoke(
Expand All @@ -526,6 +531,7 @@ def test_fallback_collected_labels_codecov_error_processing_label_analysis(
],
obj={},
)
print(result)
mock_get_runner.assert_called()
fake_runner.process_labelanalysis_result.assert_called_with(
{
Expand Down

0 comments on commit 496d2e5

Please sign in to comment.