From a97fa979fdf0596999f385271eff4f61784cf4d1 Mon Sep 17 00:00:00 2001 From: Qixiang Wan Date: Tue, 21 Jan 2025 01:15:36 +0800 Subject: [PATCH] Skip retries for Jira errors Due to the implementation of the allow list and block list, freshmaker is actually checking all advisories with all state changes. When freshmaker lacks permissions to access certain Jira issues, it continuously retries these checks, causing significant performance degradation. This change removes retry attempts for Jira permission errors, as these retries would never succeed. This workaround prevents unnecessary delays in processing advisory state change events. --- freshmaker/errata.py | 49 +++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/freshmaker/errata.py b/freshmaker/errata.py index ff20391c..93d19130 100644 --- a/freshmaker/errata.py +++ b/freshmaker/errata.py @@ -25,7 +25,7 @@ import requests import dogpile.cache from requests_kerberos import HTTPKerberosAuth, OPTIONAL -from jira import JIRA +from jira import JIRA, JIRAError from freshmaker.events import BrewSignRPMEvent, ErrataBaseEvent, FreshmakerManualRebuildEvent from freshmaker import conf, log @@ -178,6 +178,11 @@ class Errata(object): conf.dogpile_cache_backend, expiration_time=24 * 3600 ) + # Cache for Jira issue data + jira_region = dogpile.cache.make_region().configure( + conf.dogpile_cache_backend, expiration_time=60 * 60 + ) + def __init__(self, server_url=None): """ Initializes the Errata instance. @@ -526,22 +531,42 @@ def is_zstream(self, errata_id): release = self._get_release(errata_id) return release["data"]["attributes"]["type"] == "Zstream" - @retry(wait_on=Exception, logger=log) - def _check_jira_special_handling(self, issue_keys: list[str], handling_value: str) -> bool: - """Check if any vulnerability issue has the specified special handling value.""" + @jira_region.cache_on_arguments() + def _get_jira_vulnerability_special_handling(self, issue_key: str) -> None | list[str]: + """ + Get "Special Handling" values from a Jira issue, return None if Jira issue + is not a "Vulnerability" issue + """ jira_server = JIRA(server=conf.jira_server_url, token_auth=conf.jira_token) try: - for issue in issue_keys: - jira_issue = jira_server.issue(issue) - if jira_issue.fields.issuetype.name.lower() != "vulnerability": - continue - special_handling = getattr(jira_issue.fields, "customfield_12324753", []) or [] - if handling_value in [x.value for x in special_handling]: - return True - return False + try: + issue = jira_server.issue(issue_key) + except JIRAError as e: + log.error("unable to check jira issue %s: %s", issue_key, e.text) + return None + + issue_type = issue.fields.issuetype.name.lower() + if issue_type != "vulnerability": + return None + + special_handling = getattr(issue.fields, "customfield_12324753", []) + if not special_handling: + return None + return [x.value for x in special_handling] finally: jira_server.close() + @retry(wait_on=Exception, logger=log) + def _check_jira_special_handling(self, issue_keys: list[str], handling_value: str) -> bool: + """Check if any vulnerability issue has the specified special handling value.""" + for issue in issue_keys: + special_handling = self._get_jira_vulnerability_special_handling(issue) + if not special_handling: + continue + if handling_value in special_handling: + return True + return False + def is_major_incident_advisory(self, errata_id) -> bool: """Check if this advisory is a major incident advisory.""" # check if there is any "hightouch+" bug attached