[Zodb-checkins] SVN: ZODB/trunk/src/ ZEO clients now support a client_label constructor argument and

Jim Fulton jim at zope.com
Tue May 4 15:26:56 EDT 2010


Log message for revision 111943:
  ZEO clients now support a client_label constructor argument and
    client-label configuration-file option to specify a label for a
    client in server logs. This makes it easier to identify specific
    clients corresponding to server log entries, especially when there
    are multiple clients originating from the same machine.
  

Changed:
  U   ZODB/trunk/src/CHANGES.txt
  U   ZODB/trunk/src/ZEO/ClientStorage.py
  U   ZODB/trunk/src/ZEO/ServerStub.py
  U   ZODB/trunk/src/ZEO/StorageServer.py
  U   ZODB/trunk/src/ZEO/tests/testZEO.py
  U   ZODB/trunk/src/ZODB/component.xml
  U   ZODB/trunk/src/ZODB/config.py

-=-
Modified: ZODB/trunk/src/CHANGES.txt
===================================================================
--- ZODB/trunk/src/CHANGES.txt	2010-05-04 19:17:23 UTC (rev 111942)
+++ ZODB/trunk/src/CHANGES.txt	2010-05-04 19:26:56 UTC (rev 111943)
@@ -21,6 +21,12 @@
   information the number of clients, lock requests and general
   statistics.
 
+- ZEO clients now support a client_label constructor argument and
+  client-label configuration-file option to specify a label for a
+  client in server logs. This makes it easier to identify specific
+  clients corresponding to server log entries, especially when there
+  are multiple clients originating from the same machine.
+
 - The mkzeoinst script has been moved to a separate project:
 
     http://pypi.python.org/pypi/zope.mkzeoinstance

Modified: ZODB/trunk/src/ZEO/ClientStorage.py
===================================================================
--- ZODB/trunk/src/ZEO/ClientStorage.py	2010-05-04 19:17:23 UTC (rev 111942)
+++ ZODB/trunk/src/ZEO/ClientStorage.py	2010-05-04 19:26:56 UTC (rev 111943)
@@ -123,6 +123,7 @@
                  username='', password='', realm=None,
                  blob_dir=None, shared_blob_dir=False,
                  blob_cache_size=None, blob_cache_size_check=10,
+                 client_label=None,
                  ):
         """ClientStorage constructor.
 
@@ -234,6 +235,9 @@
             loaded into the cache. Defaults to 10% of the blob cache
             size.   This option is ignored if shared_blob_dir is true.
 
+        client_label
+            A label to include in server log messages for the client.
+
         Note that the authentication protocol is defined by the server
         and is detected by the ClientStorage upon connecting (see
         testConnection() and doAuth() for details).
@@ -317,6 +321,8 @@
         # _server_addr is used by sortKey()
         self._server_addr = None
 
+        self._client_label = client_label
+
         self._pickler = self._tfile = None
 
         self._info = {'length': 0, 'size': 0, 'name': 'ZEO Client',
@@ -622,6 +628,10 @@
                         self.__name__, self._server_addr)
 
         stub = self.StorageServerStubClass(conn)
+
+        if self._client_label and conn.peer_protocol_version >= "Z310":
+            stub.set_client_label(self._client_label)
+
         self._oids = []
         self.verify_cache(stub)
 

Modified: ZODB/trunk/src/ZEO/ServerStub.py
===================================================================
--- ZODB/trunk/src/ZEO/ServerStub.py	2010-05-04 19:17:23 UTC (rev 111942)
+++ ZODB/trunk/src/ZEO/ServerStub.py	2010-05-04 19:26:56 UTC (rev 111943)
@@ -299,6 +299,9 @@
     def server_status(self):
         return self.rpc.call("server_status")
 
+    def set_client_label(self, label):
+        return self.rpc.callAsync('set_client_label', label)
+
 class StorageServer308(StorageServer):
 
     def __init__(self, rpc):

Modified: ZODB/trunk/src/ZEO/StorageServer.py
===================================================================
--- ZODB/trunk/src/ZEO/StorageServer.py	2010-05-04 19:17:23 UTC (rev 111942)
+++ ZODB/trunk/src/ZEO/StorageServer.py	2010-05-04 19:26:56 UTC (rev 111943)
@@ -759,6 +759,9 @@
     def server_status(self):
         return self.server.server_status(self)
 
+    def set_client_label(self, label):
+        self.log_label = str(label)+' '+_addr_label(self.connection.addr)
+
 class StorageServerDB:
 
     def __init__(self, server, storage_id):

Modified: ZODB/trunk/src/ZEO/tests/testZEO.py
===================================================================
--- ZODB/trunk/src/ZEO/tests/testZEO.py	2010-05-04 19:17:23 UTC (rev 111942)
+++ ZODB/trunk/src/ZEO/tests/testZEO.py	2010-05-04 19:26:56 UTC (rev 111943)
@@ -1295,7 +1295,43 @@
     >>> db.close()
     """
 
+def client_labels():
+    """
+When looking at server logs, for servers with lots of clients coming
+from the same machine, it can be very difficult to correlate server
+log entries with actual clients.  It's possible, sort of, but tedious.
 
+You can make this easier by passing a label to the ClientStorage
+constructor.
+
+    >>> addr, _ = start_server()
+    >>> db = ZEO.DB(addr, client_label='test-label-1')
+    >>> db.close()
+    >>> for line in open('server-%s.log' % addr[1]):
+    ...     if 'test-label-1' in line:
+    ...         print line.split()[1:4]
+    ['INFO', 'ZEO.StorageServer', '(test-label-1']
+
+You can specify the client label via a configuration file as well:
+
+    >>> import ZODB.config
+    >>> db = ZODB.config.databaseFromString('''
+    ... <zodb>
+    ...    <zeoclient>
+    ...       server :%s
+    ...       client-label test-label-2
+    ...    </zeoclient>
+    ... </zodb>
+    ... ''' % addr[1])
+    >>> db.close()
+    >>> for line in open('server-%s.log' % addr[1]):
+    ...     if 'test-label-2' in line:
+    ...         print line.split()[1:4]
+    ['INFO', 'ZEO.StorageServer', '(test-label-2']
+
+    """
+
+
 if sys.version_info >= (2, 6):
     import multiprocessing
 

Modified: ZODB/trunk/src/ZODB/component.xml
===================================================================
--- ZODB/trunk/src/ZODB/component.xml	2010-05-04 19:17:23 UTC (rev 111942)
+++ ZODB/trunk/src/ZODB/component.xml	2010-05-04 19:26:56 UTC (rev 111943)
@@ -216,6 +216,11 @@
         instead of an expensive verification.
       </description>
     </key>
+    <key name="client-label" required="no">
+      <description>
+        A label for the client in server logs
+      </description>
+    </key>
   </sectiontype>
 
   <sectiontype name="demostorage" datatype=".DemoStorage"

Modified: ZODB/trunk/src/ZODB/config.py
===================================================================
--- ZODB/trunk/src/ZODB/config.py	2010-05-04 19:17:23 UTC (rev 111942)
+++ ZODB/trunk/src/ZODB/config.py	2010-05-04 19:26:56 UTC (rev 111943)
@@ -188,6 +188,8 @@
             options['blob_cache_size'] = self.config.blob_cache_size
         if self.config.blob_cache_size_check is not None:
             options['blob_cache_size_check'] = self.config.blob_cache_size_check
+        if self.config.client_label is not None:
+            options['client_label'] = self.config.client_label
 
         return ClientStorage(
             L,



More information about the Zodb-checkins mailing list