Пример #1
0
 def test_notify_digest_single_record(self, send, notify):
     project = self.event.project
     rule = project.rule_set.all()[0]
     digest = build_digest(project, (event_to_record(self.event, (rule,)),))
     self.plugin.notify_digest(project, digest)
     assert send.call_count is 1
     assert notify.call_count is 1
Пример #2
0
def deliver_digest(key, schedule_timestamp=None):
    from sentry.app import digests

    plugin, project = split_key(key)
    with digests.digest(key) as records:
        digest = build_digest(project, records)

    if digest:
        plugin.notify_digest(project, digest)
Пример #3
0
    def test_get_event_from_groups_in_digest(self):
        project = self.create_project()
        rule = project.rule_set.all()[0]

        events = [
            self.store_event(
                data={
                    "fingerprint": ["group1"],
                    "timestamp": iso_format(before_now(minutes=2))
                },
                project_id=project.id,
            ),
            self.store_event(
                data={
                    "fingerprint": ["group1"],
                    "timestamp": iso_format(before_now(minutes=1))
                },
                project_id=project.id,
            ),
            self.store_event(
                data={
                    "fingerprint": ["group2"],
                    "timestamp": iso_format(before_now(minutes=1))
                },
                project_id=project.id,
            ),
            self.store_event(
                data={
                    "fingerprint": ["group3"],
                    "timestamp": iso_format(before_now(minutes=1))
                },
                project_id=project.id,
            ),
            self.store_event(
                data={
                    "fingerprint": ["group4"],
                    "timestamp": iso_format(before_now(minutes=1))
                },
                project_id=project.id,
            ),
            self.store_event(
                data={
                    "fingerprint": ["group5"],
                    "timestamp": iso_format(before_now(minutes=1))
                },
                project_id=project.id,
            ),
        ]

        digest = build_digest(
            project,
            sort_records(
                [event_to_record(event, (rule, )) for event in events]))

        events.pop(0)  # remove event with same group
        assert get_event_from_groups_in_digest(digest) == set(events)
Пример #4
0
    def test_direct_email(self):
        self.project_ownership.update(fallthrough=False)
        rule = self.project.rule_set.all()[0]
        records = [event_to_record(event, (rule,)) for event in self.team1_events]
        digest = build_digest(self.project, sort_records(records))

        expected_result = {self.user1.id: set(self.team1_events)}
        self.assert_get_personalized_digests(
            self.project, digest, [self.user1.id], expected_result, ActionTargetType.MEMBER
        )
Пример #5
0
 def test_notify_digest_single_record(self, send, notify):
     project = self.event.project
     rule = project.rule_set.all()[0]
     digest = build_digest(
         project,
         (event_to_record(self.event, (rule, )), ),
     )
     self.plugin.notify_digest(project, digest)
     assert send.call_count is 1
     assert notify.call_count is 1
Пример #6
0
    def test_direct_email(self):
        """When the action type is not Issue Owners, then the target actor gets a digest."""
        self.project_ownership.update(fallthrough=False)
        rule = self.project.rule_set.all()[0]
        records = [event_to_record(event, (rule,)) for event in self.team1_events]
        digest = build_digest(self.project, sort_records(records))[0]

        expected_result = {self.user1.actor_id: set(self.team1_events)}
        assert_get_personalized_digests(
            self.project, digest, expected_result, ActionTargetType.MEMBER, self.user1.id
        )
Пример #7
0
    def test_simple(self):
        rule = self.project.rule_set.all()[0]
        records = [event_to_record(event, (rule, ))
                   for event in self.team1_events + self.team2_events + self.user4_events]
        digest = build_digest(self.project, sort_records(records))

        expected_result = {
            self.user1.id: set(self.team1_events),
            self.user2.id: set(self.team2_events),
            self.user3.id: set(self.team1_events + self.team2_events),
            self.user4.id: set(self.user4_events),
        }
        self.assert_get_personalized_digests(self.project, digest, self.user_ids, expected_result)
Пример #8
0
 def test_notify_digest(self, send_async, notify):
     project = self.event.project
     rule = project.rule_set.all()[0]
     digest = build_digest(
         project,
         (
             event_to_record(self.create_event(group=self.create_group()), (rule,)),
             event_to_record(self.event, (rule,)),
         ),
     )
     self.plugin.notify_digest(project, digest)
     assert send_async.call_count is 1
     assert notify.call_count is 0
Пример #9
0
 def test_notify_digest(self, send_async, notify):
     project = self.event.project
     rule = project.rule_set.all()[0]
     digest = build_digest(
         project,
         (
             event_to_record(self.create_event(group=self.create_group()), (rule,)),
             event_to_record(self.event, (rule,)),
         ),
     )
     self.plugin.notify_digest(project, digest)
     assert send_async.call_count is 1
     assert notify.call_count is 0
