Пример #1
0
 def _AddAlertGroup(anomaly_key,
                    subscription_name=None,
                    issue=None,
                    anomalies=None,
                    status=None,
                    project_id=None,
                    bisection_ids=None):
   anomaly_entity = anomaly_key.get()
   group = alert_group.AlertGroup(
       id=str(uuid.uuid4()),
       name=anomaly_entity.benchmark_name,
       subscription_name=subscription_name or 'sheriff',
       status=alert_group.AlertGroup.Status.untriaged,
       project_id=project_id or 'chromium',
       active=True,
       revision=alert_group.RevisionRange(
           repository='chromium',
           start=anomaly_entity.start_revision,
           end=anomaly_entity.end_revision,
       ),
       bisection_ids=bisection_ids or [],
   )
   if issue:
     group.bug = alert_group.BugInfo(
         bug_id=issue.get('id'),
         project=issue.get('projectId', 'chromium'),
     )
     group.project_id = issue.get('projectId', 'chromium')
   if anomalies:
     group.anomalies = anomalies
   if status:
     group.status = status
   return group.put()
 def _AddAlertGroup(anomaly_key, issue=None, anomalies=None, status=None):
     anomaly_entity = anomaly_key.get()
     group = alert_group.AlertGroup(
         id=str(uuid.uuid4()),
         name=anomaly_entity.benchmark_name,
         project_id='chromium',
         status=alert_group.AlertGroup.Status.untriaged,
         active=True,
         revision=alert_group.RevisionRange(
             repository='chromium',
             start=anomaly_entity.start_revision,
             end=anomaly_entity.end_revision,
         ),
     )
     if issue:
         group.bug = alert_group.BugInfo(
             bug_id=issue.get('id'),
             project='chromium',
         )
     if anomalies:
         group.anomalies = anomalies
     if status:
         group.status = status
     return group.put()
Пример #3
0
    def testProcessTest(self, mock_email_sheriff):
        self._AddDataForTests()
        test_path = 'ChromiumGPU/linux-release/scrolling_benchmark/ref'
        test = utils.TestKey(test_path).get()
        test.UpdateSheriff()
        test.put()

        alert_group_key1 = alert_group.AlertGroup(
            name='scrolling_benchmark',
            subscription_name='sheriff1',
            status=alert_group.AlertGroup.Status.untriaged,
            active=True,
            revision=alert_group.RevisionRange(repository='chromium',
                                               start=10000,
                                               end=10070),
        ).put()
        alert_group_key2 = alert_group.AlertGroup(
            name='scrolling_benchmark',
            subscription_name='sheriff2',
            status=alert_group.AlertGroup.Status.untriaged,
            active=True,
            revision=alert_group.RevisionRange(repository='chromium',
                                               start=10000,
                                               end=10070),
        ).put()

        s1 = Subscription(name='sheriff1', visibility=VISIBILITY.PUBLIC)
        s2 = Subscription(name='sheriff2', visibility=VISIBILITY.PUBLIC)
        with mock.patch.object(SheriffConfigClient, 'Match',
                               mock.MagicMock(return_value=([s1, s2],
                                                            None))) as m:
            find_anomalies.ProcessTests([test.key])
            self.assertEqual(m.call_args_list, [mock.call(test.key.id())])
        self.ExecuteDeferredTasks('default')

        expected_calls = [
            mock.call([ModelMatcher('sheriff1'),
                       ModelMatcher('sheriff2')],
                      ModelMatcher(
                          'ChromiumGPU/linux-release/scrolling_benchmark/ref'),
                      EndRevisionMatcher(10011)),
            mock.call([ModelMatcher('sheriff1'),
                       ModelMatcher('sheriff2')],
                      ModelMatcher(
                          'ChromiumGPU/linux-release/scrolling_benchmark/ref'),
                      EndRevisionMatcher(10041)),
            mock.call([ModelMatcher('sheriff1'),
                       ModelMatcher('sheriff2')],
                      ModelMatcher(
                          'ChromiumGPU/linux-release/scrolling_benchmark/ref'),
                      EndRevisionMatcher(10061))
        ]
        self.assertEqual(expected_calls, mock_email_sheriff.call_args_list)

        anomalies = anomaly.Anomaly.query().fetch()
        self.assertEqual(len(anomalies), 3)
        for a in anomalies:
            self.assertEqual(a.groups, [alert_group_key1, alert_group_key2])

        def AnomalyExists(anomalies, test, percent_changed, direction,
                          start_revision, end_revision, subscription_names,
                          internal_only, units, absolute_delta, statistic):
            for a in anomalies:
                if (a.test == test and a.percent_changed == percent_changed
                        and a.direction == direction
                        and a.start_revision == start_revision
                        and a.end_revision == end_revision
                        and a.subscription_names == subscription_names
                        and a.internal_only == internal_only
                        and a.units == units
                        and a.absolute_delta == absolute_delta
                        and a.statistic == statistic):
                    return True
            return False

        self.assertTrue(
            AnomalyExists(anomalies,
                          test.key,
                          percent_changed=100,
                          direction=anomaly.UP,
                          start_revision=10007,
                          end_revision=10011,
                          subscription_names=['sheriff1', 'sheriff2'],
                          internal_only=False,
                          units='ms',
                          absolute_delta=50,
                          statistic='avg'))

        self.assertTrue(
            AnomalyExists(anomalies,
                          test.key,
                          percent_changed=-50,
                          direction=anomaly.DOWN,
                          start_revision=10037,
                          end_revision=10041,
                          subscription_names=['sheriff1', 'sheriff2'],
                          internal_only=False,
                          units='ms',
                          absolute_delta=-100,
                          statistic='avg'))

        self.assertTrue(
            AnomalyExists(anomalies,
                          test.key,
                          percent_changed=sys.float_info.max,
                          direction=anomaly.UP,
                          start_revision=10057,
                          end_revision=10061,
                          internal_only=False,
                          units='ms',
                          subscription_names=['sheriff1', 'sheriff2'],
                          absolute_delta=100,
                          statistic='avg'))

        # This is here just to verify that AnomalyExists returns False sometimes.
        self.assertFalse(
            AnomalyExists(anomalies,
                          test.key,
                          percent_changed=100,
                          direction=anomaly.DOWN,
                          start_revision=10037,
                          end_revision=10041,
                          subscription_names=['sheriff1', 'sheriff2'],
                          internal_only=False,
                          units='ms',
                          absolute_delta=500,
                          statistic='avg'))