Exemple #1
0
    def testPost_WithTimestamp_RespondsWithNewLogs(self):
        logger = quick_logger.QuickLogger('test_namespace', 'test_name')
        logger.Log('First message.')
        logger.Log('Second message.')
        # Set back the time on these records.
        logger._records[0].timestamp -= 1
        logger._records[1].timestamp -= 2
        logger.Save()
        response = self.testapp.post('/get_logs', {
            'namespace': 'test_namespace',
            'name': 'test_name',
            'size': 100
        })
        response_logs = json.loads(response.body)
        self.assertEqual(2, len(response_logs))

        logger.Log('Third message.')
        logger.Save()

        response = self.testapp.post(
            '/get_logs', {
                'namespace': 'test_namespace',
                'name': 'test_name',
                'size': 100,
                'after_timestamp': repr(response_logs[0]['timestamp'])
            })

        response_logs = json.loads(response.body)
        self.assertEqual(1, len(response_logs))
        self.assertEqual('Third message.', response_logs[0]['message'])
Exemple #2
0
    def testQuickLogger_LoggingWithId_UpdatesExistingLog(self):
        logger = quick_logger.QuickLogger('a_namespace', 'a_log_name')
        first_id = logger.Log('First message.')
        logger.Log('Second message.')
        logger.Log('Third message.')
        logger.Save()

        logger = quick_logger.QuickLogger('a_namespace', 'a_log_name')
        logger.Log('Updated first message.', first_id)
        logger.Save()

        logs = quick_logger.Get('a_namespace', 'a_log_name')
        self.assertEqual(3, len(logs))
        self.assertEqual('Updated first message.', logs[0].message)
        self.assertEqual('Third message.', logs[1].message)
        self.assertEqual('Second message.', logs[2].message)
Exemple #3
0
 def testQuickLogger_LogSizeAndNumberAtSizeLimit(self):
     logger = quick_logger.QuickLogger('a_namespace', 'a_log_name')
     for i in xrange(quick_logger._MAX_NUM_RECORD):
         logger.Log(str(i % 2) * quick_logger._MAX_MSG_SIZE)
     logger.Save()
     logs = quick_logger.Get('a_namespace', 'a_log_name')
     self.assertEqual(len(logs), quick_logger._MAX_NUM_RECORD)
Exemple #4
0
def LogBisectResult(bug_id, comment):
  """Adds an entry to the bisect result log for a particular bug."""
  if not bug_id or bug_id < 0:
    return
  formatter = quick_logger.Formatter()
  logger = quick_logger.QuickLogger('bisect_result', bug_id, formatter)
  logger.Log(comment)
  logger.Save()
def _AddReportToLog(report_dict):
    """Adds a log for bench results."""
    report = _REPORT_TEMPLATE % report_dict
    formatter = quick_logger.Formatter()
    logger = quick_logger.QuickLogger('bench_find_anomalies', 'report',
                                      formatter)
    logger.Log(report)
    logger.Save()
Exemple #6
0
 def testQuickLogger_MultipleLogs_UsesCorrectOrder(self):
     logger = quick_logger.QuickLogger('a_namespace', 'a_log_name')
     for i in xrange(quick_logger._MAX_NUM_RECORD + 10):
         logger.Log(i)
     logger.Save()
     logs = quick_logger.Get('a_namespace', 'a_log_name')
     self.assertEqual(len(logs), quick_logger._MAX_NUM_RECORD)
     # First record is the last log added.
     self.assertEqual(logs[0].message,
                      str(quick_logger._MAX_NUM_RECORD + 9))
def UpdateQuickLog(job):
    report = bisect_report.GetReport(job)
    if not report:
        logging.error('Bisect report returns empty for job id %s, bug_id %s.',
                      job.key.id(), job.bug_id)
        return
    formatter = quick_logger.Formatter()
    logger = quick_logger.QuickLogger('bisect_result', job.bug_id, formatter)
    logger.Log(report)
    logger.Save()
 def testQuickLogger(self):
   """Tests basic logging."""
   template = '{message}{extra}'
   formatter = quick_logger.Formatter(template, extra='!')
   logger = quick_logger.QuickLogger('a_namespace', 'a_log_name', formatter)
   logger.Log('Hello %s', 'world')
   logger.Save()
   logs = quick_logger.Get('a_namespace', 'a_log_name')
   self.assertEqual(len(logs), 1)
   self.assertEqual(logs[0].message, 'Hello world!')
Exemple #9
0
 def testQuickLogger_SaveAndGetNewLogEntry(self):
     template = '{message}{extra}'
     formatter = quick_logger.Formatter(template, extra='!')
     logger = quick_logger.QuickLogger('a_namespace', 'a_log_name',
                                       formatter)
     logger.Log('Hello world')
     logger.Save()
     logs = quick_logger.Get('a_namespace', 'a_log_name')
     self.assertEqual(len(logs), 1)
     self.assertEqual(logs[0].message, 'Hello world!')
Exemple #10
0
def _LogBisectInfraFailure(bug_id, failure_message, stdio_url):
    """Adds infrastructure related bisect failures to log."""
    comment = failure_message + '\n'
    comment += ('<a href="https://chromeperf.appspot.com/group_report?'
                'bug_id=%s">%s</a>\n' % (bug_id, bug_id))
    comment += 'Buildbot stdio: <a href="%s">%s</a>\n' % (stdio_url, stdio_url)
    formatter = quick_logger.Formatter()
    logger = quick_logger.QuickLogger('bisect_failures', 'infra', formatter)
    logger.Log(comment)
    logger.Save()