Пример #10
0
def deliver_digest(key, schedule_timestamp=None):
    from sentry.app import digests

    plugin, project = split_key(key)
    minimum_delay = ProjectOption.objects.get_value(
        project,
        '{0}:digests:{1}'.format(plugin.get_conf_key(), 'minimum_delay'),
    )
    with digests.digest(key, minimum_delay=minimum_delay) as records:
        digest = build_digest(project, records)

    if digest:
        plugin.notify_digest(project, digest)
Пример #11
0
    def test_notify_digest_single_record(self, has, send, notify):
        has.side_effect = lambda label, *a, **k: {
            'projects:digests:deliver': True,
        }.get(label, False)

        project = self.event.project
        rule = project.rule_set.all()[0]
        digest = build_digest(
            project,
            (event_to_record(self.event, (rule, )), ),
        )
        self.plugin.notify_digest(project, digest)
        assert send.call_count is 1
        assert notify.call_count is 1
Пример #12
0
    def test_simple(self):
        rule = self.project.rule_set.all()[0]
        records = [
            event_to_record(event, (rule,))
            for event in self.team1_events + self.team2_events + self.user4_events
        ]
        digest = build_digest(self.project, sort_records(records))

        expected_result = {
            self.user1.id: set(self.team1_events),
            self.user2.id: set(self.team2_events),
            self.user3.id: set(self.team1_events + self.team2_events),
            self.user4.id: set(self.user4_events),
        }
        self.assert_get_personalized_digests(self.project, digest, self.user_ids, expected_result)
Пример #13
0
 def test_only_everyone(self):
     rule = self.project.rule_set.all()[0]
     events = self.create_events_from_filenames(
         self.project, ["hello.moz", "goodbye.moz", "hola.moz", "adios.moz"]
     )
     records = [event_to_record(event, (rule,)) for event in events]
     digest = build_digest(self.project, sort_records(records))[0]
     expected_result = {
         self.user1.actor_id: set(events),
         self.user2.actor_id: set(events),
         self.user3.actor_id: set(events),
         self.user4.actor_id: set(events),
         self.user5.actor_id: set(events),
     }
     assert_get_personalized_digests(self.project, digest, expected_result)
Пример #14
0
 def test_everyone_with_owners(self):
     rule = self.project.rule_set.all()[0]
     events = self.create_events(
         timezone.now(), self.project, [
             'hello.moz', 'goodbye.moz', 'hola.moz', 'adios.moz'])
     records = [event_to_record(event, (rule, )) for event in events + self.team1_events]
     digest = build_digest(self.project, sort_records(records))
     expected_result = {
         self.user1.id: set(events + self.team1_events),
         self.user2.id: set(events),
         self.user3.id: set(events + self.team1_events),
         self.user4.id: set(events),
         self.user5.id: set(events),
     }
     self.assert_get_personalized_digests(self.project, digest, self.user_ids, expected_result)
Пример #15
0
    def test_notify_digest_single_record(self, has, send, notify):
        has.side_effect = lambda label, *a, **k: {
            'projects:digests:deliver': True,
        }.get(label, False)

        project = self.event.project
        rule = project.rule_set.all()[0]
        digest = build_digest(
            project,
            (
                event_to_record(self.event, (rule,)),
            ),
        )
        self.plugin.notify_digest(project, digest)
        assert send.call_count is 1
        assert notify.call_count is 1
Пример #16
0
 def test_everyone_with_owners(self):
     rule = self.project.rule_set.all()[0]
     events = self.create_events_from_filenames(
         self.project, ["hello.moz", "goodbye.moz", "hola.moz", "adios.moz"]
     )
     records = [event_to_record(event, (rule,)) for event in events + self.team1_events]
     digest = build_digest(self.project, sort_records(records))[0]
     expected_result = {
         self.user1.actor_id: set(events + self.team1_events),
         self.user2.actor_id: set(events),
         self.user3.actor_id: set(events + self.team1_events),
         self.user4.actor_id: set(events),
         self.user5.actor_id: set(events),
     }
     with self.feature("organizations:notification-all-recipients"):
         assert_get_personalized_digests(self.project, digest, expected_result)
Пример #17
0
 def test_only_everyone(self):
     rule = self.project.rule_set.all()[0]
     events = self.create_events(
         timezone.now(), self.project,
         ["hello.moz", "goodbye.moz", "hola.moz", "adios.moz"])
     records = [event_to_record(event, (rule, )) for event in events]
     digest = build_digest(self.project, sort_records(records))
     expected_result = {
         self.user1.id: set(events),
         self.user2.id: set(events),
         self.user3.id: set(events),
         self.user4.id: set(events),
         self.user5.id: set(events),
     }
     self.assert_get_personalized_digests(self.project, digest,
                                          self.user_ids, expected_result)
Пример #18
0
    def test_notify_digest_subject_prefix(self):
        project = self.event.project
        rule = project.rule_set.all()[0]
        digest = build_digest(
            project,
            (
                event_to_record(self.create_event(group=self.create_group()), (rule,)),
                event_to_record(self.event, (rule,)),
            ),
        )
        self.plugin.notify_digest(project, digest)

        assert len(mail.outbox) == 1

        msg = mail.outbox[0]

        assert msg.subject.startswith('[Example prefix] [foo Bar]')
