Change in vdsm[ovirt-3.6]: stomp: reducing log footprint from stomp lib

piotr.kliczewski at gmail.com piotr.kliczewski at gmail.com
Tue Oct 20 11:37:11 UTC 2015


Piotr Kliczewski has uploaded a new change for review.

Change subject: stomp: reducing log footprint from stomp lib
......................................................................

stomp: reducing log footprint from stomp lib

There was bunch of not needed information about being not able to
process disconnect frame (part of the spec and expected). We made
vdsm aware of disconnect frame and few headers which are required
to validate the frame. 

We removed log statement which generate the most information
about message being sent but it do not bring any value when
debugging issues.


Bug-Url: https://bugzilla.redhat.com/1239062
Change-Id: I98f0c443fd50ec9e05dcf71ee1c7baabd044f48d
Signed-off-by: pkliczewski <piotr.kliczewski at gmail.com>
---
M lib/yajsonrpc/stomp.py
M lib/yajsonrpc/stompreactor.py
2 files changed, 29 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/16/47516/1

diff --git a/lib/yajsonrpc/stomp.py b/lib/yajsonrpc/stomp.py
index 7436984..633f307 100644
--- a/lib/yajsonrpc/stomp.py
+++ b/lib/yajsonrpc/stomp.py
@@ -55,12 +55,15 @@
     CONNECTED = "CONNECTED"
     ERROR = "ERROR"
     RECEIPT = "RECEIPT"
+    DISCONNECT = "DISCONNECT"
 
 
 class Headers(object):
     CONTENT_LENGTH = "content-length"
     CONTENT_TYPE = "content-type"
     SUBSCRIPTION = "subscription"
+    RECEIPT = "receipt"
+    RECEIPT_ID = "receipt-id"
     DESTINATION = "destination"
     ACCEPT_VERSION = "accept-version"
     REPLY_TO = "reply-to"
@@ -430,6 +433,7 @@
             Command.MESSAGE: self._process_message,
             Command.RECEIPT: self._process_receipt,
             Command.ERROR: self._process_error,
+            Command.DISCONNECT: self._process_disconnect
         }
 
     @property
@@ -488,7 +492,7 @@
         sub.handle_message(frame)
 
     def _process_receipt(self, frame, dispatcher):
-        self.log.warning("Receipt frame received and ignored")
+        self.log.debug("Receipt frame received")
 
     def _process_error(self, frame, dispatcher):
         raise StompError(frame)
@@ -528,6 +532,16 @@
         self.queue_frame(Frame(Command.UNSUBSCRIBE,
                                {"id": sub.id}))
 
+    def _process_disconnect(self, frame, dispatcher):
+        r_id = frame.headers[Headers.RECEIPT]
+        if not r_id:
+            self.log.debug("No receipt id for disconnect frame")
+            # it is not mandatory to send receipt frame
+            return
+
+        headers = {Headers.RECEIPT_ID: r_id}
+        self.queue_frame(Frame(Command.RECEIPT, headers))
+
 
 class _Subscription(object):
 
diff --git a/lib/yajsonrpc/stompreactor.py b/lib/yajsonrpc/stompreactor.py
index 87cab3f..57237c9 100644
--- a/lib/yajsonrpc/stompreactor.py
+++ b/lib/yajsonrpc/stompreactor.py
@@ -75,7 +75,8 @@
             stomp.Command.CONNECT: self._cmd_connect,
             stomp.Command.SEND: self._cmd_send,
             stomp.Command.SUBSCRIBE: self._cmd_subscribe,
-            stomp.Command.UNSUBSCRIBE: self._cmd_unsubscribe}
+            stomp.Command.UNSUBSCRIBE: self._cmd_unsubscribe,
+            stomp.Command.DISCONNECT: self._cmd_disconnect}
 
     @property
     def has_outgoing_messages(self):
@@ -165,6 +166,18 @@
             return
         else:
             self._remove_subscription(subscription)
+
+    def _cmd_disconnect(self, dispatcher, frame):
+        self.log.info("Disconnect command received")
+        r_id = frame.headers[stomp.Headers.RECEIPT]
+        if not r_id:
+            self.log.debug("No receipt id for disconnect frame")
+            # it is not mandatory to send receipt frame
+            return
+
+        headers = {stomp.Headers.RECEIPT_ID: r_id}
+        dispatcher.connection.send_raw(stomp.Frame(stomp.Command.RECEIPT,
+                                                   headers))
 
     def _remove_subscription(self, subscription):
         subs = self._sub_dests[subscription.destination]
@@ -301,7 +314,6 @@
     Sends message to all subscribes that subscribed to destination.
     """
     def send(self, message, destination=stomp.LEGACY_SUBSCRIPTION_ID_RESPONSE):
-        self.log.debug("Sending response")
         try:
             resp = json.loads(message)
             destination = self._req_dest[resp.get("id")]


-- 
To view, visit https://gerrit.ovirt.org/47516
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I98f0c443fd50ec9e05dcf71ee1c7baabd044f48d
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.6
Gerrit-Owner: Piotr Kliczewski <piotr.kliczewski at gmail.com>


More information about the vdsm-patches mailing list