Ejemplo n.º 1
0
    def _ShowAlerts(self, alert_list, bug_id=None):
        """Responds to an XHR from /group_report page with a JSON list of alerts.

    Args:
      alert_list: A list of Anomaly and/or StoppageAlert entities.
      bug_id: An integer bug ID.
    """
        anomaly_dicts = alerts.AnomalyDicts(
            [a for a in alert_list if a.key.kind() == 'Anomaly'])
        stoppage_alert_dicts = alerts.StoppageAlertDicts(
            [a for a in alert_list if a.key.kind() == 'StoppageAlert'])
        alert_dicts = anomaly_dicts + stoppage_alert_dicts

        values = {
            'alert_list': alert_dicts[:_DISPLAY_LIMIT],
            # This code for getting the subtests is supposed to be used to sort out
            # which metrics are "core" vs "non-core". But it's extremely slow, and
            # also doesn't seem to work very well. Turn it off for now:
            # https://github.com/catapult-project/catapult/issues/2877
            #'subtests': _GetSubTestsForAlerts(alert_dicts),
            'bug_id': bug_id,
            'test_suites': update_test_suites.FetchCachedTestSuites(),
        }
        self.GetDynamicVariables(values)

        self.response.out.write(json.dumps(values))
Ejemplo n.º 2
0
    def _GetAlerts(self, *args):
        alert_list = None
        list_type = args[0]
        try:
            if list_type.startswith('bug_id'):
                bug_id = list_type.replace('bug_id/', '')
                alert_list, _ = group_report.GetAlertsWithBugId(bug_id)
            elif list_type.startswith('keys'):
                keys = list_type.replace('keys/', '').split(',')
                alert_list, _ = group_report.GetAlertsForKeys(keys)
            elif list_type.startswith('rev'):
                rev = list_type.replace('rev/', '')
                alert_list, _ = group_report.GetAlertsAroundRevision(rev)
            else:
                raise BadRequestError('Invalid alert type %s' % list_type)
        except request_handler.InvalidInputError as e:
            raise BadRequestError(e.message)

        anomaly_dicts = alerts.AnomalyDicts(
            [a for a in alert_list if a.key.kind() == 'Anomaly'])
        stoppage_alert_dicts = alerts.StoppageAlertDicts(
            [a for a in alert_list if a.key.kind() == 'StoppageAlert'])

        response = {}
        if anomaly_dicts:
            response['anomalies'] = anomaly_dicts
        if stoppage_alert_dicts:
            response['stoppage_alerts'] = stoppage_alert_dicts

        return response
Ejemplo n.º 3
0
    def _ShowAlerts(self, alert_list, bug_id=None):
        """Responds to an XHR from /group_report page with a JSON list of alerts.

    Args:
      alert_list: A list of Anomaly and/or StoppageAlert entities.
      bug_id: An integer bug ID.
    """
        anomaly_dicts = alerts.AnomalyDicts(
            [a for a in alert_list if a.key.kind() == 'Anomaly'])
        stoppage_alert_dicts = alerts.StoppageAlertDicts(
            [a for a in alert_list if a.key.kind() == 'StoppageAlert'])
        alert_dicts = anomaly_dicts + stoppage_alert_dicts
        owner_info = None
        if bug_id and ndb.Key('Bug', bug_id).get():
            owner_info = _GetOwnerInfo(alert_dicts)

        values = {
            'alert_list': alert_dicts[:_DISPLAY_LIMIT],
            'subtests': _GetSubTestsForAlerts(alert_dicts),
            'bug_id': bug_id,
            'owner_info': owner_info,
            'test_suites': update_test_suites.FetchCachedTestSuites(),
        }
        self.GetDynamicVariables(values)

        self.response.out.write(json.dumps(values))
Ejemplo n.º 4
0
  def _GetAlerts(self, *args):
    alert_list = None
    list_type = args[0]
    try:
      if list_type.startswith('bug_id'):
        bug_id = list_type.replace('bug_id/', '')
        alert_list, _ = group_report.GetAlertsWithBugId(bug_id)
      elif list_type.startswith('keys'):
        keys = list_type.replace('keys/', '').split(',')
        alert_list, _ = group_report.GetAlertsForKeys(keys)
      elif list_type.startswith('rev'):
        rev = list_type.replace('rev/', '')
        alert_list, _ = group_report.GetAlertsAroundRevision(rev)
      elif list_type.startswith('history'):
        try:
          days = int(list_type.replace('history/', ''))
        except ValueError:
          days = 7
        cutoff = datetime.datetime.now() - datetime.timedelta(days=days)
        sheriff_name = self.request.get('sheriff', 'Chromium Perf Sheriff')
        sheriff_key = ndb.Key('Sheriff', sheriff_name)
        sheriff = sheriff_key.get()
        if not sheriff:
          raise BadRequestError('Invalid sheriff %s' % sheriff_name)
        include_improvements = bool(self.request.get('improvements'))
        query = anomaly.Anomaly.query(anomaly.Anomaly.sheriff == sheriff_key)
        query = query.filter(anomaly.Anomaly.timestamp > cutoff)
        if not include_improvements:
          query = query.filter(
              anomaly.Anomaly.is_improvement == False)

        query = query.order(-anomaly.Anomaly.timestamp)
        alert_list = query.fetch()
      else:
        raise BadRequestError('Invalid alert type %s' % list_type)
    except request_handler.InvalidInputError as e:
      raise BadRequestError(e.message)

    anomaly_dicts = alerts.AnomalyDicts(
        [a for a in alert_list if a.key.kind() == 'Anomaly'])
    stoppage_alert_dicts = alerts.StoppageAlertDicts(
        [a for a in alert_list if a.key.kind() == 'StoppageAlert'])

    response = {}
    if anomaly_dicts:
      response['anomalies'] = anomaly_dicts
    if stoppage_alert_dicts:
      response['stoppage_alerts'] = stoppage_alert_dicts

    return response