Пример #19
0
    def test_simple(self):
        rule = self.project.rule_set.all()[0]
        records = [
            event_to_record(event, (rule,))
            for event in self.team1_events + self.team2_events + self.user4_events
        ]
        digest = build_digest(self.project, sort_records(records))[0]

        expected_result = {
            self.user1.actor_id: set(self.team1_events),
            self.user2.actor_id: set(self.team2_events),
            self.user3.actor_id: set(self.team1_events + self.team2_events),
            self.user4.actor_id: set(self.user4_events),
        }

        with self.feature("organizations:notification-all-recipients"):
            assert_get_personalized_digests(self.project, digest, expected_result)
Пример #20
0
    def test_notify_digest_user_does_not_exist(self, notify):
        """Test that in the event a rule has been created with an action to send to a user who
        no longer exists, we don't blow up when getting users in get_send_to
        """
        project = self.project
        event = self.store_event(
            data={
                "timestamp": iso_format(before_now(minutes=1)),
                "fingerprint": ["group-1"]
            },
            project_id=project.id,
        )
        event2 = self.store_event(
            data={
                "timestamp": iso_format(before_now(minutes=1)),
                "fingerprint": ["group-2"]
            },
            project_id=project.id,
        )

        action_data = {
            "id": "sentry.mail.actions.NotifyEmailAction",
            "targetType": "Member",
            "targetIdentifier": str(444),
        }
        rule = Rule.objects.create(
            project=self.project,
            label="a rule",
            data={
                "match": "all",
                "actions": [action_data],
            },
        )

        digest = build_digest(
            project,
            (event_to_record(event,
                             (rule, )), event_to_record(event2, (rule, ))))

        with self.tasks():
            self.adapter.notify_digest(project, digest,
                                       ActionTargetType.MEMBER, 444)

        assert notify.call_count == 0
        assert len(mail.outbox) == 0
Пример #21
0
    def test_notify_digest_subject_prefix(self):
        project = self.event.project
        rule = project.rule_set.all()[0]
        digest = build_digest(
            project,
            (
                event_to_record(self.create_event(group=self.create_group()),
                                (rule, )),
                event_to_record(self.event, (rule, )),
            ),
        )
        self.plugin.notify_digest(project, digest)

        assert len(mail.outbox) == 1

        msg = mail.outbox[0]

        assert msg.subject.startswith('[Example prefix] [foo Bar]')
Пример #22
0
def deliver_digest(key, schedule_timestamp=None):
    from sentry.app import digests

    try:
        plugin, project = split_key(key)
    except Project.DoesNotExist as error:
        logger.info("Cannot deliver digest %r due to error: %s", key, error)
        digests.delete(key)
        return

    minimum_delay = ProjectOption.objects.get_value(
        project, "{0}:digests:{1}".format(plugin.get_conf_key(), "minimum_delay")
    )
    with digests.digest(key, minimum_delay=minimum_delay) as records:
        digest = build_digest(project, records)

    if digest:
        plugin.notify_digest(project, digest)
Пример #23
0
def deliver_digest(key, schedule_timestamp=None):
    from sentry.app import digests

    try:
        plugin, project = split_key(key)
    except Project.DoesNotExist as error:
        logger.info('Cannot deliver digest %r due to error: %s', key, error)
        digests.delete(key)
        return

    minimum_delay = ProjectOption.objects.get_value(
        project,
        get_option_key(plugin.get_conf_key(), 'minimum_delay')
    )
    with digests.digest(key, minimum_delay=minimum_delay) as records:
        digest = build_digest(project, records)

    if digest:
        plugin.notify_digest(project, digest)
Пример #24
0
    def test_notify_digest(self, notify):
        project = self.event.project
        rule = project.rule_set.all()[0]
        digest = build_digest(
            project,
            (
                event_to_record(self.create_event(group=self.create_group()), (rule, )),
                event_to_record(self.event, (rule, )),
            ),
        )

        with self.tasks():
            self.plugin.notify_digest(project, digest)

        assert notify.call_count is 0
        assert len(mail.outbox) == 1

        message = mail.outbox[0]
        assert 'List-ID' in message.message()
Пример #25
0
    def test_notify_digest(self, notify):
        project = self.event.project
        rule = project.rule_set.all()[0]
        digest = build_digest(
            project,
            (
                event_to_record(self.create_event(group=self.create_group()), (rule, )),
                event_to_record(self.event, (rule, )),
            ),
        )

        with self.tasks():
            self.plugin.notify_digest(project, digest)

        assert notify.call_count is 0
        assert len(mail.outbox) == 1

        message = mail.outbox[0]
        assert 'List-ID' in message.message()
