blob: 7118a5f4d70dacd468a7eff066d360e9e11ab57b [file] [log] [blame]
#!/usr/bin/env python
# Copyright 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import argparse
import dashboard_api
import json
# TODO(rnephew): Integrate into catapult/experimental/benchmark_health_report.
# pylint: disable=line-too-long
HELP_SITE = 'https://developers.google.com/api-client-library/python/auth/service-accounts#creatinganaccount'
def GetBugData(dashboard_communicator, bug):
"""Returns data for given bug."""
if not bug:
return {'bug': {'state': None, 'status': None, 'summary': None}}
if int(bug) == -1:
return {'bug': {'state': None, 'status': None, 'summary': 'Invalid'}}
if int(bug) == -2:
return {'bug': {'state': None, 'status': None, 'summary': 'Ignored'}}
data = dashboard_communicator.GetBugData(bug)
# Only care about date of comments, not content.
data['bug']['comments'] = [a['published'] for a in data['bug']['comments']]
return data
def Main():
parser = argparse.ArgumentParser()
parser.add_argument('-b', '--benchmark', required=True,
help='Benchmark to pull data for.')
parser.add_argument('-d', '--days', default=30, type=int,
help='Number of days to collect data for. Default 30')
parser.add_argument('--credentials',
help=('Path to json credentials file. See %s for '
'information about generating this.' % HELP_SITE))
parser.add_argument('--output-path', default='alert_noise.json',
help='Path to save file to. Default: alert_noise.json')
args = parser.parse_args()
dashboard_communicator = dashboard_api.PerfDashboardCommunicator(
json_key_path=args.credentials)
data = []
alerts = dashboard_communicator.GetAlertData(
args.benchmark, args.days)['anomalies']
print '%s alerts found!' % len(alerts)
bug_list = set([a.get('bug_id') for a in alerts])
print 'Collecting data for %d bugs.' % len(bug_list)
bugs = {}
for bug in bug_list:
bugs[bug] = GetBugData(dashboard_communicator, bug)['bug']
data = {'bugs': bugs, 'alerts': alerts}
with open(args.output_path, 'w') as fp:
print 'Saving data to %s.' % args.output_path
json.dump(data, fp, sort_keys=True, indent=2)
if __name__ == '__main__':
Main()