def test_get_group_backfill_attributes(self): now = datetime(2017, 5, 3, 6, 6, 6, tzinfo=pytz.utc) assert get_group_backfill_attributes( get_caches(), Group( active_at=now, first_seen=now, last_seen=now, platform='javascript', message='Hello from JavaScript', level=logging.INFO, score=ScoreClause.calculate(3, now), logger='javascript', times_seen=1, first_release=None, culprit='', data={ 'type': 'default', 'last_received': to_timestamp(now), 'metadata': {}, }, ), [ Event( platform='python', message='Hello from Python', datetime=now - timedelta(hours=1), data={ 'type': 'default', 'metadata': {}, 'tags': [ ['level', 'error'], ['logger', 'python'], ], }, ), Event( platform='java', message='Hello from Java', datetime=now - timedelta(hours=2), data={ 'type': 'default', 'metadata': {}, 'tags': [ ['level', 'debug'], ['logger', 'java'], ], }, ), ], ) == { 'active_at': now - timedelta(hours=2), 'first_seen': now - timedelta(hours=2), 'platform': 'java', 'score': ScoreClause.calculate(3, now), 'logger': 'java', 'times_seen': 3, 'first_release': None, }
def get_event_score(caches, data, event): from sentry.event_manager import ScoreClause return ScoreClause.calculate( data['times_seen'] + 1, data['last_seen'], )
def test_get_group_creation_attributes(self): now = datetime(2017, 5, 3, 6, 6, 6, tzinfo=pytz.utc) events = [ Event( platform='javascript', message='Hello from JavaScript', datetime=now, data={ 'type': 'default', 'metadata': {}, 'tags': [ ['level', 'info'], ['logger', 'javascript'], ], }, ), Event( platform='python', message='Hello from Python', datetime=now - timedelta(hours=1), data={ 'type': 'default', 'metadata': {}, 'tags': [ ['level', 'error'], ['logger', 'python'], ], }, ), Event( platform='java', message='Hello from Java', datetime=now - timedelta(hours=2), data={ 'type': 'default', 'metadata': {}, 'tags': [ ['level', 'debug'], ['logger', 'java'], ], }, ), ] assert get_group_creation_attributes( get_caches(), events, ) == { 'active_at': now - timedelta(hours=2), 'first_seen': now - timedelta(hours=2), 'last_seen': now, 'platform': 'java', 'message': 'Hello from JavaScript', 'level': logging.INFO, 'score': ScoreClause.calculate(3, now), 'logger': 'java', 'times_seen': 3, 'first_release': None, 'culprit': '', 'data': { 'type': 'default', 'last_received': to_timestamp(now), 'metadata': {}, }, }
'logger': lambda caches, data, event: event.get_tag('logger') or DEFAULT_LOGGER_NAME, 'first_seen': lambda caches, data, event: event.datetime, 'active_at': lambda caches, data, event: event.datetime, 'first_release': lambda caches, data, event: caches['Release']( caches['Project'](event.project_id).organization_id, event.get_tag('sentry:release'), ) if event.get_tag('sentry:release') else data.get('first_release', None), 'times_seen': lambda caches, data, event: data['times_seen'] + 1, 'score': lambda caches, data, event: ScoreClause.calculate( data['times_seen'] + 1, data['last_seen'], ), } def get_group_creation_attributes(caches, events): latest_event = events[0] return reduce( lambda data, event: merge_mappings([ data, { name: f(caches, data, event) for name, f in backfill_fields.items() }, ]), events,
def setUp(self): self.backend = self.create_backend() self.group1 = self.create_group( project=self.project, checksum='a' * 32, message='foo', times_seen=5, status=GroupStatus.UNRESOLVED, last_seen=datetime(2013, 8, 13, 3, 8, 24, 880386), first_seen=datetime(2013, 7, 13, 3, 8, 24, 880386), score=ScoreClause.calculate( times_seen=5, last_seen=datetime(2013, 8, 13, 3, 8, 24, 880386), ), ) self.event1 = self.create_event(event_id='a' * 32, group=self.group1, datetime=datetime( 2013, 7, 13, 3, 8, 24, 880386), tags={ 'server': 'example.com', 'environment': 'production', }) self.event3 = self.create_event(event_id='c' * 32, group=self.group1, datetime=datetime( 2013, 8, 13, 3, 8, 24, 880386), tags={ 'server': 'example.com', 'environment': 'production', }) self.group2 = self.create_group( project=self.project, checksum='b' * 32, message='bar', times_seen=10, status=GroupStatus.RESOLVED, last_seen=datetime(2013, 7, 14, 3, 8, 24, 880386), first_seen=datetime(2013, 7, 14, 3, 8, 24, 880386), score=ScoreClause.calculate( times_seen=10, last_seen=datetime(2013, 7, 14, 3, 8, 24, 880386), ), ) self.event2 = self.create_event(event_id='b' * 32, group=self.group2, datetime=datetime( 2013, 7, 14, 3, 8, 24, 880386), tags={ 'server': 'example.com', 'environment': 'staging', 'url': 'http://example.com', }) for key, value in self.event1.data['tags']: tagstore.create_group_tag_value( project_id=self.group1.project_id, group_id=self.group1.id, environment_id=None, key=key, value=value, ) for key, value in self.event2.data['tags']: tagstore.create_group_tag_value( project_id=self.group2.project_id, group_id=self.group2.id, environment_id=None, key=key, value=value, ) GroupBookmark.objects.create( user=self.user, group=self.group2, project=self.group2.project, ) GroupAssignee.objects.create( user=self.user, group=self.group2, project=self.group2.project, ) GroupSubscription.objects.create( user=self.user, group=self.group1, project=self.group1.project, is_active=True, ) GroupSubscription.objects.create( user=self.user, group=self.group2, project=self.group2.project, is_active=False, )
def setUp(self): super(SnubaSearchTest, self).setUp() self.backend = SnubaSearchBackend() self.environments = {} base_datetime = (datetime.utcnow() - timedelta(days=7)).replace(tzinfo=pytz.utc) self.group1 = self.create_group( project=self.project, checksum='a' * 32, message='foo', times_seen=5, status=GroupStatus.UNRESOLVED, last_seen=base_datetime, first_seen=base_datetime - timedelta(days=31), score=ScoreClause.calculate( times_seen=5, last_seen=base_datetime, ), ) self.event1 = self.create_event( event_id='a' * 32, group=self.group1, datetime=base_datetime - timedelta(days=31), message='group1', stacktrace={ 'frames': [{ 'module': 'group1' }]}, tags={ 'server': 'example.com', 'environment': 'production', } ) self.event3 = self.create_event( event_id='c' * 32, group=self.group1, datetime=base_datetime, message='group1', stacktrace={ 'frames': [{ 'module': 'group1' }]}, tags={ 'server': 'example.com', 'environment': 'production', } ) self.group2 = self.create_group( project=self.project, checksum='b' * 32, message='bar', times_seen=10, status=GroupStatus.RESOLVED, last_seen=base_datetime - timedelta(days=30), first_seen=base_datetime - timedelta(days=30), score=ScoreClause.calculate( times_seen=10, last_seen=base_datetime - timedelta(days=30), ), ) self.event2 = self.create_event( event_id='b' * 32, group=self.group2, datetime=base_datetime - timedelta(days=30), message='group2', stacktrace={ 'frames': [{ 'module': 'group2' }]}, tags={ 'server': 'example.com', 'environment': 'staging', 'url': 'http://example.com', } ) GroupBookmark.objects.create( user=self.user, group=self.group2, project=self.group2.project, ) GroupAssignee.objects.create( user=self.user, group=self.group2, project=self.group2.project, ) GroupSubscription.objects.create( user=self.user, group=self.group1, project=self.group1.project, is_active=True, ) GroupSubscription.objects.create( user=self.user, group=self.group2, project=self.group2.project, is_active=False, )
def setUp(self): self.backend = self.create_backend() self.group1 = self.create_group( project=self.project, checksum='a' * 32, message='foo', times_seen=5, status=GroupStatus.UNRESOLVED, last_seen=datetime(2013, 8, 13, 3, 8, 24, 880386, tzinfo=pytz.utc), first_seen=datetime(2013, 7, 13, 3, 8, 24, 880386, tzinfo=pytz.utc), score=ScoreClause.calculate( times_seen=5, last_seen=datetime(2013, 8, 13, 3, 8, 24, 880386, tzinfo=pytz.utc), ), ) self.event1 = self.create_event( event_id='a' * 32, group=self.group1, datetime=datetime(2013, 7, 13, 3, 8, 24, 880386, tzinfo=pytz.utc), tags={ 'server': 'example.com', 'environment': 'production', } ) self.event3 = self.create_event( event_id='c' * 32, group=self.group1, datetime=datetime(2013, 8, 13, 3, 8, 24, 880386, tzinfo=pytz.utc), tags={ 'server': 'example.com', 'environment': 'production', } ) self.group2 = self.create_group( project=self.project, checksum='b' * 32, message='bar', times_seen=10, status=GroupStatus.RESOLVED, last_seen=datetime(2013, 7, 14, 3, 8, 24, 880386, tzinfo=pytz.utc), first_seen=datetime(2013, 7, 14, 3, 8, 24, 880386, tzinfo=pytz.utc), score=ScoreClause.calculate( times_seen=10, last_seen=datetime(2013, 7, 14, 3, 8, 24, 880386, tzinfo=pytz.utc), ), ) self.event2 = self.create_event( event_id='b' * 32, group=self.group2, datetime=datetime(2013, 7, 14, 3, 8, 24, 880386, tzinfo=pytz.utc), tags={ 'server': 'example.com', 'environment': 'staging', 'url': 'http://example.com', } ) self.environments = {} for event in Event.objects.filter(project_id=self.project.id): self._setup_tags_for_event(event) GroupBookmark.objects.create( user=self.user, group=self.group2, project=self.group2.project, ) GroupAssignee.objects.create( user=self.user, group=self.group2, project=self.group2.project, ) GroupSubscription.objects.create( user=self.user, group=self.group1, project=self.group1.project, is_active=True, ) GroupSubscription.objects.create( user=self.user, group=self.group2, project=self.group2.project, is_active=False, )
def setUp(self): self.backend = self.create_backend() self.group1 = self.create_group( project=self.project, checksum='a' * 32, message='foo', times_seen=5, status=GroupStatus.UNRESOLVED, last_seen=datetime(2013, 8, 13, 3, 8, 24, 880386, tzinfo=pytz.utc), first_seen=datetime(2013, 7, 13, 3, 8, 24, 880386, tzinfo=pytz.utc), score=ScoreClause.calculate( times_seen=5, last_seen=datetime(2013, 8, 13, 3, 8, 24, 880386, tzinfo=pytz.utc), ), ) self.event1 = self.create_event(event_id='a' * 32, group=self.group1, datetime=datetime(2013, 7, 13, 3, 8, 24, 880386, tzinfo=pytz.utc), tags={ 'server': 'example.com', 'environment': 'production', }) self.event3 = self.create_event(event_id='c' * 32, group=self.group1, datetime=datetime(2013, 8, 13, 3, 8, 24, 880386, tzinfo=pytz.utc), tags={ 'server': 'example.com', 'environment': 'production', }) self.group2 = self.create_group( project=self.project, checksum='b' * 32, message='bar', times_seen=10, status=GroupStatus.RESOLVED, last_seen=datetime(2013, 7, 14, 3, 8, 24, 880386, tzinfo=pytz.utc), first_seen=datetime(2013, 7, 14, 3, 8, 24, 880386, tzinfo=pytz.utc), score=ScoreClause.calculate( times_seen=10, last_seen=datetime(2013, 7, 14, 3, 8, 24, 880386, tzinfo=pytz.utc), ), ) self.event2 = self.create_event(event_id='b' * 32, group=self.group2, datetime=datetime(2013, 7, 14, 3, 8, 24, 880386, tzinfo=pytz.utc), tags={ 'server': 'example.com', 'environment': 'staging', 'url': 'http://example.com', }) self.environments = {} for event in Event.objects.filter(project_id=self.project.id): self._setup_tags_for_event(event) GroupBookmark.objects.create( user=self.user, group=self.group2, project=self.group2.project, ) GroupAssignee.objects.create( user=self.user, group=self.group2, project=self.group2.project, ) GroupSubscription.objects.create( user=self.user, group=self.group1, project=self.group1.project, is_active=True, ) GroupSubscription.objects.create( user=self.user, group=self.group2, project=self.group2.project, is_active=False, )
'times_seen': lambda event: 0, } backfill_fields = { 'platform': lambda caches, data, event: event.platform, 'logger': lambda caches, data, event: event.get_tag('logger') or DEFAULT_LOGGER_NAME, 'first_seen': lambda caches, data, event: event.datetime, 'active_at': lambda caches, data, event: event.datetime, 'first_release': lambda caches, data, event: caches['Release']( caches['Project'](event.project_id).organization_id, event.get_tag('sentry:release'), ) if event.get_tag('sentry:release') else data.get('first_release', None), 'times_seen': lambda caches, data, event: data['times_seen'] + 1, 'score': lambda caches, data, event: ScoreClause.calculate( data['times_seen'] + 1, data['last_seen'], ), } def get_group_creation_attributes(caches, events): latest_event = events[0] return reduce( lambda data, event: merge_mappings([ data, {name: f(caches, data, event) for name, f in backfill_fields.items()}, ]), events, {name: f(latest_event) for name, f in initial_fields.items()}, )