Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2014 The LUCI Authors. All rights reserved. | 1 # Copyright 2014 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed by the Apache v2.0 license that can be | 2 # Use of this source code is governed by the Apache v2.0 license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Task execution result models. | 5 """Task execution result models. |
| 6 | 6 |
| 7 This module doesn't do the scheduling itself. It only describes the entities to | 7 This module doesn't do the scheduling itself. It only describes the entities to |
| 8 store tasks results. | 8 store tasks results. |
| 9 | 9 |
| 10 - TaskResultSummary represents the overall result for the TaskRequest taking in | 10 - TaskResultSummary represents the overall result for the TaskRequest taking in |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 # gaps is a series of 2 integer pairs, which specifies the part that are | 240 # gaps is a series of 2 integer pairs, which specifies the part that are |
| 241 # invalid. Normally it should be empty. All values are relative to the start | 241 # invalid. Normally it should be empty. All values are relative to the start |
| 242 # of this chunk offset. | 242 # of this chunk offset. |
| 243 gaps = ndb.IntegerProperty(repeated=True, indexed=False) | 243 gaps = ndb.IntegerProperty(repeated=True, indexed=False) |
| 244 | 244 |
| 245 @property | 245 @property |
| 246 def chunk_number(self): | 246 def chunk_number(self): |
| 247 return self.key.integer_id() - 1 | 247 return self.key.integer_id() - 1 |
| 248 | 248 |
| 249 | 249 |
| 250 class IsolatedOperation(ndb.Model): | 250 class OperationStats(ndb.Model): |
| 251 """Statistics for an isolated operation. | 251 """Statistics for an isolated operation. |
|
M-A Ruel
2016/04/28 21:03:29
s/isolated //
nodir
2016/04/28 21:10:17
Done.
| |
| 252 | 252 |
| 253 This entity is not stored in the DB. It is only embedded in PerformanceStats. | 253 This entity is not stored in the DB. It is only embedded in PerformanceStats. |
| 254 """ | 254 """ |
| 255 # Duration of the isolation operation in seconds. | 255 # Duration of the isolation operation in seconds. |
| 256 duration = ndb.FloatProperty(indexed=False) | 256 duration = ndb.FloatProperty(indexed=False) |
| 257 # Initial cache size, if applicable. | 257 # Initial cache size, if applicable. |
| 258 initial_number_items = ndb.IntegerProperty(indexed=False) | 258 initial_number_items = ndb.IntegerProperty(indexed=False) |
| 259 initial_size = ndb.IntegerProperty(indexed=False) | 259 initial_size = ndb.IntegerProperty(indexed=False) |
| 260 # Items operated on. | 260 # Items operated on. |
| 261 # These buffers are compressed as deflate'd delta-encoded varints. See | 261 # These buffers are compressed as deflate'd delta-encoded varints. See |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 283 it is generally operating on data that is used across multiple different | 283 it is generally operating on data that is used across multiple different |
| 284 tasks. | 284 tasks. |
| 285 | 285 |
| 286 This entity only exist for isolated tasks. For "raw command task", this entity | 286 This entity only exist for isolated tasks. For "raw command task", this entity |
| 287 is not stored, since there's nothing to note. | 287 is not stored, since there's nothing to note. |
| 288 """ | 288 """ |
| 289 # Miscellaneous overhead in second, in addition to the overhead from | 289 # Miscellaneous overhead in second, in addition to the overhead from |
| 290 # isolated_download.duration and isolated_upload.duration. | 290 # isolated_download.duration and isolated_upload.duration. |
| 291 bot_overhead = ndb.FloatProperty(indexed=False) | 291 bot_overhead = ndb.FloatProperty(indexed=False) |
| 292 # Runtime dependencies download operation before the task. | 292 # Runtime dependencies download operation before the task. |
| 293 isolated_download = ndb.LocalStructuredProperty(IsolatedOperation) | 293 isolated_download = ndb.LocalStructuredProperty(OperationStats) |
| 294 # Results uploading operation after the task. | 294 # Results uploading operation after the task. |
| 295 isolated_upload = ndb.LocalStructuredProperty(IsolatedOperation) | 295 isolated_upload = ndb.LocalStructuredProperty(OperationStats) |
| 296 | 296 |
| 297 @property | 297 @property |
| 298 def is_valid(self): | 298 def is_valid(self): |
| 299 return self.bot_overhead is not None | 299 return self.bot_overhead is not None |
| 300 | 300 |
| 301 def _pre_put_hook(self): | 301 def _pre_put_hook(self): |
| 302 if self.bot_overhead is None: | 302 if self.bot_overhead is None: |
| 303 raise datastore_errors.BadValueError( | 303 raise datastore_errors.BadValueError( |
| 304 'PerformanceStats.bot_overhead is required') | 304 'PerformanceStats.bot_overhead is required') |
| 305 | 305 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 | 437 |
| 438 Returns an empty instance if none is available. | 438 Returns an empty instance if none is available. |
| 439 """ | 439 """ |
| 440 # Keeps a cache. It's still paying the full latency cost of a DB fetch. | 440 # Keeps a cache. It's still paying the full latency cost of a DB fetch. |
| 441 if not hasattr(self, '_performance_stats_cache'): | 441 if not hasattr(self, '_performance_stats_cache'): |
| 442 key = None if self.deduped_from else self.performance_stats_key | 442 key = None if self.deduped_from else self.performance_stats_key |
| 443 # pylint: disable=attribute-defined-outside-init | 443 # pylint: disable=attribute-defined-outside-init |
| 444 self._performance_stats_cache = ( | 444 self._performance_stats_cache = ( |
| 445 (key.get() if key else None) or | 445 (key.get() if key else None) or |
| 446 PerformanceStats( | 446 PerformanceStats( |
| 447 isolated_download=IsolatedOperation(), | 447 isolated_download=OperationStats(), |
| 448 isolated_upload=IsolatedOperation())) | 448 isolated_upload=OperationStats())) |
| 449 return self._performance_stats_cache | 449 return self._performance_stats_cache |
| 450 | 450 |
| 451 @property | 451 @property |
| 452 def overhead_isolated_inputs(self): | 452 def overhead_isolated_inputs(self): |
| 453 """Returns the overhead from isolated setup in timedelta.""" | 453 """Returns the overhead from isolated setup in timedelta.""" |
| 454 perf = self.performance_stats | 454 perf = self.performance_stats |
| 455 if perf.isolated_download.duration is not None: | 455 if perf.isolated_download.duration is not None: |
| 456 return datetime.timedelta(seconds=perf.isolated_download.duration) | 456 return datetime.timedelta(seconds=perf.isolated_download.duration) |
| 457 | 457 |
| 458 @property | 458 @property |
| (...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1229 if tags: | 1229 if tags: |
| 1230 # Add TaskResultSummary indexes if desired. | 1230 # Add TaskResultSummary indexes if desired. |
| 1231 if sort != 'created_ts': | 1231 if sort != 'created_ts': |
| 1232 raise ValueError( | 1232 raise ValueError( |
| 1233 'Add needed indexes for sort:%s and tags if desired' % sort) | 1233 'Add needed indexes for sort:%s and tags if desired' % sort) |
| 1234 tags_filter = TaskResultSummary.tags == tags[0] | 1234 tags_filter = TaskResultSummary.tags == tags[0] |
| 1235 for tag in tags[1:]: | 1235 for tag in tags[1:]: |
| 1236 tags_filter = ndb.AND(tags_filter, TaskResultSummary.tags == tag) | 1236 tags_filter = ndb.AND(tags_filter, TaskResultSummary.tags == tag) |
| 1237 query = query.filter(tags_filter) | 1237 query = query.filter(tags_filter) |
| 1238 return _filter_query(TaskResultSummary, query, start, end, sort, state) | 1238 return _filter_query(TaskResultSummary, query, start, end, sort, state) |
| OLD | NEW |