Пример #26
0
 def test_team_without_members(self):
     team = self.create_team()
     project = self.create_project(teams=[team], fire_project_created=True)
     ProjectOwnership.objects.create(
         project_id=project.id,
         schema=dump_schema([Rule(Matcher("path", "*.cpp"), [Owner("team", team.slug)])]),
         fallthrough=True,
     )
     rule = project.rule_set.all()[0]
     records = [
         event_to_record(event, (rule,))
         for event in self.create_events_from_filenames(
             project, ["hello.py", "goodbye.py", "hola.py", "adios.py"]
         )
     ]
     digest = build_digest(project, sort_records(records))
     user_ids = [member.user_id for member in team.member_set]
     assert not user_ids
     for user_id, user_digest in get_personalized_digests(project.id, digest, user_ids):
         assert False  # no users in this team no digests should be processed
Пример #27
0
    def test_get_event_from_groups_in_digest(self):
        project = self.create_project()
        rule = project.rule_set.all()[0]
        same_group = self.create_group(project=project)

        events = [
            self.create_event(group=same_group),
            self.create_event(group=same_group),
            self.create_event(group=self.create_group(project=project)),
            self.create_event(group=self.create_group(project=project)),
            self.create_event(group=self.create_group(project=project)),
            self.create_event(group=self.create_group(project=project)),
        ]
        digest = build_digest(
            project,
            sort_records([event_to_record(event, (rule, )) for event in events]),
        )

        events.pop(0)  # remove event with same group
        assert get_event_from_groups_in_digest(digest) == set(events)
Пример #28
0
    def test_get_event_from_groups_in_digest(self):
        project = self.create_project()
        rule = project.rule_set.all()[0]
        same_group = self.create_group(project=project)

        events = [
            self.create_event(group=same_group),
            self.create_event(group=same_group),
            self.create_event(group=self.create_group(project=project)),
            self.create_event(group=self.create_group(project=project)),
            self.create_event(group=self.create_group(project=project)),
            self.create_event(group=self.create_group(project=project)),
        ]
        digest = build_digest(
            project,
            sort_records(
                [event_to_record(event, (rule, )) for event in events]))

        events.pop(0)  # remove event with same group
        assert get_event_from_groups_in_digest(digest) == set(events)
Пример #29
0
 def test_team_without_members(self):
     team = self.create_team()
     project = self.create_project(teams=[team], fire_project_created=True)
     ProjectOwnership.objects.create(
         project_id=project.id,
         schema=dump_schema([Rule(Matcher("path", "*.cpp"), [Owner("team", team.slug)])]),
         fallthrough=True,
     )
     rule = project.rule_set.all()[0]
     records = [
         event_to_record(event, (rule,))
         for event in self.create_events_from_filenames(
             project, ["hello.py", "goodbye.py", "hola.py", "adios.py"]
         )
     ]
     digest = build_digest(project, sort_records(records))[0]
     user_ids = [member.user_id for member in team.member_set]
     assert not user_ids
     participants_by_provider_by_event = get_participants_by_event(digest, project)
     assert not {
         actor for actors in participants_by_provider_by_event.values() for actor in actors
     }  # no users in this team no digests should be processed
Пример #30
0
 def test_team_without_members(self):
     team = self.create_team()
     project = self.create_project(teams=[team])
     ProjectOwnership.objects.create(
         project_id=project.id,
         schema=dump_schema([
             Rule(Matcher('path', '*.cpp'), [
                 Owner('team', team.slug),
             ]),
         ]),
         fallthrough=True,
     )
     rule = project.rule_set.all()[0]
     records = [
         event_to_record(event, (rule, )) for event in self.create_events(timezone.now(), project, [
             'hello.py', 'goodbye.py', 'hola.py', 'adios.py'])
     ]
     digest = build_digest(project, sort_records(records))
     user_ids = [member.user_id for member in team.member_set]
     assert not user_ids
     for user_id, user_digest in get_personalized_digests(project.id, digest, user_ids):
         assert False  # no users in this team no digests should be processed
Пример #31
0
def deliver_digest(key, schedule_timestamp=None):
    from sentry import digests

    try:
        plugin, project = split_key(key)
    except Project.DoesNotExist as error:
        logger.info("Cannot deliver digest %r due to error: %s", key, error)
        digests.delete(key)
        return

    minimum_delay = ProjectOption.objects.get_value(
        project, get_option_key(plugin.get_conf_key(), "minimum_delay"))

    with snuba.options_override({"consistent": True}):
        try:
            with digests.digest(key, minimum_delay=minimum_delay) as records:
                digest = build_digest(project, records)
        except InvalidState as error:
            logger.info("Skipped digest delivery: %s", error, exc_info=True)
            return

        if digest:
            plugin.notify_digest(project, digest)
Пример #32
0
 def test_team_without_members(self):
     team = self.create_team()
     project = self.create_project(teams=[team])
     ProjectOwnership.objects.create(
         project_id=project.id,
         schema=dump_schema([
             Rule(Matcher('path', '*.cpp'), [
                 Owner('team', team.slug),
             ]),
         ]),
         fallthrough=True,
     )
     rule = project.rule_set.all()[0]
     records = [
         event_to_record(event, (rule, ))
         for event in self.create_events(timezone.now(
         ), project, ['hello.py', 'goodbye.py', 'hola.py', 'adios.py'])
     ]
     digest = build_digest(project, sort_records(records))
     user_ids = [member.user_id for member in team.member_set]
     assert not user_ids
     for user_id, user_digest in get_personalized_digests(
             project.id, digest, user_ids):
         assert False  # no users in this team no digests should be processed
