| 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 collections | 5 import collections |
| 6 from infra.libs.event_mon.router import _Router | 6 from infra.libs.event_mon.router import _Router |
| 7 import socket | 7 import socket |
| 8 | 8 |
| 9 from infra.libs.event_mon.chrome_infra_log_pb2 import ChromeInfraEvent | 9 from infra.libs.event_mon.chrome_infra_log_pb2 import ChromeInfraEvent |
| 10 from infra.libs.event_mon.chrome_infra_log_pb2 import ServiceEvent | 10 from infra.libs.event_mon.chrome_infra_log_pb2 import ServiceEvent |
| 11 | 11 |
| 12 _router = None | 12 _router = None |
| 13 | 13 |
| 14 # Cache some generally useful values | 14 # Cache some generally useful values |
| 15 cache = {} | 15 cache = {} |
| 16 | 16 |
| 17 | 17 |
| 18 def add_argparse_options(parser): | 18 def add_argparse_options(parser): |
| 19 # The default values should make sense for local testing, not production. | 19 # The default values should make sense for local testing, not production. |
| 20 parser.add_argument('--event-mon-dry-run', type=bool, default=True, | 20 parser.add_argument('--event-mon-run-type', default='dry', |
| 21 help='Whether events should be sent to the remote ' | 21 choices=('dry', 'test', 'prod'), |
| 22 'server.') | 22 help='Determine how to send data. "dry" does not send' |
| 23 ' anything. "test" sends to the test endpoint, and ' |
| 24 '"prod" to the actual production endpoint.') |
| 23 parser.add_argument('--event-mon-service-name', | 25 parser.add_argument('--event-mon-service-name', |
| 24 help='Service name to use in log events.') | 26 help='Service name to use in log events.') |
| 25 parser.add_argument('--event-mon-hostname', | 27 parser.add_argument('--event-mon-hostname', |
| 26 help='Hostname to use in log events.') | 28 help='Hostname to use in log events.') |
| 27 parser.add_argument('--event-mon-appengine-name', | 29 parser.add_argument('--event-mon-appengine-name', |
| 28 help='App name to use in log events.') | 30 help='App name to use in log events.') |
| 29 | 31 |
| 30 # Provide information about version of code running. | 32 # Provide information about version of code running. |
| 31 parser.add_argument('--event-mon-code-source-url', | 33 parser.add_argument('--event-mon-code-source-url', |
| 32 help='URL where to get the source code (info sent in log ' | 34 help='URL where to get the source code (info sent in log ' |
| 33 'events.') | 35 'events.') |
| 34 parser.add_argument('--event-mon-code-dirty', type=bool, | 36 parser.add_argument('--event-mon-code-dirty', type=bool, |
| 35 help='Whether there are local modifications in the ' | 37 help='Whether there are local modifications in the ' |
| 36 'currently running code (info sent in log events).') | 38 'currently running code (info sent in log events).') |
| 37 parser.add_argument('--event-mon-code-version', | 39 parser.add_argument('--event-mon-code-version', |
| 38 help='Version string for the currently running code.') | 40 help='Version string for the currently running code.') |
| 39 parser.add_argument('--event-mon-code-git-hash', | 41 parser.add_argument('--event-mon-code-git-hash', |
| 40 help='Git hash for the currently running code.') | 42 help='Git hash for the currently running code.') |
| 41 parser.add_argument('--event-mon-code-svn-revision', type=int, | 43 parser.add_argument('--event-mon-code-svn-revision', type=int, |
| 42 help='Svn revision for the currently running code.') | 44 help='Svn revision for the currently running code.') |
| 43 | 45 |
| 44 | 46 |
| 45 def process_argparse_options(args): | 47 def process_argparse_options(args): |
| 46 global _router | 48 global _router |
| 47 if not _router: | 49 if not _router: |
| 48 _router = _Router(dry_run=args.event_mon_dry_run) | 50 ENDPOINTS = { |
| 51 'dry': None, |
| 52 'test': 'https://jmt17.google.com/log', |
| 53 'prod': 'https://play.googleapis.com/log', |
| 54 } |
| 55 endpoint = ENDPOINTS.get(args.event_mon_run_type) |
| 56 _router = _Router(endpoint=endpoint) |
| 49 | 57 |
| 50 default_event = ChromeInfraEvent() | 58 default_event = ChromeInfraEvent() |
| 51 | 59 |
| 52 if args.event_mon_hostname: | 60 if args.event_mon_hostname: |
| 53 default_event.event_source.host_name = args.event_mon_hostname | 61 default_event.event_source.host_name = args.event_mon_hostname |
| 54 else: | 62 else: |
| 55 hostname = socket.getfqdn() | 63 hostname = socket.getfqdn() |
| 56 # hostname might be empty string or None on some systems, who knows. | 64 # hostname might be empty string or None on some systems, who knows. |
| 57 if hostname: # pragma: no branch | 65 if hostname: # pragma: no branch |
| 58 default_event.event_source.host_name = hostname | 66 default_event.event_source.host_name = hostname |
| (...skipping 16 matching lines...) Expand all Loading... |
| 75 timeout (int): number of seconds to wait before giving up. | 83 timeout (int): number of seconds to wait before giving up. |
| 76 Returns: | 84 Returns: |
| 77 success (bool): False if a timeout occured. | 85 success (bool): False if a timeout occured. |
| 78 """ | 86 """ |
| 79 global _router | 87 global _router |
| 80 success = True | 88 success = True |
| 81 if _router: | 89 if _router: |
| 82 success = _router.close(timeout=timeout) | 90 success = _router.close(timeout=timeout) |
| 83 _router = None | 91 _router = None |
| 84 return success | 92 return success |
| OLD | NEW |