예제 #1
0
def sherlock_factory(days_to_lookup: timedelta) -> Sherlock:
    report_maintainer = __report_maintainer_factory(days_to_lookup)
    backfill_tool = backfill_tool_factory()
    secretary = Secretary()
    notify_client = notify_client_factory()

    return Sherlock(report_maintainer, backfill_tool, secretary, notify_client)
예제 #2
0
    def _remove_leftovers(self):
        # remove any signatures which are
        # no longer associated with a job
        signatures = PerformanceSignature.objects.filter(
            last_updated__lte=self.max_timestamp)
        notify_client = taskcluster.notify_client_factory()
        signatures_remover = PublicSignatureRemover(
            timer=self.timer, notify_client=notify_client)
        signatures_remover.remove_in_chunks(signatures)

        # remove empty alert summaries
        logger.warning(
            'Removing alert summaries which no longer have any alerts...')
        (PerformanceAlertSummary.objects.prefetch_related(
            'alerts', 'related_alerts'
        ).annotate(
            total_alerts=Count('alerts'),
            total_related_alerts=Count('related_alerts'),
        ).filter(
            total_alerts=0,
            total_related_alerts=0,
            # WARNING! Don't change this without proper approval!           #
            # Otherwise we risk deleting data that's actively investigated  #
            # and cripple the perf sheriffing process!                      #
            created__lt=(datetime.now() - timedelta(days=180)),
            #################################################################
        ).delete())
예제 #3
0
def perf_sheriff_bot_factory(days_to_lookup: timedelta) -> PerfSheriffBot:
    report_maintainer = __report_maintainer_factory(days_to_lookup)
    backfill_tool = __backfill_tool_factory()
    secretary_tool = SecretaryTool()
    notify_client = notify_client_factory()

    return PerfSheriffBot(report_maintainer, backfill_tool, secretary_tool, notify_client)
예제 #4
0
    def __remove_empty_signatures(self):
        logger.warning(
            "Removing performance signatures which don't have any data points..."
        )
        potentially_empty_signatures = PerformanceSignature.objects.filter(
            last_updated__lte=self.max_timestamp)
        notify_client = taskcluster.notify_client_factory()

        signatures_remover = PublicSignatureRemover(
            timer=self.timer, notify_client=notify_client)
        signatures_remover.remove_in_chunks(potentially_empty_signatures)
예제 #5
0
 def handle(self, *args, **options):
     logger.info("Sherlock Notify Service: Notifying backfill outcome...")
     if BackfillNotificationRecord.objects.count() == 0:
         logger.info(
             "Sherlock Notify Service: Nothing to report via email.")
         return
     notify = notify_client_factory()
     email_writer = BackfillNotificationWriter()
     sent_confirmation = True
     while BackfillNotificationRecord.objects.count(
     ) != 0 & sent_confirmation:
         backfills_to_email = BackfillNotificationRecord.objects.all(
         )[:MAX_COUNT_OF_ROWS_PER_EMAIL]
         backfilled_records = [
             backfill.record for backfill in backfills_to_email
         ]
         if backfilled_records:
             backfill_notification = email_writer.prepare_new_email(
                 backfilled_records)
             logger.debug(
                 f"Sherlock Notify Service: Composed email notification payload `{backfill_notification}`."
             )
             # send email
             notification_outcome = notify.email(backfill_notification)
             logger.debug(
                 f"Sherlock Notify Service: Email notification service replied with `{notification_outcome}`."
             )
             if notification_outcome[
                     'response'].status_code == SUCCESS_STATUS:
                 logger.debug(
                     "Sherlock Notify Service: Removing notified records from helper table."
                 )
                 for record in backfills_to_email:
                     record.delete()
             else:
                 sent_confirmation = False
                 logger.debug(
                     "Sherlock Notify Service: Email notification service failed."
                 )
예제 #6
0
def notify_client_mock() -> taskcluster.Notify:
    return MagicMock(spec=notify_client_factory(
        'https://fakerooturl.org', 'FAKE_CLIENT_ID', 'FAKE_ACCESS_TOKEN'))
 def test_returns_null_object_on_non_production(self):
     notify = notify_client_factory()
     assert isinstance(notify, NotifyNullObject)
 def test_returns_real_client_on_production(self, mock_tc_prod_credentials):
     notify = notify_client_factory()
     assert isinstance(notify, NotifyAdapter)