Пример #33
0
    def test_notify_digest(self, notify):
        project = self.project
        event = self.store_event(
            data={"timestamp": iso_format(before_now(minutes=1)), "fingerprint": ["group-1"]},
            project_id=project.id,
        )
        event2 = self.store_event(
            data={"timestamp": iso_format(before_now(minutes=1)), "fingerprint": ["group-2"]},
            project_id=project.id,
        )

        rule = project.rule_set.all()[0]
        digest = build_digest(
            project, (event_to_record(event, (rule,)), event_to_record(event2, (rule,)))
        )

        with self.tasks():
            self.adapter.notify_digest(project, digest, ActionTargetType.ISSUE_OWNERS)

        assert notify.call_count == 0
        assert len(mail.outbox) == 1

        message = mail.outbox[0]
        assert "List-ID" in message.message()
Пример #34
0
def deliver_digest(key, schedule_timestamp=None):
    from sentry.app import digests

    try:
        plugin, project = split_key(key)
    except Project.DoesNotExist as error:
        logger.info('Cannot deliver digest %r due to error: %s', key, error)
        digests.delete(key)
        return

    minimum_delay = ProjectOption.objects.get_value(
        project,
        get_option_key(plugin.get_conf_key(), 'minimum_delay')
    )

    try:
        with digests.digest(key, minimum_delay=minimum_delay) as records:
            digest = build_digest(project, records)
    except InvalidState as error:
        logger.info('Skipped digest delivery: %s', error, exc_info=True)
        return

    if digest:
        plugin.notify_digest(project, digest)
Пример #35
0
def digest(request):
    seed = request.GET.get('seed', str(time.time()))
    logger.debug('Using random seed value: %s')
    random = Random(seed)

    now = datetime.utcnow().replace(tzinfo=pytz.utc)

    # TODO: Refactor all of these into something more manageable.
    org = Organization(
        id=1,
        slug='example',
        name='Example Organization',
    )

    team = Team(
        id=1,
        slug='example',
        name='Example Team',
        organization=org,
    )

    project = Project(
        id=1,
        slug='example',
        name='Example Project',
        team=team,
        organization=org,
    )

    state = {
        'project': project,
        'groups': {},
        'rules': {
            1: Rule(id=1, project=project, label="First Rule"),
            2: Rule(id=2, project=project, label="Second Rule"),
            3: Rule(id=3, project=project, label="Third Rule"),
        },
        'event_counts': {},
        'user_counts': {},
    }

    records = []

    group_sequence = itertools.count(1)
    event_sequence = itertools.count(1)

    for i in xrange(random.randint(1, 4)):
        group_id = next(group_sequence)

        group = state['groups'][group_id] = Group(
            id=group_id,
            project=project,
            message='This is example event #%s' % (group_id,),
        )

        offset = timedelta(seconds=0)
        for i in xrange(random.randint(1, 10)):
            offset += timedelta(seconds=random.random() * 120)
            event = Event(
                id=next(event_sequence),
                event_id=uuid.uuid4().hex,
                project=project,
                group=group,
                message=group.message,
                data=load_data('python'),
                datetime=now - offset,
            )

            records.append(
                Record(
                    event.event_id,
                    Notification(
                        event,
                        random.sample(state['rules'], random.randint(1, len(state['rules']))),
                    ),
                    to_timestamp(event.datetime),
                )
            )

            state['event_counts'][group_id] = random.randint(10, 1e4)
            state['user_counts'][group_id] = random.randint(10, 1e4)

    digest = build_digest(project, records, state)

    return MailPreview(
        html_template='sentry/emails/digests/body.html',
        text_template='sentry/emails/digests/body.txt',
        context={
            'project': project,
            'digest': digest,
        },
    ).render()
