Skip to content
Draft
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
6 changes: 6 additions & 0 deletions bot/code_review_bot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ def __init__(self):
# Indexed by their Phabricator ID
self.user_blacklist = {}

# bugbug test configuration
self.bugbug_enabled_repositories = ["firefox-autoland"]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize that a bunch of config for bugbug is in tc secrets. I wasn't sure if that was helpful or desired here; I can make that adjustment if needed.

# Because it's unclear how much load this will add, this is being rolled out gradually.
self.bugbug_enabled_percent = 0.1

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect variable name

self.bugbug_optimize_strategy = "gecko_taskgraph.optimize:tryselect.bugbug_reduced_manifests_config_selection_medium"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In an ideal world, I'd want to use the exact same strategy as autoland. In reality that doesn't seem possible because it uses a long composite strategy that takes into account push id, backstops, and other things. I'm not sure if what I have here is the best one; I'm happy to be corrected on this.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On autoland, the builds for various operating systems get scheduled. On try, the fewer builds the better, and they better are fast ones and without a small machine pool to run one. By default Linux opt should run, debug if the penalty for slower tests is acceptable. macOS and Windows shall get test tasks if the changes are expected to affect operating systems differently.


# Always cleanup at the end of the execution
atexit.register(self.cleanup)
# caching the versions of the app
Expand Down
16 changes: 16 additions & 0 deletions bot/code_review_bot/vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

import json
import os
import random
import time

import rs_parsepatch
import structlog
from libmozdata.phabricator import PhabricatorPatch

from code_review_bot.config import settings
from code_review_bot.sources.phabricator import PhabricatorBuild

logger = structlog.get_logger(__name__)
Expand All @@ -22,6 +24,13 @@
PUSH_RETRY_EXPONENTIAL_DELAY = 6


def bugbug_enabled(repository_name):
if repository_name not in settings.bugbug_enabled_repositories:
return False

return random.random() < settings.bugbug_enabled_percent


class RetryNeeded(Exception):
"""
Raised when retrying a build is needed
Expand Down Expand Up @@ -176,6 +185,13 @@ def add_try_commit(self, build):
"phabricator_diff": build.target_phid,
},
}

if bugbug_enabled(self.name):
config["parameters"]["test_manifest_loader"] = "bugbug"
config["parameters"]["optimize_strategies"] = (
settings.bugbug_optimize_strategy
)

diff_phid = build.stack[-1].phid

if build.revision_url:
Expand Down
27 changes: 21 additions & 6 deletions bot/tests/test_mercurial.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
from unittest.mock import MagicMock

import hglib
import pytest
import responses
from conftest import MockBuild
from libmozdata.phabricator import PhabricatorPatch

from code_review_bot import mercurial
from code_review_bot.config import settings


class STDOutputMock:
Expand Down Expand Up @@ -73,11 +75,20 @@ def test_robustcheckout(monkeypatch):
]


def test_push_to_try(PhabricatorMock, mock_mc, responses):
@pytest.mark.parametrize("bugbug", [False, True], ids=["bugbug-off", "bugbug-on"])
def test_push_to_try(PhabricatorMock, mock_mc, responses, monkeypatch, bugbug):
"""
Run mercurial worker on a single diff
with a push to try server

The bugbug parameters only affect try_task_config.json: the commits
themselves are identical whether the repository is selected or not
"""
if bugbug:
monkeypatch.setattr(settings, "bugbug_enabled_repositories", [mock_mc.name])
monkeypatch.setattr(settings, "bugbug_enabled_percent", 1)
monkeypatch.setattr(settings, "bugbug_optimize_strategy", "test:strategy")

# Preload the build
diff = {
"phid": "PHID-DIFF-test123",
Expand Down Expand Up @@ -128,14 +139,18 @@ def test_push_to_try(PhabricatorMock, mock_mc, responses):
assert open(target).read() == "First Line\nSecond Line\n"

# Check the try_task_config file
expected_parameters = {
"target_tasks_method": "codereview",
"optimize_target_tasks": True,
"phabricator_diff": "PHID-HMBT-deadbeef",
}
if bugbug:
expected_parameters["test_manifest_loader"] = "bugbug"
expected_parameters["optimize_strategies"] = "test:strategy"
assert os.path.exists(config)
assert json.load(open(config)) == {
"version": 2,
"parameters": {
"target_tasks_method": "codereview",
"optimize_target_tasks": True,
"phabricator_diff": "PHID-HMBT-deadbeef",
},
"parameters": expected_parameters,
}

# Get tip commit in repo
Expand Down
39 changes: 39 additions & 0 deletions bot/tests/test_vcs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from code_review_bot import vcs
from code_review_bot.config import settings


def test_bugbug_default_configuration():
"""
The shipped rollout configuration is usable: a percentage expressed as a
ratio, a non empty allow list and a non empty optimize strategy
"""
assert 0 <= settings.bugbug_enabled_percent <= 1
assert settings.bugbug_enabled_repositories
assert settings.bugbug_optimize_strategy


def test_bugbug_disabled_for_unlisted_repository(monkeypatch):
"""
Repositories outside of the allow list are never selected, even when the
rollout percentage is at its maximum
"""
monkeypatch.setattr(settings, "bugbug_enabled_percent", 1)

assert vcs.bugbug_enabled("mozilla-central") is False
assert vcs.bugbug_enabled("nss") is False


def test_bugbug_enabled_for_listed_repository(monkeypatch):
"""
Repositories from the allow list are selected by the rollout percentage
"""
monkeypatch.setattr(settings, "bugbug_enabled_repositories", ["autoland"])

monkeypatch.setattr(settings, "bugbug_enabled_percent", 1)
assert vcs.bugbug_enabled("autoland") is True

monkeypatch.setattr(settings, "bugbug_enabled_percent", 0)
assert vcs.bugbug_enabled("autoland") is False