def _AlertRowDict(alert):
  """Returns a dict with information to print about one stoppage alert."""
  test_path = utils.TestPath(alert.test)
  return {
      'rev': alert.revision,
      'test_path': test_path,
      'graph_link': email_template.GetReportPageLink(test_path),
      'stdio_link': _StdioLink(alert),
  }
Exemple #2
0
    def testURLEncoding(self):
        actual_output = email_template.GetReportPageLink(
            'ABC/bot-name/abc-perf-test/passed%', '1415919839')

        self.assertEquals(('https://chromeperf.appspot.com/report?masters=ABC&'
                           'bots=bot-name&tests=abc-perf-test%2Fpassed%25'
                           '&checked=passed%25%2Cpassed%25_ref%2Cref&'
                           'rev=1415919839'), actual_output)

        actual_output_no_host = email_template.GetReportPageLink(
            'ABC/bot-name/abc-perf-test/passed%',
            '1415919839',
            add_protocol_and_host=False)

        self.assertEquals(('/report?masters=ABC&bots=bot-name&tests='
                           'abc-perf-test%2Fpassed%25&checked=passed%25%2C'
                           'passed%25_ref%2Cref&rev=1415919839'),
                          actual_output_no_host)
Exemple #3
0
def _AlertDict(alert_entity):
    """Returns a base dictionary with properties common to all alerts."""
    test_path = utils.TestPath(alert_entity.GetTestMetadataKey())
    test_path_parts = test_path.split('/')
    dashboard_link = email_template.GetReportPageLink(
        test_path, rev=alert_entity.end_revision, add_protocol_and_host=False)
    return {
        'key': alert_entity.key.urlsafe(),
        'group': alert_entity.group.urlsafe() if alert_entity.group else None,
        'start_revision': alert_entity.start_revision,
        'end_revision': alert_entity.end_revision,
        'date': str(alert_entity.timestamp.date()),
        'master': test_path_parts[0],
        'bot': test_path_parts[1],
        'testsuite': test_path_parts[2],
        'test': '/'.join(test_path_parts[3:]),
        'bug_id': alert_entity.bug_id,
        'dashboard_link': dashboard_link,
    }
Exemple #4
0
def GetAnomalyDict(anomaly_entity, bisect_status=None, v2=False):
    """Returns a dictionary for an Anomaly which can be encoded as JSON.

  Args:
    anomaly_entity: An Anomaly entity.
    bisect_status: String status of bisect run.

  Returns:
    A dictionary which is safe to be encoded as JSON.
  """
    test_key = anomaly_entity.GetTestMetadataKey()
    test_path = utils.TestPath(test_key)
    dashboard_link = email_template.GetReportPageLink(
        test_path,
        rev=anomaly_entity.end_revision,
        add_protocol_and_host=False)

    dct = {
        'bug_id': anomaly_entity.bug_id,
        'dashboard_link': dashboard_link,
        'end_revision': anomaly_entity.end_revision,
        'improvement': anomaly_entity.is_improvement,
        'key': anomaly_entity.key.urlsafe(),
        'median_after_anomaly': anomaly_entity.median_after_anomaly,
        'median_before_anomaly': anomaly_entity.median_before_anomaly,
        'recovered': anomaly_entity.recovered,
        'start_revision': anomaly_entity.start_revision,
        'units': anomaly_entity.units,
    }

    if v2:
        bug_labels = set()
        bug_components = set()
        if anomaly_entity.internal_only:
            bug_labels.add('Restrict-View-Google')
        tags = bug_label_patterns.GetBugLabelsForTest(test_key)
        if anomaly_entity.sheriff:
            try:
                tags += anomaly_entity.sheriff.get().labels
            except AssertionError:
                # The Sheriff is internal_only even though the alert isn't.
                pass
        for tag in tags:
            if tag.startswith('Cr-'):
                bug_components.add(tag.replace('Cr-', '').replace('-', '>'))
            else:
                bug_labels.add(tag)

        dct['bug_components'] = list(bug_components)
        dct['bug_labels'] = list(bug_labels)

        desc = descriptor.Descriptor.FromTestPathSync(test_path)
        dct['descriptor'] = {
            'testSuite': desc.test_suite,
            'measurement': desc.measurement,
            'bot': desc.bot,
            'testCase': desc.test_case,
            'statistic': desc.statistic,
        }
        dct['pinpoint_bisects'] = anomaly_entity.pinpoint_bisects
    else:
        test_path_parts = test_path.split('/')
        dct['absolute_delta'] = '%s' % anomaly_entity.GetDisplayAbsoluteChanged(
        )
        dct['bisect_status'] = bisect_status
        dct['bot'] = test_path_parts[1]
        dct['date'] = str(anomaly_entity.timestamp.date())
        dct['display_end'] = anomaly_entity.display_end
        dct['display_start'] = anomaly_entity.display_start
        dct['master'] = test_path_parts[0]
        dct['percent_changed'] = '%s' % anomaly_entity.GetDisplayPercentChanged(
        )
        dct['ref_test'] = anomaly_entity.GetRefTestPath()
        dct['test'] = '/'.join(test_path_parts[3:])
        dct['testsuite'] = test_path_parts[2]
        dct['timestamp'] = anomaly_entity.timestamp.isoformat()
        dct['type'] = 'anomaly'

    return dct