Ability to Soft Delete Stale Bugs from elastic-recheck
Add a resolved_at attribute in the query yaml files that can be used to mark when a bug has been fixed or does not occur any more. This can help us re-enable bugs quickly when we see them again. Change-Id: I7af7ce9417eec5ff9ecc2487a920ff9d1286a714
This commit is contained in:
parent
0843b5917b
commit
d14cde9dec
@ -146,11 +146,12 @@ class Classifier():
|
||||
es_query = qb.generic(query, facet=facet)
|
||||
return self.es.search(es_query, size=size)
|
||||
|
||||
def classify(self, change_number, patch_number, comment):
|
||||
def classify(self, change_number, patch_number, comment,
|
||||
skip_resolved=True):
|
||||
"""Returns either empty list or list with matched bugs."""
|
||||
self.log.debug("Entering classify")
|
||||
#Reload each time
|
||||
self.queries = loader.load(self.queries_dir)
|
||||
self.queries = loader.load(self.queries_dir, skip_resolved)
|
||||
#Wait till Elastic search is ready
|
||||
self.log.debug("checking if ElasticSearch is ready")
|
||||
if not self._is_ready(change_number, patch_number, comment):
|
||||
|
@ -18,11 +18,14 @@ A set of utility methods to load queries for elastic recheck.
|
||||
"""
|
||||
|
||||
import glob
|
||||
import logging
|
||||
import os.path
|
||||
import yaml
|
||||
|
||||
LOG = logging.getLogger('recheckwatchbot')
|
||||
|
||||
def load(directory='queries'):
|
||||
|
||||
def load(directory='queries', skip_resolved=True):
|
||||
"""Load queries from a set of yaml files in a directory."""
|
||||
bugs = glob.glob("%s/*.yaml" % directory)
|
||||
data = []
|
||||
@ -30,5 +33,9 @@ def load(directory='queries'):
|
||||
bugnum = os.path.basename(fname).rstrip('.yaml')
|
||||
query = yaml.load(open(fname).read())
|
||||
query['bug'] = bugnum
|
||||
data.append(query)
|
||||
if skip_resolved and 'resolved_at' in query:
|
||||
LOG.debug('Skipping Bug : %s as it was resolved at %s'
|
||||
% (query['bug'], query['resolved_at']))
|
||||
else:
|
||||
data.append(query)
|
||||
return data
|
||||
|
@ -18,14 +18,19 @@ from elastic_recheck import results
|
||||
from elastic_recheck import tests
|
||||
|
||||
|
||||
def fake_queries(*args):
|
||||
return [
|
||||
def fake_queries(directory='queries', skip_resolved=True):
|
||||
queries = [
|
||||
{'query': '@message:"fake query" AND @fields.filename:"fake"\n',
|
||||
'bug': 1226337},
|
||||
{'query': 'magic query',
|
||||
'bug': 1234567},
|
||||
{'query': '@message:"fake_query3" AND @fields.filename:"fake"\n',
|
||||
'bug': 1235437}]
|
||||
if not skip_resolved:
|
||||
queries.append({'query': 'magic query',
|
||||
'bug': 1252514,
|
||||
'resolved_at': 'Tue Dec 10 12:08:42 EST 2013'})
|
||||
return queries
|
||||
|
||||
|
||||
def _fake_search(query, size=None):
|
||||
@ -96,3 +101,16 @@ class TestClassifier(tests.TestCase):
|
||||
'-devstack-vm-postgres-full/99bb8f6'
|
||||
)
|
||||
self.assertEqual(bug_numbers, [1234567])
|
||||
|
||||
def test_classify_without_skipping_resolved_bugs(self):
|
||||
self.stubs.Set(self.classifier.es, 'search', _fake_search)
|
||||
self.stubs.Set(self.classifier, '_urls_match', _fake_urls_match)
|
||||
self.stubs.Set(self.classifier, '_is_ready', _fake_is_ready)
|
||||
bug_numbers = self.classifier.classify(
|
||||
'47463',
|
||||
'3',
|
||||
' blah http://logs.openstack.org/63/47463/3/gate/gate-tempest'
|
||||
'-devstack-vm-postgres-full/99bb8f6',
|
||||
False
|
||||
)
|
||||
self.assertEqual(bug_numbers, [1234567, 1252514])
|
||||
|
Loading…
Reference in New Issue
Block a user