Sean Dague 932986a876 move queries.yaml into a queries subdir
this handles the piece of work we've been talking about for a while
in moving the queries.yaml file into a directory with a bunch of
files. These remain yaml so that they can be tagged with additional
metadata. This would support the concept of soft deleting as well
as other useful meta data to gauge our evolution of the bugs we
track over time.

This should see some real review as it's extensive enough of a
change that the existing tests might not be sufficient. However it
should be enough to move this forward quite a bit.

This also makes future looking statements about doing soft deletes
with a resolved_at keyword in the future. That implementation will
come later.

Change-Id: I86317fcf6f1886ab5b6c0ee154b29e71865c52b7
2013-12-02 11:43:00 -05:00

98 lines
2.7 KiB
Python
Executable File

#!/usr/bin/env python
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import argparse
import os
from launchpadlib import launchpad
import elastic_recheck.elasticRecheck as er
LPCACHEDIR = os.path.expanduser('~/.launchpadlib/cache')
def get_options():
parser = argparse.ArgumentParser(
description='Query for existing recheck bugs.')
parser.add_argument('--dir', '-d', help="Queries Directory",
default="queries")
return parser.parse_args()
def collect_metrics(classifier):
data = {}
for q in classifier.queries:
results = classifier.hits_by_query(q['query'], size=3000)
rate = {}
for hit in results:
uuid = hit.build_uuid
success = hit.build_status
if success not in rate:
rate[success] = set(uuid)
else:
rate[success].add(uuid)
num_fails = 0
if "FAILURE" in rate:
num_fails = len(rate["FAILURE"])
data[q['bug']] = {
'fails': num_fails,
'hits': rate,
'query': q['query']
}
return data
def print_metrics(data):
print "Elastic recheck known issues"
print
sorted_data = sorted(data.iteritems(),
key=lambda x: -x[1]['fails'])
for d in sorted_data:
print "Bug: https://bugs.launchpad.net/bugs/%s => %s" % (d[0], d[1]['query'].rstrip())
get_launchpad_bug(d[0])
print "Hits"
for s in d[1]['hits'].keys():
print " %s: %s" % (s, len(d[1]['hits'][s]))
print
def get_launchpad_bug(bug):
lp = launchpad.Launchpad.login_anonymously('grabbing bugs',
'production',
LPCACHEDIR)
lp_bug = lp.bugs[bug]
print "Title: %s" % lp_bug.title
targets = map(lambda x: (x.bug_target_name, x.status), lp_bug.bug_tasks)
print "Project: Status"
for target, status in targets:
print " %s: %s" % (target, status)
def main():
opts = get_options()
classifier = er.Classifier(opts.dir)
data = collect_metrics(classifier)
print_metrics(data)
if __name__ == "__main__":
main()