OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
| 5 import logging |
5 import sys | 6 import sys |
6 import traceback | 7 import traceback |
7 | 8 |
8 import infra_libs.event_mon as event_mon | 9 import infra_libs.event_mon as event_mon |
9 import infra_libs.ts_mon as ts_mon | 10 import infra_libs.ts_mon as ts_mon |
10 | 11 |
11 from infra.tools.send_monitoring_event import send_event | 12 from infra.tools.send_monitoring_event import send_event |
12 | 13 |
13 | 14 |
14 def main(argv): # pragma: no cover | 15 def main(argv): # pragma: no cover |
15 # Does nothing when no arguments are passed, to make it safe to import this | 16 # Does nothing when no arguments are passed, to make it safe to import this |
16 # module (main() is executed on import, because this file is called __main__). | 17 # module (main() is executed on import, because this file is called __main__). |
17 status = 0 | 18 status = 0 |
18 | 19 |
19 if len(argv) == 0: | 20 if len(argv) == 0: |
20 return status | 21 return status |
21 | 22 |
22 success_metric = ts_mon.BooleanMetric('send_monitoring_event/success') | 23 success_metric = ts_mon.BooleanMetric('send_monitoring_event/success') |
23 | 24 |
24 try: | 25 try: |
25 args = send_event.get_arguments(argv) | 26 args = send_event.get_arguments(argv) |
26 | |
27 send_event.process_argparse_options(args) | 27 send_event.process_argparse_options(args) |
28 | 28 |
29 if args.build_event_type: | 29 if args.build_event_type: |
30 success_metric.set(send_event.send_build_event(args)) | 30 success_metric.set(send_event.send_build_event(args)) |
31 | 31 |
32 elif args.service_event_type: | 32 elif args.service_event_type: |
33 success_metric.set(send_event.send_service_event(args)) | 33 success_metric.set(send_event.send_service_event(args)) |
34 | 34 |
35 elif args.events_from_file: | 35 elif args.events_from_file: |
36 success_metric.set(send_event.send_events_from_file(args)) | 36 success_metric.set(send_event.send_events_from_file(args)) |
37 | 37 |
38 else: | 38 else: |
39 print >> sys.stderr, ('At least one of the --*-event-type options or ' | 39 print >> sys.stderr, ('At least one of the --*-event-type options or ' |
40 '--events-from-file should be provided. Nothing ' | 40 '--events-from-file should be provided. Nothing ' |
41 'was sent.') | 41 'was sent.') |
42 status = 2 | 42 status = 2 |
43 success_metric.set(False) | 43 success_metric.set(False) |
44 except Exception: | 44 except Exception: |
45 success_metric.set(False) | 45 success_metric.set(False) |
46 traceback.print_exc() # helps with debugging locally. | 46 traceback.print_exc() # helps with debugging locally. |
47 finally: | 47 finally: |
48 event_mon.close() | 48 event_mon.close() |
49 try: | 49 try: |
50 ts_mon.flush() | 50 ts_mon.flush() |
51 except ts_mon.MonitoringNoConfiguredMonitorError: | 51 except ts_mon.MonitoringNoConfiguredMonitorError: |
52 pass | 52 logging.error("Unable to flush ts_mon because it's not configured.") |
| 53 except Exception: |
| 54 logging.exception("Flushing ts_mon metrics failed.") |
53 return status | 55 return status |
54 | 56 |
55 | 57 |
56 if __name__ == '__main__': | 58 if __name__ == '__main__': |
57 sys.exit(main(sys.argv[1:])) | 59 sys.exit(main(sys.argv[1:])) |
OLD | NEW |