def verify_fails_on_nonexistent_db(self, crash_tuple, app_load_tuple): app_id, error_type, crash_hash, version, date, num_crashes = crash_tuple with self.assertRaises(OperationalError) as e: CRErrorHistoryDAO.num_previously_known(app_id, error_type, crash_hash, version, date) self.assertEqual(e.exception.args[0], 'no such table: error_history') with self.assertRaises(OperationalError) as e: CRErrorHistoryDAO.set_known_occurrences(app_id, error_type, crash_hash, version, date, num_crashes) self.assertEqual(e.exception.args[0], 'no such table: error_history') start_date, end_date, num_app_loads = app_load_tuple with self.assertRaises(OperationalError) as e: CRAppLoadHistoryDAO.num_previously_known(app_id, start_date, end_date) self.assertEqual(e.exception.args[0], 'no such table: app_load_history') with self.assertRaises(OperationalError) as e: CRAppLoadHistoryDAO.set_known_occurrences(app_id, start_date, end_date, num_app_loads) self.assertEqual(e.exception.args[0], 'no such table: app_load_history')
def save_state(self): num_uploaded = len(self.unpacked_events()) if num_uploaded: for update_tuple in self._to_save: event_type, cr_hash, version, todays_date, version_occurrences = update_tuple CRErrorHistoryDAO.set_known_occurrences(self._app_id, event_type, cr_hash, version, todays_date, version_occurrences)
def save_state(self): num_uploaded = len(self.unpacked_events()) if num_uploaded: for update_tuple in self._to_save: event_type, cr_hash, version, todays_date, version_occurrences = update_tuple CRErrorHistoryDAO.set_known_occurrences( self._app_id, event_type, cr_hash, version, todays_date, version_occurrences)
def test_all_daos(self): crash_data = ('bogusAppId', 'bogusErrorType', 'bogusCrashHash', 'bogusVersion', '2099-09-09', 8008) app_id, error_type, crash_hash, version, date, num_crashes = crash_data app_load_data = ('2099-09-09', '2107-01-05', 8008) start_date, end_date, num_app_loads = app_load_data self.verify_fails_on_nonexistent_db(crash_data, app_load_data) create_tables() self.assertEqual(0, CRErrorHistoryDAO.num_previously_known(app_id, error_type, crash_hash, version, date)) CRErrorHistoryDAO.set_known_occurrences(app_id, error_type, crash_hash, version, date, num_crashes) self.assertEqual(num_crashes, CRErrorHistoryDAO.num_previously_known(app_id, error_type, crash_hash, version, date)) self.assertEqual(0, CRErrorHistoryDAO.num_previously_known(app_id, error_type, crash_hash, 'bad', date)) self.assertEqual(0, CRErrorHistoryDAO.num_previously_known(app_id, error_type, crash_hash, version, 'bad')) self.assertEqual(0, CRErrorHistoryDAO.num_previously_known(app_id, error_type, 'bad', version, date)) self.assertEqual(0, CRErrorHistoryDAO.num_previously_known(app_id, 'bad', crash_hash, version, date)) self.assertEqual(0, CRErrorHistoryDAO.num_previously_known('bad', error_type, crash_hash, version, date)) self.assertEqual(0, CRAppLoadHistoryDAO.num_previously_known(app_id, start_date, end_date)) CRAppLoadHistoryDAO.set_known_occurrences(app_id, start_date, end_date, num_app_loads) self.assertEqual(num_app_loads, CRAppLoadHistoryDAO.num_previously_known(app_id, start_date, end_date)) self.assertEqual(0, CRAppLoadHistoryDAO.num_previously_known('bad', start_date, end_date)) self.assertEqual(0, CRAppLoadHistoryDAO.num_previously_known(app_id, 'bad', end_date)) self.assertEqual(0, CRAppLoadHistoryDAO.num_previously_known(app_id, start_date, 'bad'))
def __init__(self, app_id, lookback_minutes, new_relic_account, new_relic_app_id, event_type): super(ErrorsByVersionProcessor, self).__init__(app_id, lookback_minutes, new_relic_account, new_relic_app_id, event_type) self._to_save = [] errors_with_details = self.get_errors_with_details(lookback_minutes) events = [] cumulative_errors_found = 0 cumulative_previously_known = 0 for cr_error in errors_with_details: todays_date = cr_error.current_date().strftime('%Y-%m-%d') e = Event(new_relic_account, new_relic_app_id, event_type, datetime.now()) for k, v in cr_error.as_event_dict(app_id).items(): e.set(k, v) for version, version_occurrences in cr_error.current_date_occurrences( ).items(): previously_known = CRErrorHistoryDAO.num_previously_known( self._app_id, event_type, cr_error.crittercism_hash(), version, todays_date) delta = version_occurrences - previously_known cumulative_errors_found += version_occurrences cumulative_previously_known += previously_known logging.getLogger().debug( 'Building event for cr_error=%s version=%s previously_known=%s num_new=%s', cr_error.crittercism_hash(), version, previously_known, delta) version_event = copy.deepcopy(e) version_event.set(u'version', version) events += [version_event] * delta self._to_save.append( (event_type, cr_error.crittercism_hash(), version, todays_date, version_occurrences)) self._events = events logging.getLogger().info( 'AppId=%s Event=%s num_found=%s num_known=%s num_new=%s', app_id, event_type, cumulative_errors_found, cumulative_previously_known, len(events))
def __init__(self, app_id, lookback_minutes, new_relic_account, new_relic_app_id, event_type): super(ErrorsByVersionProcessor, self).__init__(app_id, lookback_minutes, new_relic_account, new_relic_app_id, event_type) self._to_save = [] errors_with_details = self.get_errors_with_details(lookback_minutes) events = [] cumulative_errors_found = 0 cumulative_previously_known = 0 for cr_error in errors_with_details: todays_date = cr_error.current_date().strftime('%Y-%m-%d') e = Event(new_relic_account, new_relic_app_id, event_type, datetime.now()) for k, v in cr_error.as_event_dict().items(): e.set(k, v) for version, version_occurrences in cr_error.current_date_occurrences().items(): previously_known = CRErrorHistoryDAO.num_previously_known(self._app_id, event_type, cr_error.crittercism_hash(), version, todays_date) delta = version_occurrences - previously_known cumulative_errors_found += version_occurrences cumulative_previously_known += previously_known logging.getLogger().debug('Building event for cr_error=%s version=%s previously_known=%s num_new=%s', cr_error.crittercism_hash(), version, previously_known, delta) version_event = copy.deepcopy(e) version_event.set(u'version', version) events += [version_event] * delta self._to_save.append((event_type, cr_error.crittercism_hash(), version, todays_date, version_occurrences)) self._events = events logging.getLogger().info('AppId=%s Event=%s num_found=%s num_known=%s num_new=%s', app_id, event_type, cumulative_errors_found, cumulative_previously_known, len(events))
def test_all_daos(self): crash_data = ('bogusAppId', 'bogusErrorType', 'bogusCrashHash', 'bogusVersion', '2099-09-09', 8008) app_id, error_type, crash_hash, version, date, num_crashes = crash_data app_load_data = ('2099-09-09', '2107-01-05', 8008) start_date, end_date, num_app_loads = app_load_data self.verify_fails_on_nonexistent_db(crash_data, app_load_data) create_tables() self.assertEqual( 0, CRErrorHistoryDAO.num_previously_known(app_id, error_type, crash_hash, version, date)) CRErrorHistoryDAO.set_known_occurrences(app_id, error_type, crash_hash, version, date, num_crashes) self.assertEqual( num_crashes, CRErrorHistoryDAO.num_previously_known(app_id, error_type, crash_hash, version, date)) self.assertEqual( 0, CRErrorHistoryDAO.num_previously_known(app_id, error_type, crash_hash, 'bad', date)) self.assertEqual( 0, CRErrorHistoryDAO.num_previously_known(app_id, error_type, crash_hash, version, 'bad')) self.assertEqual( 0, CRErrorHistoryDAO.num_previously_known(app_id, error_type, 'bad', version, date)) self.assertEqual( 0, CRErrorHistoryDAO.num_previously_known(app_id, 'bad', crash_hash, version, date)) self.assertEqual( 0, CRErrorHistoryDAO.num_previously_known('bad', error_type, crash_hash, version, date)) self.assertEqual( 0, CRAppLoadHistoryDAO.num_previously_known(app_id, start_date, end_date)) CRAppLoadHistoryDAO.set_known_occurrences(app_id, start_date, end_date, num_app_loads) self.assertEqual( num_app_loads, CRAppLoadHistoryDAO.num_previously_known(app_id, start_date, end_date)) self.assertEqual( 0, CRAppLoadHistoryDAO.num_previously_known('bad', start_date, end_date)) self.assertEqual( 0, CRAppLoadHistoryDAO.num_previously_known(app_id, 'bad', end_date)) self.assertEqual( 0, CRAppLoadHistoryDAO.num_previously_known(app_id, start_date, 'bad'))