Skip to content
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

Add new rule for detecting potential performance-related bugs #2305

Merged
merged 19 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
101 changes: 101 additions & 0 deletions bugbot/rules/performancebug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# 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 bugbot.bugbug_utils import get_bug_ids_classification
from bugbot.bzcleaner import BzCleaner
from bugbot.utils import nice_round


class PerformanceBug(BzCleaner):
def __init__(self):
super().__init__()
self.autofix_bugs = []

def description(self):
return "[Using ML] Bugs with Missing Performance Impact"

def columns(self):
return ["id", "summary", "confidence", "autofixed"]

def get_bz_params(self, date):
start_date, _ = self.get_dates(date)

params = {
"include_fields": ["id", "summary"],
"f1": "creation_ts",
"o1": "greaterthan",
"v1": start_date,
"f2": "keywords",
"o2": "nowords",
"v2": "perf,topperf,main-thread-io",
"f3": "cf_performance_impact",
"o3": "equals",
"v3": ["---"],
}

return params

def get_bugs(self, date="today", bug_ids=[]):
# Retrieve the bugs with the fields defined in get_bz_params
PromiseFru marked this conversation as resolved.
Show resolved Hide resolved
raw_bugs = super().get_bugs(date=date, bug_ids=bug_ids, chunk_size=7000)

if len(raw_bugs) == 0:
return {}

# Extract the bug ids
PromiseFru marked this conversation as resolved.
Show resolved Hide resolved
bug_ids = list(raw_bugs.keys())

# Classify those bugs
bugs = get_bug_ids_classification("performancebug", bug_ids)

results = {}

for bug_id in sorted(bugs.keys()):
PromiseFru marked this conversation as resolved.
Show resolved Hide resolved
bug_data = bugs[bug_id]

if not bug_data.get("available", True):
# The bug was not available, it was either removed or is a
# security bug
continue

if not {"prob", "index"}.issubset(bug_data.keys()):
raise Exception(f"Invalid bug response {bug_id}: {bug_data!r}")
PromiseFru marked this conversation as resolved.
Show resolved Hide resolved

bug = raw_bugs[bug_id]
prob = bug_data["prob"]

if prob[1] < 0.2:
continue

results[bug_id] = {
"id": bug_id,
"summary": bug["summary"],
"confidence": nice_round(prob[1]),
"autofixed": False,
PromiseFru marked this conversation as resolved.
Show resolved Hide resolved
}

# Only autofix results for which we are sure enough.
if prob[1] >= self.get_config("confidence_threshold"):
results[bug_id]["autofixed"] = True
self.autofix_bugs.append((bug_id, prob[1]))

return results

def get_autofix_change(self):
autofix_change = {}
for bug_id, confidence in self.autofix_bugs:
autofix_change[bug_id] = {
"cf_performance_impact": "?",
}

if confidence != 1.0:
autofix_change[bug_id]["comment"] = {
"body": "The [Bugbug](https://github.com/mozilla/bugbug/) bot thinks this bug is a performance bug, but please revert this change in case of error."
}

return autofix_change
suhaibmujahid marked this conversation as resolved.
Show resolved Hide resolved


if __name__ == "__main__":
PerformanceBug().run()
4 changes: 4 additions & 0 deletions configs/rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@
"confidence_threshold": 0.95,
"cc": []
},
"performancebug": {
PromiseFru marked this conversation as resolved.
Show resolved Hide resolved
"days_lookup": 7,
"confidence_threshold": 0.9
PromiseFru marked this conversation as resolved.
Show resolved Hide resolved
},
"stepstoreproduce": {
"max_days_in_cache": 7,
"days_lookup": 3,
Expand Down
25 changes: 25 additions & 0 deletions templates/performancebug.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<p>
The following {{ plural('bug is', data, pword='bugs are') }} probably performance related and {{ plural('doesn\'t', data, pword='don\'t') }} have performance impact value:
</p>
<table {{ table_attrs }}>
<thead>
<tr>
<th>Bug</th>
<th>Summary</th>
<th>Confidence (%)</th>
</tr>
</thead>
<tbody>
{% for i, (bugid, summary, confidence, autofixed) in enumerate(data) -%}
<tr {% if i % 2 == 0 %}bgcolor="#E0E0E0"
{% endif -%}
>
<td>
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id={{ bugid }}">{{ bugid }}</a>
</td>
<td>{{ summary | e }}</td>
<td {% if autofixed %}bgcolor="#00FF00"{% endif -%}>{{ confidence }}</td>
</tr>
{% endfor -%}
</tbody>
</table>