def test(self): closed_incident = create_incident( self.organization, IncidentType.CREATED, "Closed", "", groups=[self.group], date_started=timezone.now() - timedelta(days=30), ) update_incident_status(closed_incident, IncidentStatus.CLOSED) open_incident = create_incident( self.organization, IncidentType.CREATED, "Open", "", groups=[self.group], date_started=timezone.now() - timedelta(days=30), ) incidents = [closed_incident, open_incident] for incident, incident_stats in zip(incidents, bulk_get_incident_stats(incidents)): event_stats = get_incident_event_stats(incident) assert incident_stats["event_stats"].data["data"] == event_stats.data["data"] assert incident_stats["event_stats"].start == event_stats.start assert incident_stats["event_stats"].end == event_stats.end assert incident_stats["event_stats"].rollup == event_stats.rollup aggregates = get_incident_aggregates(incident) assert incident_stats["total_events"] == aggregates["count"] assert incident_stats["unique_users"] == aggregates["unique_users"]
def run_test(self, incident, expected_results, start=None, end=None, windowed_stats=False): kwargs = {} if start is not None: kwargs["start"] = start if end is not None: kwargs["end"] = end result = get_incident_event_stats(incident, windowed_stats=windowed_stats, **kwargs) self.validate_result(incident, result, expected_results, start, end, windowed_stats)
def run_test(self, incident, expected_results, start=None, end=None): kwargs = {} if start is not None: kwargs['start'] = start if end is not None: kwargs['end'] = end result = get_incident_event_stats(incident, data_points=20, **kwargs) # Duration of 300s / 20 data points assert result.rollup == 15 assert result.start == start if start else incident.date_started assert result.end == end if end else incident.current_end_date assert [r['count'] for r in result.data['data']] == expected_results
def get_attrs(self, item_list, user, **kwargs): incident_projects = defaultdict(list) for incident_project in IncidentProject.objects.filter( incident__in=item_list).select_related('project'): incident_projects[incident_project.incident_id].append(incident_project.project.slug) results = {} for item in item_list: results[item] = {'projects': incident_projects.get(item.id, [])} for incident in item_list: results[item]['event_stats'] = get_incident_event_stats(incident) results[item]['aggregates'] = get_incident_aggregates(incident) return results
def get_attrs(self, item_list, user, **kwargs): incident_projects = defaultdict(list) for incident_project in IncidentProject.objects.filter( incident__in=item_list).select_related('project'): incident_projects[incident_project.incident_id].append(incident_project.project.slug) results = {} for incident in item_list: results[incident] = { 'projects': incident_projects.get(incident.id, []), 'event_stats': get_incident_event_stats(incident), 'aggregates': get_incident_aggregates(incident), } return results
def run_test(self, incident, expected_results, start=None, end=None): kwargs = {} if start is not None: kwargs["start"] = start if end is not None: kwargs["end"] = end result = get_incident_event_stats(incident, data_points=20, **kwargs) # Duration of 300s / 20 data points assert result.rollup == 15 expected_start = start if start else incident.date_started expected_end = end if end else incident.current_end_date expected_start = expected_start - (expected_end - expected_start) / 5 assert result.start == expected_start assert result.end == expected_end assert [r["count"] for r in result.data["data"]] == expected_results
def test_project(self): self.create_event(self.now - timedelta(minutes=2)) self.create_event(self.now - timedelta(minutes=2)) self.create_event(self.now - timedelta(minutes=1)) incident = self.create_incident(date_started=self.now - timedelta(minutes=5), query='', projects=[self.project]) result = get_incident_event_stats(incident) # Duration of 300s / 20 data points assert result.rollup == 15 assert result.start == incident.date_started assert result.end == incident.current_end_date assert len(result.data['data']) == 2 assert result.data['data'][0]['count'] == 2 assert result.data['data'][1]['count'] == 1
def test_project(self): self.create_event(self.now - timedelta(minutes=2)) self.create_event(self.now - timedelta(minutes=2)) self.create_event(self.now - timedelta(minutes=1)) incident = self.create_incident( date_started=self.now - timedelta(minutes=5), query='', projects=[self.project] ) result = get_incident_event_stats(incident) # Duration of 300s / 20 data points assert result.rollup == 15 assert result.start == incident.date_started assert result.end == incident.current_end_date assert len(result.data['data']) == 2 assert result.data['data'][0]['count'] == 2 assert result.data['data'][1]['count'] == 1
def test_groups(self): fingerprint = 'group-1' event = self.create_event(self.now - timedelta(minutes=2), fingerprint=fingerprint) self.create_event(self.now - timedelta(minutes=2), fingerprint='other-group') self.create_event(self.now - timedelta(minutes=1), fingerprint=fingerprint) incident = self.create_incident( date_started=self.now - timedelta(minutes=5), query='', projects=[], groups=[event.group], ) result = get_incident_event_stats(incident) # Duration of 300s / 20 data points assert result.rollup == 15 assert result.start == incident.date_started assert result.end == incident.current_end_date assert len(result.data['data']) == 2, result.data assert result.data['data'][0]['count'] == 1 assert result.data['data'][1]['count'] == 1
def test(self): closed_incident = create_incident( self.organization, IncidentType.ALERT_TRIGGERED, "Closed", "", QueryAggregations.TOTAL, groups=[self.group], date_started=timezone.now() - timedelta(days=30), ) update_incident_status(closed_incident, IncidentStatus.CLOSED) open_incident = create_incident( self.organization, IncidentType.ALERT_TRIGGERED, "Open", "", QueryAggregations.TOTAL, groups=[self.group], date_started=timezone.now() - timedelta(days=30), ) incidents = [closed_incident, open_incident] changed = False for incident, incident_stats in zip( incidents, bulk_get_incident_stats(incidents)): event_stats = get_incident_event_stats(incident) assert incident_stats["event_stats"].data[ "data"] == event_stats.data["data"] expected_start = incident_stats["event_stats"].start expected_end = incident_stats["event_stats"].end if not changed: expected_start = expected_start - calculate_incident_prewindow( expected_start, expected_end, incident) changed = True assert event_stats.start == expected_start assert event_stats.end == expected_end assert incident_stats["event_stats"].rollup == event_stats.rollup aggregates = get_incident_aggregates(incident) assert incident_stats["total_events"] == aggregates["count"] assert incident_stats["unique_users"] == aggregates["unique_users"]
def test_groups(self): fingerprint = 'group-1' event = self.create_event(self.now - timedelta(minutes=2), fingerprint=fingerprint) self.create_event(self.now - timedelta(minutes=2), fingerprint='other-group') self.create_event(self.now - timedelta(minutes=1), fingerprint=fingerprint) incident = self.create_incident( date_started=self.now - timedelta(minutes=5), query='', projects=[], groups=[event.group], ) result = get_incident_event_stats(incident) # Duration of 300s / 20 data points assert result.rollup == 15 assert result.start == incident.date_started assert result.end == incident.current_end_date assert len(result.data['data']) == 2, result.data assert result.data['data'][0]['count'] == 1 assert result.data['data'][1]['count'] == 1