Пример #36
0
def digest(request):
    seed = request.GET.get("seed", str(time.time()))
    logger.debug("Using random seed value: %s")
    random = Random(seed)

    now = datetime.utcnow().replace(tzinfo=pytz.utc)

    # TODO: Refactor all of these into something more manageable.
    org = Organization(id=1, slug="example", name="Example Organization")

    team = Team(id=1, slug="example", name="Example Team", organization=org)

    project = Project(id=1, slug="example", name="Example Project", team=team, organization=org)

    rules = {i: Rule(id=i, project=project, label="Rule #%s" % (i,)) for i in xrange(1, random.randint(2, 4))}

    state = {"project": project, "groups": {}, "rules": rules, "event_counts": {}, "user_counts": {}}

    records = []

    group_sequence = itertools.count(1)
    event_sequence = itertools.count(1)

    for i in xrange(random.randint(1, 30)):
        group_id = next(group_sequence)

        culprit = "{module} in {function}".format(
            module=".".join(
                "".join(random.sample(WORDS, random.randint(1, int(random.paretovariate(2.2)))))
                for word in xrange(1, 4)
            ),
            function=random.choice(WORDS),
        )
        group = state["groups"][group_id] = Group(
            id=group_id,
            project=project,
            message=words(int(random.weibullvariate(8, 4)), common=False),
            culprit=culprit,
            level=random.choice(LOG_LEVELS.keys()),
        )

        offset = timedelta(seconds=0)
        for i in xrange(random.randint(1, 10)):
            offset += timedelta(seconds=random.random() * 120)
            event = Event(
                id=next(event_sequence),
                event_id=uuid.uuid4().hex,
                project=project,
                group=group,
                message=group.message,
                data=load_data("python"),
                datetime=now - offset,
            )

            records.append(
                Record(
                    event.event_id,
                    Notification(event, random.sample(state["rules"], random.randint(1, len(state["rules"])))),
                    to_timestamp(event.datetime),
                )
            )

            state["event_counts"][group_id] = random.randint(10, 1e4)
            state["user_counts"][group_id] = random.randint(10, 1e4)

    digest = build_digest(project, records, state)
    start, end, counts = get_digest_metadata(digest)

    return MailPreview(
        html_template="sentry/emails/digests/body.html",
        text_template="sentry/emails/digests/body.txt",
        context={"project": project, "counts": counts, "digest": digest, "start": start, "end": end},
    ).render()
Пример #37
0
def digest(request):
    random = get_random(request)

    # TODO: Refactor all of these into something more manageable.
    org = Organization(
        id=1,
        slug='example',
        name='Example Organization',
    )

    team = Team(
        id=1,
        slug='example',
        name='Example Team',
        organization=org,
    )

    project = Project(
        id=1,
        slug='example',
        name='Example Project',
        team=team,
        organization=org,
    )

    rules = {i: Rule(
        id=i,
        project=project,
        label="Rule #%s" % (i,),
    ) for i in range(1, random.randint(2, 4))}

    state = {
        'project': project,
        'groups': {},
        'rules': rules,
        'event_counts': {},
        'user_counts': {},
    }

    records = []

    event_sequence = itertools.count(1)
    group_generator = make_group_generator(random, project)

    for i in range(random.randint(1, 30)):
        group = next(group_generator)
        state['groups'][group.id] = group

        offset = timedelta(seconds=0)
        for i in range(random.randint(1, 10)):
            offset += timedelta(seconds=random.random() * 120)
            event = Event(
                id=next(event_sequence),
                event_id=uuid.uuid4().hex,
                project=project,
                group=group,
                message=group.message,
                data=load_data('python'),
                datetime=to_datetime(
                    random.randint(
                        to_timestamp(group.first_seen),
                        to_timestamp(group.last_seen),
                    ),
                )
            )

            records.append(
                Record(
                    event.event_id,
                    Notification(
                        event,
                        random.sample(state['rules'], random.randint(1, len(state['rules']))),
                    ),
                    to_timestamp(event.datetime),
                )
            )

            state['event_counts'][group.id] = random.randint(10, 1e4)
            state['user_counts'][group.id] = random.randint(10, 1e4)

    digest = build_digest(project, records, state)
    start, end, counts = get_digest_metadata(digest)

    return MailPreview(
        html_template='sentry/emails/digests/body.html',
        text_template='sentry/emails/digests/body.txt',
        context={
            'project': project,
            'counts': counts,
            'digest': digest,
            'start': start,
            'end': end,
        },
    ).render(request)
Пример #38
0
def digest(request):
    seed = request.GET.get('seed', str(time.time()))
    logger.debug('Using random seed value: %s')
    random = Random(seed)

    now = datetime.utcnow().replace(tzinfo=pytz.utc)

    # TODO: Refactor all of these into something more manageable.
    org = Organization(
        id=1,
        slug='example',
        name='Example Organization',
    )

    team = Team(
        id=1,
        slug='example',
        name='Example Team',
        organization=org,
    )

    project = Project(
        id=1,
        slug='example',
        name='Example Project',
        team=team,
        organization=org,
    )

    rules = {i: Rule(
        id=i,
        project=project,
        label="Rule #%s" % (i,),
    ) for i in xrange(1, random.randint(2, 4))}

    state = {
        'project': project,
        'groups': {},
        'rules': rules,
        'event_counts': {},
        'user_counts': {},
    }

    records = []

    group_sequence = itertools.count(1)
    event_sequence = itertools.count(1)

    for i in xrange(random.randint(1, 30)):
        group_id = next(group_sequence)

        group = state['groups'][group_id] = Group(
            id=group_id,
            project=project,
            message='This is example event #%s' % (group_id,),
            culprit='widget.foo in bar',
        )

        offset = timedelta(seconds=0)
        for i in xrange(random.randint(1, 10)):
            offset += timedelta(seconds=random.random() * 120)
            event = Event(
                id=next(event_sequence),
                event_id=uuid.uuid4().hex,
                project=project,
                group=group,
                message=group.message,
                data=load_data('python'),
                datetime=now - offset,
            )

            records.append(
                Record(
                    event.event_id,
                    Notification(
                        event,
                        random.sample(state['rules'], random.randint(1, len(state['rules']))),
                    ),
                    to_timestamp(event.datetime),
                )
            )

            state['event_counts'][group_id] = random.randint(10, 1e4)
            state['user_counts'][group_id] = random.randint(10, 1e4)

    digest = build_digest(project, records, state)

    # TODO(tkaemming): This duplication from ``MailPlugin.notify_digest`` is a code smell
    counts = Counter()
    for rule, groups in digest.iteritems():
        counts.update(groups.keys())

    return MailPreview(
        html_template='sentry/emails/digests/body.html',
        text_template='sentry/emails/digests/body.txt',
        context={
            'project': project,
            'counts': counts,
            'digest': digest,
        },
    ).render()
