def to_dict(self): return { 'key': self.key.id() if type(self.key.id()) != long else None, 'timestamp': to_unix_timestamp(self.timestamp), 'tags': self.tags, 'fields': self.fields, }
def to_dict(self): return { 'key': self.key.id() if not isinstance(self.key.id(), long) else None, 'timestamp': to_unix_timestamp(self.timestamp), 'tags': self.tags, 'fields': self.fields, }
def rietveld_timestamp(timestamp_string): # pragma: no cover """Converts a Rietveld timestamp into a unix timestamp.""" try: return to_unix_timestamp( datetime.strptime(timestamp_string, RIETVELD_TIMESTAMP_FORMAT)) except ValueError: return None
def to_dict(self, name_filter=None): """Returns a JSON friendly dict If the name filter is falsey it is ignored. """ def combined_stats(): for stats in self.count_stats + self.list_stats: if not name_filter or self.stats_matches_names(stats, name_filter): yield stats.to_dict() return { 'key': self.key.id(), 'interval_minutes': self.interval_minutes, 'begin': to_unix_timestamp(self.begin), 'end': to_unix_timestamp(self.end), 'project': self.project, 'stats': list(combined_stats()), }
def rietveld_timestamp(timestamp_string): try: return to_unix_timestamp( datetime.strptime(timestamp_string, RIETVELD_TIMESTAMP_FORMAT)) except ValueError: logging.warning('Failed to parse Rietveld timestamp: ' + timestamp_string) return None
def parse_rietveld_timestamp(timestamp_string): """Converts a Rietveld timestamp into a unix timestamp.""" for rietveld_ts_format in RIETVELD_TIMESTAMP_FORMATS: try: return to_unix_timestamp( datetime.strptime(timestamp_string, rietveld_ts_format)) except ValueError: pass return None
def test_to_unix_timestamp(self): self.assertEquals( 100, utils.to_unix_timestamp(datetime.utcfromtimestamp(100))) self.assertEquals( 100.1, utils.to_unix_timestamp(datetime.utcfromtimestamp(100.1))) self.assertEquals( 100.5, utils.to_unix_timestamp(datetime.utcfromtimestamp(100.5))) self.assertEquals( 100.9, utils.to_unix_timestamp(datetime.utcfromtimestamp(100.9))) self.assertEquals( -100, utils.to_unix_timestamp(datetime.utcfromtimestamp(-100))) self.assertEquals( -100.1, utils.to_unix_timestamp(datetime.utcfromtimestamp(-100.1)))
def test_to_unix_timestamp(self): self.assertEquals(100, utils.to_unix_timestamp(datetime.utcfromtimestamp(100))) self.assertEquals(100.1, utils.to_unix_timestamp(datetime.utcfromtimestamp(100.1))) self.assertEquals(100.5, utils.to_unix_timestamp(datetime.utcfromtimestamp(100.5))) self.assertEquals(100.9, utils.to_unix_timestamp(datetime.utcfromtimestamp(100.9))) self.assertEquals(-100, utils.to_unix_timestamp(datetime.utcfromtimestamp(-100))) self.assertEquals(-100.1, utils.to_unix_timestamp(datetime.utcfromtimestamp(-100.1)))
def get(self, codereview_hostname, issue, patch): # pylint: disable=W0221 now = utils.to_unix_timestamp(datetime.utcnow()) return summarize_patch(codereview_hostname, issue, patch, now)
def summarize_attempt(raw_attempt, now): assert len(raw_attempt) > 0 start_timestamp = utils.to_unix_timestamp(raw_attempt[0].timestamp) summary = blank_attempt_summary() job_tracker = AttemptJobTracker(start_timestamp) durations = summary['durations'] last_patch_action = None last_patch_timestamp = None verifier_start_timestamp = None for record in raw_attempt: action = record.fields.get('action') # patch_ready_to_commit signals are noisy and not useful. if action == 'patch_ready_to_commit': continue verifier = record.fields.get('verifier') timestamp = utils.to_unix_timestamp(record.timestamp) if last_patch_action: patch_state_duration = timestamp - last_patch_timestamp # Verifier job updates. if verifier == TRYJOBVERIFIER: if action == 'verifier_start': verifier_start_timestamp = timestamp elif action == 'verifier_jobs_update': job_tracker.update_jobs(record) elif (action in ('verifier_pass', 'verifier_fail') and verifier_start_timestamp is not None): durations['running_all_jobs'] = timestamp - verifier_start_timestamp verifier_start_timestamp = None # Patch state updates. if action and action.startswith('patch_'): if last_patch_action == 'patch_throttled': durations['blocked_on_throttled_tree'] += patch_state_duration if last_patch_action == 'patch_tree_closed': durations['blocked_on_closed_tree'] += patch_state_duration if action == 'patch_committed': summary['success'] = True if last_patch_action == 'patch_committing': # pragma: no branch durations['committing'] += patch_state_duration if action == 'patch_failed': summary['success'] = False summary['fail_reason'] = record.fields.get('reason') if action == 'patch_stop': summary['end'] = timestamp if action and action.startswith('patch_'): last_patch_action = action last_patch_timestamp = timestamp # Finalize attempt durations. summary['begin'] = start_timestamp if summary['end'] != None: # pragma: no branch durations['total'] = summary['end'] - summary['begin'] last_timestamp = summary['end'] or now if last_patch_action: # pragma: no branch patch_state_duration = last_timestamp - last_patch_timestamp if last_patch_action == 'patch_tree_closed': # pragma: no cover durations['blocked_on_closed_tree'] += patch_state_duration if last_patch_action == 'patch_throttled': # pragma: no cover durations['blocked_on_throttled_tree'] += patch_state_duration if last_patch_action == 'patch_committing': # pragma: no cover durations['committing'] += patch_state_duration if verifier_start_timestamp: # pragma: no cover durations['running_all_jobs'] = last_timestamp - verifier_start_timestamp # Finalize jobs and job durations. summary['jobs'] = job_tracker.summarize_jobs( summary['success'] != None, last_timestamp) return summary
def summarize_attempt(raw_attempt, now): # pragma: no cover assert len(raw_attempt) > 0 start_timestamp = to_unix_timestamp(raw_attempt[0].timestamp) summary = blank_attempt_summary() job_tracker = AttemptJobTracker(start_timestamp) durations = summary["durations"] last_patch_action = None last_patch_timestamp = None verifier_start_timestamp = None for record in raw_attempt: action = record.fields.get("action") # patch_ready_to_commit signals are noisy and not useful. if action == "patch_ready_to_commit": continue verifier = record.fields.get("verifier") timestamp = to_unix_timestamp(record.timestamp) if last_patch_action: patch_state_duration = timestamp - last_patch_timestamp # Verifier job updates. if verifier == TRYJOBVERIFIER: if action == "verifier_start": verifier_start_timestamp = timestamp elif action == "verifier_jobs_update": job_tracker.update_jobs(record) elif action in ("verifier_pass", "verifier_fail"): durations["running_all_jobs"] = timestamp - verifier_start_timestamp verifier_start_timestamp = None # Patch state updates. if action and action.startswith("patch_"): if last_patch_action == "patch_throttled": durations["blocked_on_throttled_tree"] += patch_state_duration if last_patch_action == "patch_tree_closed": durations["blocked_on_closed_tree"] += patch_state_duration if action == "patch_committed": summary["success"] = True if last_patch_action == "patch_committing": durations["committing"] += patch_state_duration if action == "patch_failed": summary["success"] = False summary["fail_reason"] = record.fields.get("reason") if action == "patch_stop": summary["end"] = timestamp if action and action.startswith("patch_"): last_patch_action = action last_patch_timestamp = timestamp # Finalize attempt durations. summary["begin"] = start_timestamp if summary["end"] != None: durations["total"] = summary["end"] - summary["begin"] last_timestamp = summary["end"] or now if last_patch_action: patch_state_duration = last_timestamp - last_patch_timestamp if last_patch_action == "patch_tree_closed": durations["blocked_on_closed_tree"] += patch_state_duration if last_patch_action == "patch_throttled": durations["blocked_on_throttled_tree"] += patch_state_duration if last_patch_action == "patch_committing": durations["committing"] += patch_state_duration if verifier_start_timestamp: durations["running_all_jobs"] = last_timestamp - verifier_start_timestamp # Finalize jobs and job durations. summary["jobs"] = job_tracker.summarize_jobs(summary["success"] != None, last_timestamp) return summary
def get(self, issue, patch): # pylint: disable=W0221 now = to_unix_timestamp(datetime.utcnow()) return summarize_patch(issue, patch, now)
def rietveld_timestamp(timestamp_string): try: return to_unix_timestamp(datetime.strptime(timestamp_string, RIETVELD_TIMESTAMP_FORMAT)) except ValueError: logging.warning("Failed to parse Rietveld timestamp: " + timestamp_string) return None