Skip to content

Commit

Permalink
Fix issue #278 - failure pod crashing
Browse files Browse the repository at this point in the history
We should log error rather then crash pod if JIRA is missing
type required by failure exporter. JIRA type may be added
after pelorus deployment.
  • Loading branch information
mpryc committed Apr 26, 2022
1 parent 631105d commit c57f384
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
32 changes: 26 additions & 6 deletions exporters/failure/collector_jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
import pelorus
from failure.collector_base import AbstractFailureCollector, TrackerIssue

JIRA_SEARCH_RESULTS = 50 # One query limit, exporter will query
# multiple times. Do not exceed 100 as
# JIRA won't return more.


class JiraFailureCollector(AbstractFailureCollector):
"""
Expand Down Expand Up @@ -60,16 +64,32 @@ def _connect_to_jira(self) -> JIRA:

def search_issues(self):
jira = self._connect_to_jira()
# TODO FIXME This may need to be modified to suit needs and have a time period.
query_string = "type=bug and priority=highest"
if self.projects is not None:
query_string = query_string + " and project in (" + self.projects + ")"
jira_issues = jira.search_issues(query_string)

critical_issues = []

try:
jira_issues = jira.search_issues(query_string)
# TODO FIXME This may need to be modified to suit needs and have a time period.
query_string = "type=bug and priority=highest"
query_result_fields = "summary,labels,created,resolutiondate"

if self.projects is not None:
query_string = query_string + " AND project in (" + self.projects + ")"

jira_issues = []
start_at = 0
while True:
jira_search_results = jira.search_issues(
query_string,
startAt=start_at,
maxResults=JIRA_SEARCH_RESULTS,
fields=query_result_fields,
)
jira_issues += jira_search_results.iterable
start_at += JIRA_SEARCH_RESULTS
logging.info("Getting jira results: %s" % start_at)
if start_at >= jira_search_results.total:
break

for issue in jira_issues:
logging.debug(issue)
logging.debug(
Expand Down
5 changes: 4 additions & 1 deletion exporters/tests/test_failure_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
#

from typing import cast

import pytest
from jira.exceptions import JIRAError
from prometheus_client.core import REGISTRY

from failure.app import TrackerFactory
from failure.collector_jira import JiraFailureCollector

Expand Down Expand Up @@ -80,6 +82,7 @@ def test_jira_prometheus_register(
):
def mock_search_issues(self):
return []

monkeypatch.setattr(JiraFailureCollector, "search_issues", mock_search_issues)
collector = JiraFailureCollector(
user=username, apikey=apikey, server=server, projects=None
Expand All @@ -100,7 +103,7 @@ def mock_search_issues(self):
)
def test_jira_exception(server, username, apikey, monkeypatch: pytest.MonkeyPatch):
class FakeJira(object):
def search_issues(self, issues):
def search_issues(self, issues, startAt=0, maxResults=50, fields=None):
raise JIRAError(status_code=400, text="Fake search error")

def mock_jira_connect(self):
Expand Down

0 comments on commit c57f384

Please sign in to comment.