| OLD | NEW |
| 1 # Copyright 2016 The LUCI Authors. All rights reserved. | 1 # Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import logging | 5 import logging |
| 6 import time | 6 import time |
| 7 | 7 |
| 8 import gae_event_mon | 8 import gae_event_mon |
| 9 | 9 |
| 10 from server import task_result | 10 from server import task_result |
| 11 | 11 |
| 12 | 12 |
| 13 DIMENSIONS = ( | 13 DIMENSIONS = { |
| 14 ('cores', int), | 14 'cores': int, |
| 15 ('cpu', unicode), | 15 'cpu': unicode, |
| 16 ('device_os', unicode), | 16 'device_os': unicode, |
| 17 ('device_type', unicode), | 17 'device_type': unicode, |
| 18 ('gpu', unicode), | 18 'gpu': unicode, |
| 19 ('hidpi', unicode), | 19 'hidpi': unicode, |
| 20 ('machine_type', unicode), | 20 'machine_type': unicode, |
| 21 ('os', unicode), | 21 'os': unicode, |
| 22 ('pool', unicode), | 22 'pool': unicode, |
| 23 ('xcode_version', unicode), | 23 'xcode_version': unicode, |
| 24 ('zone', unicode), | 24 'zone': unicode, |
| 25 ) | 25 } |
| 26 | 26 |
| 27 | 27 |
| 28 TAGS = { | 28 TAGS = { |
| 29 'build_id': ['buildnumber'], | 29 'build_id': ['buildnumber'], |
| 30 'buildername': ['buildername'], | 30 'buildername': ['buildername'], |
| 31 'codereview': ['rietveld'], | 31 'codereview': ['rietveld'], |
| 32 'master': ['master'], | 32 'master': ['master'], |
| 33 'name': ['name'], | 33 'name': ['name'], |
| 34 'patch_project': ['patch_project'], | 34 'patch_project': ['patch_project'], |
| 35 'project': ['project'], | 35 'project': ['project'], |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 if task_properties.cipd_input: | 83 if task_properties.cipd_input: |
| 84 cipd_proto = properties_proto.cipd_input | 84 cipd_proto = properties_proto.cipd_input |
| 85 cipd_proto.server = task_properties.cipd_input.server | 85 cipd_proto.server = task_properties.cipd_input.server |
| 86 | 86 |
| 87 _cipd_package_to_proto(task_properties.cipd_input.client_package, | 87 _cipd_package_to_proto(task_properties.cipd_input.client_package, |
| 88 cipd_proto.client_package) | 88 cipd_proto.client_package) |
| 89 for package in task_properties.cipd_input.packages: | 89 for package in task_properties.cipd_input.packages: |
| 90 package_proto = cipd_proto.packages.add() | 90 package_proto = cipd_proto.packages.add() |
| 91 _cipd_package_to_proto(package, package_proto) | 91 _cipd_package_to_proto(package, package_proto) |
| 92 | 92 |
| 93 for d, t in DIMENSIONS: | 93 for key, value in task_properties.dimensions: |
| 94 if d in task_properties.dimensions: | 94 if key in DIMENSIONS: |
| 95 getattr(properties_proto.dimensions, d).append( | 95 getattr(properties_proto.dimensions, key).append(DIMENSIONS[key](value)) |
| 96 t(task_properties.dimensions[d])) | |
| 97 | 96 |
| 98 if task_properties.execution_timeout_secs: | 97 if task_properties.execution_timeout_secs: |
| 99 properties_proto.execution_timeout_s = \ | 98 properties_proto.execution_timeout_s = \ |
| 100 task_properties.execution_timeout_secs | 99 task_properties.execution_timeout_secs |
| 101 if task_properties.grace_period_secs: | 100 if task_properties.grace_period_secs: |
| 102 properties_proto.grace_period_s = task_properties.grace_period_secs | 101 properties_proto.grace_period_s = task_properties.grace_period_secs |
| 103 if task_properties.io_timeout_secs: | 102 if task_properties.io_timeout_secs: |
| 104 properties_proto.io_timeout_s = task_properties.io_timeout_secs | 103 properties_proto.io_timeout_s = task_properties.io_timeout_secs |
| 105 properties_proto.idempotent = task_properties.idempotent | 104 properties_proto.idempotent = task_properties.idempotent |
| 106 | 105 |
| 107 state_enum = event.proto.swarming_task_event.State.DESCRIPTOR.values_by_name | 106 state_enum = event.proto.swarming_task_event.State.DESCRIPTOR.values_by_name |
| 108 if summary.state == task_result.State.COMPLETED: | 107 if summary.state == task_result.State.COMPLETED: |
| 109 event.proto.swarming_task_event.state = state_enum['COMPLETED'].number | 108 event.proto.swarming_task_event.state = state_enum['COMPLETED'].number |
| 110 elif summary.state == task_result.State.CANCELED: | 109 elif summary.state == task_result.State.CANCELED: |
| 111 event.proto.swarming_task_event.state = state_enum['CANCELED'].number | 110 event.proto.swarming_task_event.state = state_enum['CANCELED'].number |
| 112 elif summary.state == task_result.State.BOT_DIED: | 111 elif summary.state == task_result.State.BOT_DIED: |
| 113 event.proto.swarming_task_event.state = state_enum['BOT_DIED'].number | 112 event.proto.swarming_task_event.state = state_enum['BOT_DIED'].number |
| 114 elif summary.state == task_result.State.TIMED_OUT: | 113 elif summary.state == task_result.State.TIMED_OUT: |
| 115 event.proto.swarming_task_event.state = state_enum['TIMED_OUT'].number | 114 event.proto.swarming_task_event.state = state_enum['TIMED_OUT'].number |
| 116 elif summary.state == task_result.State.EXPIRED: | 115 elif summary.state == task_result.State.EXPIRED: |
| 117 event.proto.swarming_task_event.state = state_enum['EXPIRED'].number | 116 event.proto.swarming_task_event.state = state_enum['EXPIRED'].number |
| 118 else: | 117 else: |
| 119 logging.error('Unhandled task state %r', summary.state) | 118 logging.error('Unhandled task state %r', summary.state) |
| 120 | 119 |
| 121 event.proto.swarming_task_event.bot_id = summary.bot_id | 120 event.proto.swarming_task_event.bot_id = summary.bot_id |
| 122 event.proto.swarming_task_event.bot_version = summary.bot_version | 121 event.proto.swarming_task_event.bot_version = summary.bot_version |
| 123 | 122 |
| 124 for d, t in DIMENSIONS: | 123 for d, t in DIMENSIONS.iteritems(): |
| 125 for v in summary.bot_dimensions.get(d, []): | 124 for v in summary.bot_dimensions.get(d, []): |
| 126 getattr(event.proto.swarming_task_event.bot_dimensions, d).append(t(v)) | 125 getattr(event.proto.swarming_task_event.bot_dimensions, d).append(t(v)) |
| 127 | 126 |
| 128 for v in summary.server_versions: | 127 for v in summary.server_versions: |
| 129 event.proto.swarming_task_event.server_versions.append(v) | 128 event.proto.swarming_task_event.server_versions.append(v) |
| 130 | 129 |
| 131 event.proto.swarming_task_event.internal_failure = summary.internal_failure | 130 event.proto.swarming_task_event.internal_failure = summary.internal_failure |
| 132 if summary.exit_code is not None: | 131 if summary.exit_code is not None: |
| 133 event.proto.swarming_task_event.exit_code = summary.exit_code | 132 event.proto.swarming_task_event.exit_code = summary.exit_code |
| 134 else: | 133 else: |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 summary: TaskResultSummary object. | 180 summary: TaskResultSummary object. |
| 182 """ | 181 """ |
| 183 # Isolate rest of the app from monitoring pipeline issues. They should | 182 # Isolate rest of the app from monitoring pipeline issues. They should |
| 184 # not cause outage of swarming. | 183 # not cause outage of swarming. |
| 185 try: | 184 try: |
| 186 event = gae_event_mon.Event('POINT') | 185 event = gae_event_mon.Event('POINT') |
| 187 _task_summary_to_proto(summary, event) | 186 _task_summary_to_proto(summary, event) |
| 188 event.send() | 187 event.send() |
| 189 except Exception: | 188 except Exception: |
| 190 logging.exception('Caught exception while sending event') | 189 logging.exception('Caught exception while sending event') |
| OLD | NEW |