Exemple #11
0
def LogBisectResult(bug_id, comment):
    """Adds bisect results to log.

  Args:
    bug_id: ID of the issue.
    comment: Bisect results information.
  """
    if not bug_id or bug_id < 0:
        return
    formatter = quick_logger.Formatter()
    logger = quick_logger.QuickLogger('bisect_result', bug_id, formatter)
    logger.Log(comment)
    logger.Save()
Exemple #12
0
def LogBisectResult(job, comment):
    """Adds an entry to the bisect result log for a particular bug."""
    if not job.bug_id or job.bug_id < 0:
        return
    formatter = quick_logger.Formatter()
    logger = quick_logger.QuickLogger('bisect_result', job.bug_id, formatter)
    if job.log_record_id:
        logger.Log(comment, record_id=job.log_record_id)
        logger.Save()
    else:
        job.log_record_id = logger.Log(comment)
        logger.Save()
        job.put()
Exemple #13
0
def _AddLogForRecoveredAnomaly(anomaly_entity):
    """Adds a quick log entry for an anomaly that has recovered."""
    formatter = quick_logger.Formatter()
    sheriff_key = anomaly_entity.test.get().sheriff
    if not sheriff_key:
        return
    sheriff_name = sheriff_key.string_id()
    logger = quick_logger.QuickLogger('auto_triage', sheriff_name, formatter)
    logger.Log('Alert on %s has recovered. See <a href="%s">graph</a>.%s',
               utils.TestPath(anomaly_entity.test),
               ('https://chromeperf.appspot.com/group_report?keys=' +
                anomaly_entity.key.urlsafe()), _BugLink(anomaly_entity))
    logger.Save()
Exemple #14
0
def _AddLogForBugAssociate(anomaly_entity, bug_id):
  """Adds a log for associating alert with a bug."""
  sheriff = anomaly_entity.test.get().sheriff
  if not sheriff:
    return
  # TODO(qyearsley): Add test coverage. See http://crbug.com/447432
  sheriff = sheriff.string_id()
  html_str = 'Associated alert on %s with bug <a href="%s">%s</a>.'
  bug_url = ('https://chromeperf.appspot.com/group_report?bug_id=' +
             str(bug_id))
  test_path = utils.TestPath(anomaly_entity.test)
  formatter = quick_logger.Formatter()
  logger = quick_logger.QuickLogger('auto_triage', sheriff, formatter)
  logger.Log(html_str, test_path, bug_url, bug_id)
  logger.Save()
Exemple #15
0
def _AddLogForBugAssociate(anomaly_entity):
  """Adds a log for associating alert with a bug."""
  bug_id = anomaly_entity.bug_id
  sheriff = anomaly_entity.GetTestMetadataKey().get().sheriff
  if not sheriff:
    return
  sheriff = sheriff.string_id()
  bug_url = ('https://chromeperf.appspot.com/group_report?bug_id=' +
             str(bug_id))
  test_path = utils.TestPath(anomaly_entity.GetTestMetadataKey())
  html_str = ('Associated alert on %s with bug <a href="%s">%s</a>.' %
              (test_path, bug_url, bug_id))
  formatter = quick_logger.Formatter()
  logger = quick_logger.QuickLogger('auto_triage', sheriff, formatter)
  logger.Log(html_str)
  logger.Save()
Exemple #16
0
def UpdateQuickLog(job):
    if not job.bug_id or job.bug_id < 0:
        return
    report = bisect_report.GetReport(job)
    if not report:
        logging.error('Bisect report returns empty for job id %s, bug_id %s.',
                      job.key.id(), job.bug_id)
        return
    formatter = quick_logger.Formatter()
    logger = quick_logger.QuickLogger('bisect_result', job.bug_id, formatter)
    if job.log_record_id:
        logger.Log(report, record_id=job.log_record_id)
        logger.Save()
    else:
        job.log_record_id = logger.Log(report)
        logger.Save()
        job.put()
Exemple #17
0
def _AddLogForRecoveredAnomaly(anomaly_entity, bug_id=None):
  """Adds a log for an anomaly that has recovered."""
  sheriff_key = anomaly_entity.test.get().sheriff
  if not sheriff_key:
    return
  sheriff_name = sheriff_key.string_id()
  html_str = 'Alert on %s has recovered.%s See <a href="%s">graph</a>.'
  alert_url = ('https://chromeperf.appspot.com/group_report?keys=' +
               anomaly_entity.key.urlsafe())
  bug_link = ''
  if bug_id:
    bug_link = (' Bug: <a href="https://chromeperf.appspot.com/group_report?'
                'bug_id=%s">%s</a>' % (bug_id, bug_id))

  test_path = utils.TestPath(anomaly_entity.test)
  formatter = quick_logger.Formatter()
  logger = quick_logger.QuickLogger('auto_triage', sheriff_name, formatter)
  logger.Log(html_str, test_path, bug_link, alert_url)
  logger.Save()
Exemple #18
0
def _LogFeedback(try_job_id, email):
    formatter = quick_logger.Formatter()
    logger = quick_logger.QuickLogger('bad_bisect', 'report', formatter)
    message = '%s marked try job %d.' % (email, try_job_id)
    logger.Log(message)
    logger.Save()
Exemple #19
0
 def testQuickLogger_MultipleLogs_RecordIsUnique(self):
     first_logger = quick_logger.QuickLogger('a_namespace', 'a_log_name')
     second_logger = quick_logger.QuickLogger('a_namespace', 'a_log_name')
     first_id = first_logger.Log('First message.')
     second_id = second_logger.Log('Second message.')
     self.assertNotEqual(first_id, second_id)
Exemple #20
0
def _AddReportToLog(report):
    """Adds a log for bench results."""
    formatter = quick_logger.Formatter()
    logger = quick_logger.QuickLogger('task_runner', 'report', formatter)
    logger.Log(report)
    logger.Save()