Sean Dague 362a7e47a4 add check_success tool
this adds a tool that runs through the query list and looks for
whether the queries exist in success runs in logstash. This helps
us classify whether or not queries need to be looked at for
narrowing.

make elastic-recheck-success the entry point when installed

Change-Id: I3eaa822af35146935b22100ffb1e3a4f18dc8d0e
2013-10-02 16:00:20 -04:00

78 lines
2.3 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 elastic_recheck.elasticRecheck as er
def get_options():
parser = argparse.ArgumentParser(description='Edit hiera yaml.')
parser.add_argument('--file', '-f', help="Queries file",
default="queries.yaml")
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 x in results['hits']['hits']:
uuid = x['_source']['@fields']['build_uuid']
if type(uuid) == list:
uuid = uuid[0]
success = x['_source']['@fields']['build_status']
if type(success) == list:
success = success[0]
# use of sets to ensure we aren't finding more than one
# fail per build
if success not in rate:
rate[success] = set(uuid)
else:
rate[success].add(uuid)
data[q['bug']] = {
'fails': len(rate["FAILURE"]),
'hits': rate,
'query': q['query']
}
return data
def print_metrics(data):
print "Elastic recheck known issues"
sorted_data = sorted(data.iteritems(),
key=lambda x: -len(x[1]['hits']['FAILURE']))
for d in sorted_data:
print "Bug: %s => %s" % (d[0], d[1]['query'].rstrip())
for s in d[1]['hits'].keys():
print " %s: %s" % (s, len(d[1]['hits'][s]))
print
def main():
opts = get_options()
classifier = er.Classifier(opts.file)
data = collect_metrics(classifier)
print_metrics(data)
if __name__ == "__main__":
main()