Skip to content

Print traceback in case of InfraError in Static Quality Gates #39048

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

Merged
merged 2 commits into from
Jul 21, 2025
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions tasks/quality_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ def parse_and_trigger_gates(ctx, config_path=GATE_CONFIG_PATH):
gate_states.append({"name": gate, "state": False, "error_type": "AssertionError", "message": str(e)})
except InfraError as e:
print(f"Gate {gate} flaked ! (InfraError)\n Restarting the job...")
traceback.print_exception(e)
ctx.run("datadog-ci tag --level job --tags static_quality_gates:\"restart\"")
raise Exit(code=42) from e
except Exception:
Expand Down
28 changes: 27 additions & 1 deletion tasks/unit_tests/quality_gates_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
from unittest.mock import ANY, MagicMock, patch

from invoke import Context, MockContext, Result
from invoke.exceptions import Exit

from tasks.quality_gates import display_pr_comment, generate_new_quality_gate_config
from tasks.libs.package.size import InfraError
from tasks.quality_gates import display_pr_comment, generate_new_quality_gate_config, parse_and_trigger_gates
from tasks.static_quality_gates.lib.docker_agent_lib import calculate_image_on_disk_size
from tasks.static_quality_gates.lib.gates_lib import GateMetricHandler

Expand All @@ -16,6 +18,30 @@ def __init__(self, metrics):


class TestQualityGatesConfigUpdate(unittest.TestCase):
@patch.dict(
'os.environ',
{
'CI_COMMIT_REF_NAME': 'pikachu',
'CI_COMMIT_BRANCH': 'sequoia',
'CI_COMMIT_REF_SLUG': 'pikachu',
'BUCKET_BRANCH': 'main',
},
)
@patch("builtins.__import__")
def test_parse_and_trigger_gates_infra_error(self, mock_import):
ctx = MockContext(
run={
"datadog-ci tag --level job --tags static_quality_gates:\"restart\"": Result("Done"),
"datadog-ci tag --level job --tags static_quality_gates:\"failure\"": Result("Done"),
}
)
mock_quality_gates_module = MagicMock()
mock_quality_gates_module.some_gate_high.entrypoint.side_effect = InfraError("Test infra error message")
mock_import.return_value = mock_quality_gates_module
with self.assertRaises(Exit) as cm:
parse_and_trigger_gates(ctx, "tasks/unit_tests/testdata/quality_gate_config_test.yml")
assert "Test infra error message" in str(cm.exception)

def test_one_gate_update(self):
with open("tasks/unit_tests/testdata/quality_gate_config_test.yml") as f:
new_config, saved_amount = generate_new_quality_gate_config(
Expand Down