Пример #39
0
def digest(request):
    seed = request.GET.get('seed', str(time.time()))
    logger.debug('Using random seed value: %s')
    random = Random(seed)

    now = datetime.utcnow().replace(tzinfo=pytz.utc)

    # TODO: Refactor all of these into something more manageable.
    org = Organization(
        id=1,
        slug='example',
        name='Example Organization',
    )

    team = Team(
        id=1,
        slug='example',
        name='Example Team',
        organization=org,
    )

    project = Project(
        id=1,
        slug='example',
        name='Example Project',
        team=team,
        organization=org,
    )

    rules = {i: Rule(
        id=i,
        project=project,
        label="Rule #%s" % (i,),
    ) for i in xrange(1, random.randint(2, 4))}

    state = {
        'project': project,
        'groups': {},
        'rules': rules,
        'event_counts': {},
        'user_counts': {},
    }

    records = []

    group_sequence = itertools.count(1)
    event_sequence = itertools.count(1)

    for i in xrange(random.randint(1, 30)):
        group_id = next(group_sequence)

        culprit = '{module} in {function}'.format(
            module='.'.join(
                ''.join(random.sample(WORDS, random.randint(1, int(random.paretovariate(2.2))))) for word in xrange(1, 4)
            ),
            function=random.choice(WORDS)
        )
        group = state['groups'][group_id] = Group(
            id=group_id,
            project=project,
            message=words(int(random.weibullvariate(8, 4)), common=False),
            culprit=culprit,
            level=random.choice(LOG_LEVELS.keys()),
        )

        offset = timedelta(seconds=0)
        for i in xrange(random.randint(1, 10)):
            offset += timedelta(seconds=random.random() * 120)
            event = Event(
                id=next(event_sequence),
                event_id=uuid.uuid4().hex,
                project=project,
                group=group,
                message=group.message,
                data=load_data('python'),
                datetime=now - offset,
            )

            records.append(
                Record(
                    event.event_id,
                    Notification(
                        event,
                        random.sample(state['rules'], random.randint(1, len(state['rules']))),
                    ),
                    to_timestamp(event.datetime),
                )
            )

            state['event_counts'][group_id] = random.randint(10, 1e4)
            state['user_counts'][group_id] = random.randint(10, 1e4)

    digest = build_digest(project, records, state)
    start, end, counts = get_digest_metadata(digest)

    return MailPreview(
        html_template='sentry/emails/digests/body.html',
        text_template='sentry/emails/digests/body.txt',
        context={
            'project': project,
            'counts': counts,
            'digest': digest,
            'start': start,
            'end': end,
        },
    ).render()
Пример #40
0
def digest(request):
    random = get_random(request)

    # TODO: Refactor all of these into something more manageable.
    org = Organization(
        id=1,
        slug='example',
        name='Example Organization',
    )

    team = Team(
        id=1,
        slug='example',
        name='Example Team',
        organization=org,
    )

    project = Project(
        id=1,
        slug='example',
        name='Example Project',
        team=team,
        organization=org,
    )

    rules = {i: Rule(
        id=i,
        project=project,
        label="Rule #%s" % (i,),
    ) for i in range(1, random.randint(2, 4))}

    state = {
        'project': project,
        'groups': {},
        'rules': rules,
        'event_counts': {},
        'user_counts': {},
    }

    records = []

    event_sequence = itertools.count(1)
    group_generator = make_group_generator(random, project)

    for i in range(random.randint(1, 30)):
        group = next(group_generator)
        state['groups'][group.id] = group

        offset = timedelta(seconds=0)
        for i in range(random.randint(1, 10)):
            offset += timedelta(seconds=random.random() * 120)
            event = Event(
                id=next(event_sequence),
                event_id=uuid.uuid4().hex,
                project=project,
                group=group,
                message=group.message,
                data=load_data('python'),
                datetime=to_datetime(
                    random.randint(
                        to_timestamp(group.first_seen),
                        to_timestamp(group.last_seen),
                    ),
                )
            )

            records.append(
                Record(
                    event.event_id,
                    Notification(
                        event,
                        random.sample(state['rules'], random.randint(1, len(state['rules']))),
                    ),
                    to_timestamp(event.datetime),
                )
            )

            state['event_counts'][group.id] = random.randint(10, 1e4)
            state['user_counts'][group.id] = random.randint(10, 1e4)

    digest = build_digest(project, records, state)
    start, end, counts = get_digest_metadata(digest)

    context = {
        'project': project,
        'counts': counts,
        'digest': digest,
        'start': start,
        'end': end,
    }
    add_unsubscribe_link(context)

    return MailPreview(
        html_template='sentry/emails/digests/body.html',
        text_template='sentry/emails/digests/body.txt',
        context=context,
    ).render(request)