Ejemplo n.º 5
0
  def _ShowAlerts(self, alert_list, selected_keys=None, bug_id=None):
    """Responds to an XHR from /group_report page with a JSON list of alerts.

    Args:
      alert_list: A list of Anomaly and/or StoppageAlert entities.
      bug_id: An integer bug ID.
    """
    anomaly_dicts = alerts.AnomalyDicts(
        [a for a in alert_list if a.key.kind() == 'Anomaly'])
    stoppage_alert_dicts = alerts.StoppageAlertDicts(
        [a for a in alert_list if a.key.kind() == 'StoppageAlert'])
    alert_dicts = anomaly_dicts + stoppage_alert_dicts

    values = {
        'alert_list': alert_dicts[:_DISPLAY_LIMIT],
        'bug_id': bug_id,
        'test_suites': update_test_suites.FetchCachedTestSuites(),
        'selected_keys': selected_keys,
    }
    self.GetDynamicVariables(values)

    self.response.out.write(json.dumps(values))
Ejemplo n.º 6
0
  def _ShowAlerts(self, alert_list, bug_id=None):
    """Renders the template group_report.html with a list of alerts.

    Args:
      alert_list: A list of Anomaly and/or StoppageAlert entities.
      bug_id: An integer bug ID.
    """
    anomaly_dicts = alerts.AnomalyDicts(
        [a for a in alert_list if a.key.kind() == 'Anomaly'])
    stoppage_alert_dicts = alerts.StoppageAlertDicts(
        [a for a in alert_list if a.key.kind() == 'StoppageAlert'])
    alert_dicts = anomaly_dicts + stoppage_alert_dicts
    owner_info = None
    if bug_id and ndb.Key('Bug', bug_id).get():
      owner_info = _GetOwnerInfo(alert_dicts)

    self.RenderHtml('group_report.html', {
        'alert_list': json.dumps(alert_dicts[:_DISPLAY_LIMIT]),
        'subtests': json.dumps(_GetSubTestsForAlerts(alert_dicts)),
        'bug_id': bug_id,
        'owner_info': json.dumps(owner_info),
        'test_suites': json.dumps(update_test_suites.FetchCachedTestSuites()),
    })
Ejemplo n.º 7
0
    def post(self):
        """Returns dynamic data for /group_report with some set of alerts.

    The set of alerts is determined by the sid, keys, bug ID, or revision given.

    Request parameters:
      keys: A comma-separated list of urlsafe Anomaly keys (optional).
      bug_id: A bug number on the Chromium issue tracker (optional).
      rev: A revision number (optional).
      sid: A hash of a group of keys from /short_uri (optional).

    Outputs:
      JSON for the /group_report page XHR request.
    """
        bug_id = self.request.get('bug_id')
        rev = self.request.get('rev')
        keys = self.request.get('keys')
        hash_code = self.request.get('sid')

        # sid takes precedence.
        if hash_code:
            state = ndb.Key(page_state.PageState, hash_code).get()
            if state:
                keys = json.loads(state.value)
        elif keys:
            keys = keys.split(',')

        try:
            alert_list = None
            if bug_id:
                alert_list, extra_columns = GetAlertsWithBugId(bug_id)
            elif keys:
                alert_list, extra_columns = GetAlertsForKeys(keys)
            elif rev:
                alert_list, extra_columns = GetAlertsAroundRevision(rev)
            else:
                # TODO(qyearsley): Instead of just showing an error here, show a form
                # where the user can input a bug ID or revision.
                raise request_handler.InvalidInputError(
                    'No anomalies specified.')

            anomaly_dicts = alerts.AnomalyDicts(
                [a for a in alert_list if a.key.kind() == 'Anomaly'])
            stoppage_alert_dicts = alerts.StoppageAlertDicts(
                [a for a in alert_list if a.key.kind() == 'StoppageAlert'])
            alert_dicts = anomaly_dicts + stoppage_alert_dicts

            values = {
                'alert_list': alert_dicts[:_DISPLAY_LIMIT],
                'extra_columns': extra_columns,
                'test_suites': update_test_suites.FetchCachedTestSuites(),
            }
            if bug_id:
                values['bug_id'] = bug_id
            if keys:
                values['selected_keys'] = keys
            self.GetDynamicVariables(values)

            self.response.out.write(json.dumps(values))
        except request_handler.InvalidInputError as error:
            self.response.out.write(json.dumps({'error': str(error)}))