← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~lifeless/launchpad/use-oops-twisted into lp:launchpad

 

Robert Collins has proposed merging lp:~lifeless/launchpad/use-oops-twisted into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~lifeless/launchpad/use-oops-twisted/+merge/78336

More code deletion in favour of extracted out oops micro projects. This time: our twisted integration.
-- 
https://code.launchpad.net/~lifeless/launchpad/use-oops-twisted/+merge/78336
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~lifeless/launchpad/use-oops-twisted into lp:launchpad.
=== modified file 'lib/lp/hardwaredb/tests/test_hwdb_submission_validation.py'
--- lib/lp/hardwaredb/tests/test_hwdb_submission_validation.py	2011-09-26 07:33:00 +0000
+++ lib/lp/hardwaredb/tests/test_hwdb_submission_validation.py	2011-10-05 23:10:31 +0000
@@ -145,10 +145,10 @@
             after=True)
         # Add the OopsHandler to the log, because we want to make sure this
         # doesn't create an Oops report.
+        last_oops_time = self._getLastOopsTime()
         logging.getLogger('test_hwdb_submission_parser').addHandler(
             OopsHandler(self.log.name))
         result, submission_id = self.runValidator(sample_data)
-        last_oops_time = self._getLastOopsTime()
         # We use the class method here, because it's been overrided for the
         # other tests in this test case.
         TestCase.assertEqual(self,

=== modified file 'lib/lp/services/sshserver/service.py'
--- lib/lp/services/sshserver/service.py	2011-01-31 06:33:01 +0000
+++ lib/lp/services/sshserver/service.py	2011-10-05 23:10:31 +0000
@@ -171,7 +171,7 @@
             logging.getLogger(self._access_log_path),
             self._access_log_path)
         manager.setUp()
-        set_up_oops_reporting(self._oops_configuration, self._main_log)
+        set_up_oops_reporting(self._main_log, self._oops_configuration)
         notify(events.ServerStarting())
         # By default, only the owner of files should be able to write to them.
         # Perhaps in the future this line will be deleted and the umask

