[CalendarServer-changes] [4946] CalendarServer/branches/users/wsanchez/deployment/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Wed Jan 20 13:00:04 PST 2010


Revision: 4946
          http://trac.macosforge.org/projects/calendarserver/changeset/4946
Author:   cdaboo at apple.com
Date:     2010-01-20 13:00:02 -0800 (Wed, 20 Jan 2010)
Log Message:
-----------
Tweak new inspector code to allow enable/disable feature and to work with processType Single.

Modified Paths:
--------------
    CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/accesslog.py
    CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/config.py
    CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/httpfactory.py
    CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/inspection.py
    CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/tap.py

Modified: CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/accesslog.py
===================================================================
--- CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/accesslog.py	2010-01-20 20:32:54 UTC (rev 4945)
+++ CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/accesslog.py	2010-01-20 21:00:02 UTC (rev 4946)
@@ -66,7 +66,7 @@
             loginfo = eventDict['loginfo']
 
             channel = request.chanRequest.channel
-            if channel._inspection:
+            if config.EnableInspection and channel._inspection:
                 channel._inspection.add("access_log")
     
             # Try to determine authentication and authorization identifiers

Modified: CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/config.py
===================================================================
--- CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/config.py	2010-01-20 20:32:54 UTC (rev 4945)
+++ CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/config.py	2010-01-20 21:00:02 UTC (rev 4946)
@@ -173,8 +173,9 @@
     "DefaultLogLevel"   : "",
     "LogLevels"         : {},
     "LogID"          : "",
+    "EnableInspection"   : False,
     "BaseInspectionPort" : 10000,
