Skip to content

Commit

Permalink
Add new rule for monitoring perfalert resolution changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmierz committed Nov 5, 2024
1 parent bb8427e commit a3ab301
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 0 deletions.
107 changes: 107 additions & 0 deletions bugbot/rules/perfalert_resolved_regression.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# 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 libmozdata.bugzilla import Bugzilla

from bugbot.bzcleaner import BzCleaner


class PerfAlertInactiveRegression(BzCleaner):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.extra_email_info = {}
self._bug_history = {}
self._bug_comments = {}

def description(self):
return "PerfAlert regressions whose resolution has changed recently"

def get_bz_params(self, date):
fields = [
"id",
"resolution",
]

# Find all bugs that have perf-alert, and regression in their keywords. Search
# for bugs that have been changed in the last day. Only look for bugs after
# October 1st, 2024 to prevent triggering comments on older performance regressions
params = {
"include_fields": fields,
"f3": "creation_ts",
"o3": "greaterthan",
"v3": "2024-10-01T00:00:00Z",
"f1": "regressed_by",
"o1": "isnotempty",
"f2": "keywords",
"o2": "allwords",
"v2": ["regression", "perf-alert"],
"f4": "resolution",
"o4": "changedafter",
"v4": date,
}

return params

def get_extra_for_template(self):
return self.extra_email_info

def get_resolution_comments(self, bugs):
# Match all the resolutions with resolution comments if they exist
for bug_id, bug in bugs.items():
bug_comments = self._bug_comments.get(bug_id, [])
bug_history = self._bug_history.get(bug_id, {})

# Sometimes a resolution comment is not provided so use a default
bug_history["resolution_comment"] = "No resolution comment provided."
for comment in bug_comments[::-1]:
if (
comment["creation_time"] == bug_history["resolution_time"]
and comment["author"] == bug_history["resolution_author"]
):
bug_history["resolution_comment"] = comment["text"]
break

self.extra_email_info[bug_id] = bug_history

def comment_handler(self, bug, bug_id, bugs):
# Gather all comments to match them with the history after
self._bug_comments[bug_id] = bug["comments"]

def history_handler(self, bug):
bug_info = self._bug_history.setdefault(str(bug["id"]), {})

# Get the last resolution change that was made in this bug
for change in bug["history"][::-1]:
for specific_change in change["changes"]:
if specific_change["field_name"] == "status" and specific_change[
"added"
] in ("RESOLVED", "REOPENED"):
bug_info["resolution_time"] = change["when"]
bug_info["resolution_author"] = change["who"]
bug_info["resolution"] = specific_change["added"]
break
if bug_info.get("resolution_author"):
break

def gather_bugs_info(self, bugs):
Bugzilla(
bugids=self.get_list_bugs(bugs),
historyhandler=self.history_handler,
commenthandler=self.comment_handler,
commentdata=bugs,
comment_include_fields=["text", "creation_time", "author"],
).get_data().wait()

# Match the history with comments to get resolution reasons
self.get_resolution_comments(bugs)

def get_bugs(self, *args, **kwargs):
bugs = super().get_bugs(*args, **kwargs)
self.gather_bugs_info(bugs)
return bugs


if __name__ == "__main__":
PerfAlertInactiveRegression().run()
3 changes: 3 additions & 0 deletions configs/rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -471,5 +471,8 @@
},
"perfalert_inactive_regression": {
"additional_receivers": ["[email protected]", "[email protected]"]
},
"perfalert_resolved_regression": {
"additional_receivers": ["[email protected]", "[email protected]"]
}
}
3 changes: 3 additions & 0 deletions scripts/cron_run_daily.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ python -m bugbot.rules.performancebug --production
# Try to detect potential performance alerts that have been inactive for too long
python -m bugbot.rules.perfalert_inactive_regression --production

# Send an email about all performance alerts who were recently resolved
python -m bugbot.rules.perfalert_resolved_regression --production

# Send a mail if the logs are not empty
# MUST ALWAYS BE THE LAST COMMAND
python -m bugbot.log --send
Expand Down
39 changes: 39 additions & 0 deletions templates/perfalert_resolved_regression.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<p>The following bug list contains performance alerts whose resolution has changed in the last week:</p>
<table {{ table_attrs }}>
<thead>
<tr>
<th>Bug</th>
<th>Summary</th>
<th>Resolution</th>
</tr>
</thead>
<tbody>
{% for i, (bugid, summary) 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>
<table>
<tr>
<td>{{ summary | e }}</td>
</tr>
<tr>
<td>
<b>Resolution Comment:</b> {{ extra[bugid]["resolution_comment"] }}
</td>
</tr>
<tr>
<td>
<i>Resolved by {{ extra[bugid]["resolution_author"] }}</i>
</td>
</tr>
</table>
</td>
<td>{{ extra[bugid]["resolution"] }}</td>
</tr>
{% endfor -%}
</tbody>
</table>

0 comments on commit a3ab301

Please sign in to comment.