=== modified file 'lib/lp/services/twistedsupport/loggingsupport.py'
--- lib/lp/services/twistedsupport/loggingsupport.py	2011-08-16 20:35:11 +0000
+++ lib/lp/services/twistedsupport/loggingsupport.py	2011-10-05 23:10:31 +0000
@@ -8,8 +8,6 @@
 __metaclass__ = type
 __all__ = [
     'LaunchpadLogFile',
-    'OOPSLoggingObserver',
-    'log_oops_from_failure',
     'set_up_logging_for_script',
     'set_up_oops_reporting',
     'set_up_tacfile_logging',
@@ -23,6 +21,7 @@
 import signal
 import sys
 
+from oops_twisted import OOPSObserver
 from twisted.python import (
     log,
     logfile,
@@ -36,35 +35,6 @@
 from canonical.librarian.utils import copy_and_close
 
 
-class OOPSLoggingObserver(log.PythonLoggingObserver):
-    """A version of `PythonLoggingObserver` that logs OOPSes for errors."""
-    # XXX: JonathanLange 2008-12-23 bug=314959: As best as I can tell, this
-    # ought to be a log *handler*, not a feature of the bridge from
-    # Twisted->Python logging. Ask Michael about this.
-
-    def emit(self, eventDict):
-        """See `PythonLoggingObserver.emit`."""
-        if eventDict.get('isError', False) and 'failure' in eventDict:
-            try:
-                failure = eventDict['failure']
-                request = log_oops_from_failure(failure)
-                self.logger.info(
-                    "Logged OOPS id %s: %s: %s",
-                    request.oopsid, failure.type.__name__, failure.value)
-            except:
-                self.logger.exception("Error reporting OOPS:")
-        else:
-            log.PythonLoggingObserver.emit(self, eventDict)
-
-
-def log_oops_from_failure(failure, URL=None, **args):
-    request = errorlog.ScriptRequest(args.items(), URL=URL)
-    errorlog.globalErrorUtility.raising(
-        (failure.type, failure.value, failure.getTraceback()),
-        request)
-    return request
-
-
 def set_up_logging_for_script(options, name):
     """Create a `Logger` object and configure twisted to use it.
 
@@ -80,7 +50,7 @@
 
     This is preferable to use over `set_up_logging_for_script` for .tac
     files since there's no options to pass through.  The logger object
-    is connected to Twisted's log and returned.
+    is connected to Twisted's log and returned. 
 
     :param name: The logger instance name.
     :param level: The log level to use, eg. logging.INFO or logging.DEBUG
@@ -94,18 +64,19 @@
     return logger
 
 
-def set_up_oops_reporting(configuration, name, mangle_stdout=True):
+def set_up_oops_reporting(name, configuration, mangle_stdout=True):
     """Set up OOPS reporting by starting the Twisted logger with an observer.
 
+    :param name: The name of the logger to use for oops reporting.
     :param configuration: The name of the config section to use for oops
         reporting.
-    :param name: The name of the logger to use for oops reporting.
     :param mangle_stdout: If True, send stdout and stderr to the logger.
         Defaults to False.
     """
     errorlog.globalErrorUtility.configure(configuration)
-    log.startLoggingWithObserver(
-        OOPSLoggingObserver(loggerName=name).emit, mangle_stdout)
+    oops_observer = OOPSObserver(errorlog.globalErrorUtility._oops_config)
+        config, log.PythonLoggingObserver(loggerName=name).emit)
+    log.startLoggingWithObserver(oops_observer.emit, mangle_stdout)
 
 
 class LaunchpadLogFile(DailyLogFile):

=== modified file 'lib/lp/services/twistedsupport/tests/test_loggingsupport.py'
--- lib/lp/services/twistedsupport/tests/test_loggingsupport.py	2011-08-14 23:11:45 +0000
+++ lib/lp/services/twistedsupport/tests/test_loggingsupport.py	2011-10-05 23:10:31 +0000
@@ -27,7 +27,6 @@
 from canonical.launchpad.webapp.errorlog import globalErrorUtility
 from lp.services.twistedsupport.loggingsupport import (
     LaunchpadLogFile,
-    OOPSLoggingObserver,
     )
 from lp.services.twistedsupport.tests.test_processmonitor import (
     makeFailure,
@@ -39,50 +38,6 @@
 UTC = pytz.utc
 
 
-class LoggingSupportTests(TestCase):
-
-    run_tests_with = AsynchronousDeferredRunTest
-
-    def setUp(self):
-        super(LoggingSupportTests, self).setUp()
-        self.temp_dir = tempfile.mkdtemp()
-        self.addCleanup(shutil.rmtree, self.temp_dir)
-        config.push('testing', dedent("""
-            [error_reports]
-            oops_prefix: O
-            error_dir: %s
-            """ % self.temp_dir))
-        globalErrorUtility.configure()
-        self.log_stream = StringIO.StringIO()
-        self.logger = logging.getLogger('test')
-        self.logger.setLevel(logging.DEBUG)
-        self.logger.addHandler(logging.StreamHandler(self.log_stream))
-        self.observer = OOPSLoggingObserver('test')
-
-    def tearDown(self):
-        config.pop('testing')
-        globalErrorUtility.configure()
-        super(LoggingSupportTests, self).tearDown()
-
-    def assertLogMatches(self, pattern):
-        """Assert that the messages logged by self.logger matches a regexp."""
-        log_text = self.log_stream.getvalue()
-        self.failUnless(re.match(pattern, log_text, re.M))
-
-    @suppress_stderr
-    def test_oops_reporting(self):
-        # Calling log.err should result in an OOPS being logged.
-        log.addObserver(self.observer.emit)
-        self.addCleanup(log.removeObserver, self.observer.emit)
-        error_time = datetime.datetime.now(UTC)
-        fail = makeFailure(RuntimeError)
-        log.err(fail, error_time=error_time)
-        flush_logged_errors(RuntimeError)
-        oops = self.oopses[-1]
-        self.assertEqual(oops['type'], 'RuntimeError')
-        self.assertLogMatches('^Logged OOPS id.*')
-
-
 class TestLaunchpadLogFile(TestCase):
 
     def setUp(self):

=== modified file 'scripts/code-import-worker-monitor.py'
--- scripts/code-import-worker-monitor.py	2011-08-27 03:35:53 +0000
+++ scripts/code-import-worker-monitor.py	2011-10-05 23:10:31 +0000
@@ -36,7 +36,7 @@
 
     def __init__(self, name, dbuser=None, test_args=None):
         LaunchpadScript.__init__(self, name, dbuser, test_args)
-        set_up_oops_reporting('codeimportworker', name, mangle_stdout=True)
+        set_up_oops_reporting(name, 'codeimportworker', mangle_stdout=True)
 
     def add_my_options(self):
         """See `LaunchpadScript`."""

=== modified file 'setup.py'
--- setup.py	2011-09-27 09:25:31 +0000
+++ setup.py	2011-10-05 23:10:31 +0000
@@ -59,6 +59,7 @@
         'oops',
         'oops_datedir_repo',
         'oops_timeline',
+        'oops_twisted',
         'oops_wsgi',
         'paramiko',
         'pgbouncer',