-    "InspectionPort" : "",
+    "InspectionPort"     : "",
 
     "AccountingCategories": {
         "iTIP": False,

Modified: CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/httpfactory.py
===================================================================
--- CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/httpfactory.py	2010-01-20 20:32:54 UTC (rev 4945)
+++ CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/httpfactory.py	2010-01-20 21:00:02 UTC (rev 4946)
@@ -23,6 +23,7 @@
 from twistedcaldav.inspection import Inspector
 
 from twistedcaldav.config import config
+from twisted.web2 import iweb
 
 __all__ = ['HTTP503LoggingFactory', ]
 
@@ -54,45 +55,22 @@
 
         self.transport.loseConnection()
 
-class HTTP503LoggingFactory(HTTPFactory):
-    """Factory for HTTP server."""
+class InspectableHTTPChannel(HTTPChannel):
 
-    def __init__(self, requestFactory, maxRequests=600, **kwargs):
-        HTTPFactory.__init__(self, requestFactory, maxRequests, **kwargs)
-        
-    def buildProtocol(self, addr):
-        if self.outstandingRequests >= self.maxRequests:
-            return OverloadedLoggingServerProtocol(self.outstandingRequests)
-        
-        p = protocol.ServerFactory.buildProtocol(self, addr)
-        
-        for arg,value in self.protocolArgs.iteritems():
-            setattr(p, arg, value)
-        return p
+    _inspection = None
 
-
-class LimitingHTTPChannel(HTTPChannel):
-
     def connectionMade(self):
         if self._inspection:
             self._inspection.add("conn_made")
 
-        retVal = HTTPChannel.connectionMade(self)
-        if self.factory.outstandingRequests >= self.factory.maxRequests:
-            # log.msg("Overloaded")
-            self.factory.myServer.myPort.stopReading()
-        return retVal
+        return super(InspectableHTTPChannel, self).connectionMade()
 
     def connectionLost(self, reason):
         if self._inspection:
             self._inspection.add("conn_lost")
             self._inspection.complete()
 
-        retVal = HTTPChannel.connectionLost(self, reason)
-        if self.factory.outstandingRequests < self.factory.resumeRequests:
-            # log.msg("Resuming")
-            self.factory.myServer.myPort.startReading()
-        return retVal
+        return super(InspectableHTTPChannel, self).connectionLost(reason)
 
     _firstChunkReceived = False
 
@@ -102,25 +80,67 @@
             if self._inspection:
                 self._inspection.add("first_byte")
 
-        return HTTPChannel.dataReceived(self, data)
+        return super(InspectableHTTPChannel, self).dataReceived(data)
 
     def requestReadFinished(self, request):
         if self._inspection:
             self._inspection.add("body_received")
 
-        return HTTPChannel.requestReadFinished(self, request)
+        return super(InspectableHTTPChannel, self).requestReadFinished(request)
 
     def requestWriteFinished(self, request):
         if self._inspection:
             self._inspection.add("resp_finish")
 
-        return HTTPChannel.requestWriteFinished(self, request)
+        return super(InspectableHTTPChannel, self).requestWriteFinished(request)
 
 
+class HTTP503LoggingFactory(HTTPFactory):
+    """Factory for HTTP server."""
+
+    protocol = InspectableHTTPChannel
+
+    def __init__(self, requestFactory, maxRequests=600, **kwargs):
+        HTTPFactory.__init__(self, requestFactory, maxRequests, **kwargs)
+        self.channelCounter = 0
+        
+    def buildProtocol(self, addr):
+        if self.outstandingRequests >= self.maxRequests:
+            return OverloadedLoggingServerProtocol(self.outstandingRequests)
+        
+        p = protocol.ServerFactory.buildProtocol(self, addr)
+        
+        for arg,value in self.protocolArgs.iteritems():
+            setattr(p, arg, value)
+
+        self.channelCounter += 1
+        if config.EnableInspection:
+            p._inspection = Inspector.getInspection(self.channelCounter)
+
+        return p
+
+
+class LimitingHTTPChannel(InspectableHTTPChannel):
+
+    def connectionMade(self):
+        retVal = super(LimitingHTTPChannel, self).connectionMade()
+        if self.factory.outstandingRequests >= self.factory.maxRequests:
+            # log.msg("Overloaded")
+            self.factory.myServer.myPort.stopReading()
+        return retVal
+
+    def connectionLost(self, reason):
+        retVal = super(LimitingHTTPChannel, self).connectionLost(reason)
+        if self.factory.outstandingRequests < self.factory.resumeRequests:
+            # log.msg("Resuming")
+            self.factory.myServer.myPort.startReading()
+        return retVal
+
+
 class LimitingHTTPFactory(HTTPFactory):
+
     protocol = LimitingHTTPChannel
 
-
     def __init__(self, requestFactory, maxRequests=600, maxAccepts=100, resumeRequests=550,
         **kwargs):
         HTTPFactory.__init__(self, requestFactory, maxRequests, **kwargs)
@@ -133,9 +153,11 @@
         p = protocol.ServerFactory.buildProtocol(self, addr)
         for arg, value in self.protocolArgs.iteritems():
             setattr(p, arg, value)
+
         self.channelCounter += 1
+        if config.EnableInspection:
+            p._inspection = Inspector.getInspection(self.channelCounter)
 
-        p._inspection = Inspector.getInspection(self.channelCounter)
         return p
 
 class LimitingRequest(Request):
@@ -144,13 +166,13 @@
         Request.__init__(self, *args, **kwargs)
         self.extendedLogItems = {}
         channel = self.chanRequest.channel
-        if channel._inspection:
+        if config.EnableInspection and channel._inspection:
             channel._inspection.add("headers_received")
             self.extendedLogItems['insp'] = channel._inspection.id
 
     def writeResponse(self, response):
         channel = self.chanRequest.channel
-        if channel._inspection:
+        if config.EnableInspection and channel._inspection:
             channel._inspection.add("resp_start")
 
         Request.writeResponse(self, response)

Modified: CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/inspection.py
===================================================================
--- CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/inspection.py	2010-01-20 20:32:54 UTC (rev 4945)
+++ CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/inspection.py	2010-01-20 21:00:02 UTC (rev 4946)
@@ -50,6 +50,7 @@
     @classmethod
     def isInspecting(klass):
         return klass._inspector is not None and len(klass._inspector.observers) > 0
+
     def __init__(self):
         self.observers = set()
 
@@ -62,7 +63,7 @@
         except KeyError:
             pass
 
-    def hasObservers():
+    def hasObservers(self):
         return len(self.observers) > 0
 
     def emit(self, msg):

Modified: CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/tap.py
===================================================================
--- CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/tap.py	2010-01-20 20:32:54 UTC (rev 4945)
+++ CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/tap.py	2010-01-20 21:00:02 UTC (rev 4946)
@@ -832,17 +832,19 @@
         # Register USR1 handler
         def sigusr1_handler(num, frame):
             from twisted.internet import reactor
-            log.debug("SIGUSR1 recieved, triggering directory refresh")
+            log.debug("SIGUSR1 received, triggering directory refresh")
             reactor.callLater(0, baseDirectory.refresh)
             return
 
         signal.signal(signal.SIGUSR1, sigusr1_handler)
 
-        internet.TCPServer(
-            int(config.InspectionPort),
-            InspectionFactory(),
-            interface="127.0.0.1"
-        ).setServiceParent(service)
+        if config.EnableInspection:
+            inspector = internet.TCPServer(
+                int(config.InspectionPort) if config.InspectionPort else config.BaseInspectionPort,
+                InspectionFactory(),
+                interface="127.0.0.1"
+            )
+            inspector.setServiceParent(service)
 
         return service
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100120/5fcc811a/attachment-0001.html>


More information about the calendarserver-changes mailing list