Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(496)

Side by Side Diff: appengine/swarming/event_mon_metrics.py

Issue 2556763002: swarming: fill the rest of SwarmingTaskEvent proto (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 7
7 import gae_event_mon 8 import gae_event_mon
8 9
10 from server import task_result
11
12
13 DIMENSIONS = (
14 ('cores', int),
15 ('cpu', unicode),
16 ('device_os', unicode),
17 ('device_type', unicode),
18 ('gpu', unicode),
19 ('hidpi', unicode),
20 ('machine_type', unicode),
21 ('os', unicode),
22 ('pool', unicode),
23 ('xcode_version', unicode),
24 ('zone', unicode),
25 )
26
27
28 def _to_timestamp(dt):
29 return int(time.mktime(dt.timetuple()))
30
31
32 def _files_ref_to_proto(files_ref, proto):
M-A Ruel 2016/12/06 15:40:09 You think it is useful information to stream? I do
Paweł Hajdan Jr. 2016/12/07 20:27:56 I think we already had that discussion. It's part
33 if files_ref.isolated:
34 proto.isolated = files_ref.isolated
35 if files_ref.isolatedserver:
36 proto.isolatedserver = files_ref.isolatedserver
37 if files_ref.namespace:
38 proto.namespace = files_ref.namespace
39
40
41 def _cipd_package_to_proto(cipd_package, package_proto):
42 if cipd_package.package_name:
43 package_proto.package_name = cipd_package.package_name
44 if cipd_package.version:
45 package_proto.version = cipd_package.version
46 if package_proto.path:
47 package_proto.path = cipd_package.path
48
49
50 def _task_summary_to_proto(summary, event):
51 event.proto.swarming_task_event.id = summary.task_id
52
53 request_proto = event.proto.swarming_task_event.request
54 if summary.request.parent_task_id:
55 request_proto.parent_task_id = summary.request.parent_task_id
56 request_proto.name = summary.request.name
57 request_proto.created_ts = _to_timestamp(summary.request.created_ts)
58 request_proto.expiration_ts = _to_timestamp(summary.request.expiration_ts)
59 request_proto.priority = summary.request.priority
60 if summary.request.pubsub_topic:
61 request_proto.pubsub_topic = summary.request.pubsub_topic
62
63 task_properties = summary.request.properties
64 properties_proto = request_proto.properties
65
66 if task_properties.inputs_ref:
67 _files_ref_to_proto(task_properties.inputs_ref, properties_proto.inputs_ref)
68
69 if task_properties.cipd_input:
70 cipd_proto = properties_proto.cipd_input
71 cipd_proto.server = task_properties.cipd_input.server
72
73 _cipd_package_to_proto(task_properties.cipd_input.client_package,
74 cipd_proto.client_package)
75 for package in task_properties.cipd_input.packages:
76 package_proto = cipd_proto.packages.add()
77 _cipd_package_to_proto(package, package_proto)
78
79 for d, t in DIMENSIONS:
80 if d in task_properties.dimensions:
81 getattr(properties_proto.dimensions, d).append(
82 t(task_properties.dimensions[d]))
83
84 if task_properties.execution_timeout_secs:
M-A Ruel 2016/12/06 15:40:09 it is always set; no need for condition
85 properties_proto.execution_timeout_s = task_properties.execution_timeout_sec s
86 if task_properties.grace_period_secs:
M-A Ruel 2016/12/06 15:40:09 same here, and io_timeout
Paweł Hajdan Jr. 2016/12/07 20:27:56 I'm getting exceptions if I remove. For _some_ of
M-A Ruel 2016/12/07 21:47:53 Humm that's weird. ok.
87 properties_proto.grace_period_s = task_properties.grace_period_secs
88 if task_properties.io_timeout_secs:
89 properties_proto.io_timeout_s = task_properties.io_timeout_secs
90 properties_proto.idempotent = task_properties.idempotent
91
92 state_enum = event.proto.swarming_task_event.State.DESCRIPTOR.values_by_name
93 if summary.state == task_result.State.COMPLETED:
94 event.proto.swarming_task_event.state = state_enum['COMPLETED'].number
M-A Ruel 2016/12/06 15:40:09 maybe use a string representation instead?
Paweł Hajdan Jr. 2016/12/07 20:27:56 Do you have a more specific suggestion? Please not
M-A Ruel 2016/12/07 21:47:53 Ah, ignore me then
95 elif summary.state == task_result.State.CANCELED:
96 event.proto.swarming_task_event.state = state_enum['CANCELED'].number
97 elif summary.state == task_result.State.BOT_DIED:
98 event.proto.swarming_task_event.state = state_enum['BOT_DIED'].number
99 elif summary.state == task_result.State.TIMED_OUT:
100 event.proto.swarming_task_event.state = state_enum['TIMED_OUT'].number
101 elif summary.state == task_result.State.EXPIRED:
102 event.proto.swarming_task_event.state = state_enum['EXPIRED'].number
103 else:
104 logging.error('Unhandled task state %r', summary.state)
105
106 event.proto.swarming_task_event.bot_id = summary.bot_id
107 event.proto.swarming_task_event.bot_version = summary.bot_version
108
109 for d, t in DIMENSIONS:
110 for v in summary.bot_dimensions.get(d, []):
111 getattr(event.proto.swarming_task_event.bot_dimensions, d).append(t(v))
112
113 for v in summary.server_versions:
114 event.proto.swarming_task_event.server_versions.append(v)
115
116 event.proto.swarming_task_event.internal_failure = summary.internal_failure
117 event.proto.swarming_task_event.exit_code = summary.exit_code
118 if summary.started_ts:
119 event.proto.swarming_task_event.started_ts = _to_timestamp(
120 summary.started_ts)
121 if summary.completed_ts:
122 event.proto.swarming_task_event.completed_ts = _to_timestamp(
123 summary.completed_ts)
124 if summary.abandoned_ts:
125 event.proto.swarming_task_event.abandoned_ts = _to_timestamp(
126 summary.abandoned_ts)
127
128 for task_id in summary.children_task_ids:
129 event.proto.swarming_task_event.children_task_ids.append(task_id)
130
131 if summary.outputs_ref:
132 _files_ref_to_proto(
133 summary.outputs_ref, event.proto.swarming_task_event.outputs_ref)
134
135 event.proto.swarming_task_event.cost_usd = summary.cost_usd
136 if summary.cost_saved_usd:
137 event.proto.swarming_task_event.cost_saved_usd = summary.cost_saved_usd
138 if summary.deduped_from:
139 event.proto.swarming_task_event.deduped_from = summary.deduped_from
140 event.proto.swarming_task_event.try_number = summary.try_number
141
9 142
10 def initialize(): 143 def initialize():
11 gae_event_mon.initialize('swarming') 144 gae_event_mon.initialize('swarming')
12 145
13 146
14 def send_task_event(task_result_summary): 147 def send_task_event(summary):
15 """Sends an event_mon event about a swarming task. 148 """Sends an event_mon event about a swarming task.
16 149
17 Currently implemented as sending a HTTP request. 150 Currently implemented as sending a HTTP request.
18 151
19 Args: 152 Args:
20 task_result_summary: TaskResultSummary object. 153 summary: TaskResultSummary object.
21 """ 154 """
22 event = gae_event_mon.Event('POINT')
23 event.proto.swarming_task_event.id = task_result_summary.task_id
24
25 # Isolate rest of the app from monitoring pipeline issues. They should 155 # Isolate rest of the app from monitoring pipeline issues. They should
26 # not cause outage of swarming. 156 # not cause outage of swarming.
27 try: 157 try:
158 event = gae_event_mon.Event('POINT')
159 _task_summary_to_proto(summary, event)
28 event.send() 160 event.send()
29 except Exception: 161 except Exception:
30 logging.exception('Caught exception while sending event') 162 logging.exception('Caught exception while sending event')
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698