Пример #41
0
 def test_empty_records(self):
     assert build_digest(self.project, []) == (None, [])
Пример #42
0
def digest(request):
    random = get_random(request)

    # TODO: Refactor all of these into something more manageable.
    org = Organization(id=1, slug="example", name="Example Organization")

    project = Project(id=1, slug="example", name="Example Project", organization=org)

    rules = {
        i: Rule(id=i, project=project, label="Rule #%s" % (i,))
        for i in range(1, random.randint(2, 4))
    }

    state = {
        "project": project,
        "groups": {},
        "rules": rules,
        "event_counts": {},
        "user_counts": {},
    }

    records = []

    group_generator = make_group_generator(random, project)

    for i in range(random.randint(1, 30)):
        group = next(group_generator)
        state["groups"][group.id] = group

        offset = timedelta(seconds=0)
        for i in range(random.randint(1, 10)):
            offset += timedelta(seconds=random.random() * 120)

            data = dict(load_data("python"))
            data["message"] = group.message
            data.pop("logentry", None)

            event_manager = EventManager(data)
            event_manager.normalize()
            data = event_manager.get_data()

            data["timestamp"] = random.randint(
                to_timestamp(group.first_seen), to_timestamp(group.last_seen)
            )

            event = eventstore.create_event(
                event_id=uuid.uuid4().hex, group_id=group.id, project_id=project.id, data=data.data
            )

            records.append(
                Record(
                    event.event_id,
                    Notification(
                        event, random.sample(state["rules"], random.randint(1, len(state["rules"])))
                    ),
                    to_timestamp(event.datetime),
                )
            )

            state["event_counts"][group.id] = random.randint(10, 1e4)
            state["user_counts"][group.id] = random.randint(10, 1e4)

    digest = build_digest(project, records, state)
    start, end, counts = get_digest_metadata(digest)

    context = {
        "project": project,
        "counts": counts,
        "digest": digest,
        "start": start,
        "end": end,
        "referrer": "digest_email",
    }
    add_unsubscribe_link(context)

    return MailPreview(
        html_template="sentry/emails/digests/body.html",
        text_template="sentry/emails/digests/body.txt",
        context=context,
    ).render(request)
Пример #43
0
def digest(request):
    seed = request.GET.get('seed', str(time.time()))
    logger.debug('Using random seed value: %s')
    random = Random(seed)

    now = datetime.utcnow().replace(tzinfo=pytz.utc)

    # TODO: Refactor all of these into something more manageable.
    org = Organization(
        id=1,
        slug='example',
        name='Example Organization',
    )

    team = Team(
        id=1,
        slug='example',
        name='Example Team',
        organization=org,
    )

    project = Project(
        id=1,
        slug='example',
        name='Example Project',
        team=team,
        organization=org,
    )

    rules = {i: Rule(
        id=i,
        project=project,
        label="Rule #%s" % (i,),
    ) for i in xrange(1, random.randint(2, 4))}

    state = {
        'project': project,
        'groups': {},
        'rules': rules,
        'event_counts': {},
        'user_counts': {},
    }

    records = []

    group_sequence = itertools.count(1)
    event_sequence = itertools.count(1)

    for i in xrange(random.randint(1, 30)):
        group_id = next(group_sequence)

        group = state['groups'][group_id] = Group(
            id=group_id,
            project=project,
            message='This is example event #%s' % (group_id,),
            culprit='widget.foo in bar',
        )

        offset = timedelta(seconds=0)
        for i in xrange(random.randint(1, 10)):
            offset += timedelta(seconds=random.random() * 120)
            event = Event(
                id=next(event_sequence),
                event_id=uuid.uuid4().hex,
                project=project,
                group=group,
                message=group.message,
                data=load_data('python'),
                datetime=now - offset,
            )

            records.append(
                Record(
                    event.event_id,
                    Notification(
                        event,
                        random.sample(state['rules'], random.randint(1, len(state['rules']))),
                    ),
                    to_timestamp(event.datetime),
                )
            )

            state['event_counts'][group_id] = random.randint(10, 1e4)
            state['user_counts'][group_id] = random.randint(10, 1e4)

    digest = build_digest(project, records, state)

    # TODO(tkaemming): This duplication from ``MailPlugin.notify_digest`` is a code smell
    counts = Counter()
    for rule, groups in digest.iteritems():
        counts.update(groups.keys())

    return MailPreview(
        html_template='sentry/emails/digests/body.html',
        text_template='sentry/emails/digests/body.txt',
        context={
            'project': project,
            'counts': counts,
            'digest': digest,
        },
    ).render()