[Twisted-Python] Monitoring configuration of twisted calls.
I'm fairly new to twisted, although we are using it in production. What I'd like to do, is have a simple redlight/greenlight method (over XML-RPC) to tell me which methods have been called successfully at least once. The goal of this is not so much performance or uptime, but to just tell me that we are configured correctly. We're using twisted as a sort of service bus, so we have a decent amount of configuration that needs to be set up. What I've considered so far: 1. Modifying each xmlrpc method individually and setting a boolean to True in a dictionary: if results: self._monitor['xmlrpc.method.name'] = True This is okay, but I'd like something that is more generic so I don't have to write this code in every single XMLRPC method. 2. Extending/subclassing XMLRPC: def _getFunction(self, functionPath): ''' Overrides XMLRPC._getFunction to use our simple mapper. ''' ## attempt default behavior for local methods try: func = XMLRPC._getFunction(self, functionPath) return func except NoSuchFunction: pass This would work in my head, but in actuality, the call doesn't actually happen here, it just returns the function. 3. Extending/subclassing QueryProtocol: def handleStatus(self, version, status, message): if status != '200': self.factory.badStatus(status, message) I could override QueryProtocol and in the handleStatus method set a field in a dictionary. There are probably many ways to do this wrong, and I'm a Java guy just getting used to the twisted way of doing things. I apologize if my attempts are painful and/or hilarious. Thanks, Steve L.
On Thu, 28 Aug 2008 06:25:40 -0700 (PDT), Steve Lewis <spiritualmechanic@yahoo.com> wrote:
I'm fairly new to twisted, although we are using it in production. What I'd like to do, is have a simple redlight/greenlight method (over XML-RPC) to tell me which methods have been called successfully at least once. The goal of this is not so much performance or uptime, but to just tell me that we are configured correctly.
We're using twisted as a sort of service bus, so we have a decent amount of configuration that needs to be set up.
What I've considered so far:
[snip]
2. Extending/subclassing XMLRPC:
def _getFunction(self, functionPath): ''' Overrides XMLRPC._getFunction to use our simple mapper. '''
## attempt default behavior for local methods try: func = XMLRPC._getFunction(self, functionPath) return func except NoSuchFunction: pass
This would work in my head, but in actuality, the call doesn't actually happen here, it just returns the function.
This is probably the best approach. `_getFunction´ should probably be a public method. Its docstring directs users to override it, which is rather in conflict with it being private. To overcome the problem of the function not actually being called inside `_getFunction´, you just need to apply a wrapper to the function which is looked up. The wrapper can mark the call as successful. For example: def _getFunction(self, functionPath): f = XMLRPC._getFunction(self, functionPath) def wrapper(*a, **kw): result = f(*a, **kw) self._monitor[functionPath] = True return result return wrapper I'd also recommend filing a ticket to make `_getFunction´ public, so that you don't have to rely on a private hook to make this work. Jean-Paul
participants (2)
-
Jean-Paul Calderone
-
Steve Lewis