qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gmur...@apache.org
Subject [qpid-dispatch] branch master updated: DISPATCH-1558: Introduced a new logging module called PROTOCOL. This closes #675
Date Wed, 29 Jan 2020 15:27:45 GMT
This is an automated email from the ASF dual-hosted git repository.

gmurthy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-dispatch.git


The following commit(s) were added to refs/heads/master by this push:
     new e0895ee  DISPATCH-1558: Introduced a new logging module called PROTOCOL. This closes
#675
e0895ee is described below

commit e0895ee1e89c15992108502a3b6b063649b46914
Author: Ganesh Murthy <gmurthy@apache.org>
AuthorDate: Mon Jan 27 13:09:45 2020 -0500

    DISPATCH-1558: Introduced a new logging module called PROTOCOL. This closes #675
---
 python/qpid_dispatch/management/qdrouter.json |   1 +
 src/server.c                                  |  16 +++-
 tests/system_tests_log_level_update.py        | 116 +++++++++++++++++++++++---
 tests/system_tests_topology_disposition.py.in |   2 +-
 4 files changed, 119 insertions(+), 16 deletions(-)

diff --git a/python/qpid_dispatch/management/qdrouter.json b/python/qpid_dispatch/management/qdrouter.json
index b414700..b647a4f 100644
--- a/python/qpid_dispatch/management/qdrouter.json
+++ b/python/qpid_dispatch/management/qdrouter.json
@@ -1082,6 +1082,7 @@
                         "HTTP",
                         "CONN_MGR",
                         "PYTHON",
+                        "PROTOCOL",
                         "DEFAULT"
                     ],
                     "required": true,
diff --git a/src/server.c b/src/server.c
index dada7e8..6b6eb7c 100644
--- a/src/server.c
+++ b/src/server.c
@@ -58,6 +58,7 @@ struct qd_server_t {
     pn_proactor_t            *proactor;
     qd_container_t           *container;
     qd_log_source_t          *log_source;
+    qd_log_source_t          *protocol_log_source; // Log source for the PROTOCOL module
     void                     *start_context;
     sys_cond_t               *cond;
     sys_mutex_t              *lock;
@@ -98,14 +99,17 @@ static const int BACKLOG = 50;  /* Listening backlog */
 static void setup_ssl_sasl_and_open(qd_connection_t *ctx);
 static qd_failover_item_t *qd_connector_get_conn_info(qd_connector_t *ct);
 
+
 /**
  * This function is set as the pn_transport->tracer and is invoked when proton tries to
write the log message to pn_transport->tracer
  */
 static void transport_tracer(pn_transport_t *transport, const char *message)
 {
     qd_connection_t *ctx = (qd_connection_t*) pn_transport_get_context(transport);
-    if (ctx)
-        qd_log(ctx->server->log_source, QD_LOG_TRACE, "[%"PRIu64"]:%s", ctx->connection_id,
message);
+    if (ctx) {
+        // The PROTOCOL module is used exclusively for logging protocol related tracing.
The protocol could be AMQP, HTTP, TCP etc.
+        qd_log(ctx->server->protocol_log_source, QD_LOG_TRACE, "[%"PRIu64"]:%s", ctx->connection_id,
message);
+    }
 }
 
 
@@ -609,9 +613,12 @@ static void on_connection_bound(qd_server_t *server, pn_event_t *e) {
 
     //
     // Proton pushes out its trace to transport_tracer() which in turn writes a trace
-    // message to the qdrouter log If trace level logging is enabled on the router set
+    // message to the qdrouter log
+    // If trace level logging is enabled on the PROTOCOL module, set PN_TRACE_FRM as the
transport trace
+    // and also set the transport tracer callback.
+    // Note here that if trace level logging is enabled on the DEFAULT module, all modules
are logging at trace level too.
     //
-    if (qd_log_enabled(ctx->server->log_source, QD_LOG_TRACE)) {
+    if (qd_log_enabled(ctx->server->protocol_log_source, QD_LOG_TRACE)) {
         pn_transport_trace(tport, PN_TRACE_FRM);
         pn_transport_set_tracer(tport, transport_tracer);
     }
@@ -1226,6 +1233,7 @@ qd_server_t *qd_server(qd_dispatch_t *qd, int thread_count, const char
*containe
 
     qd_server->qd               = qd;
     qd_server->log_source       = qd_log_source("SERVER");
+    qd_server->protocol_log_source = qd_log_source("PROTOCOL");
     qd_server->container_name   = container_name;
     qd_server->sasl_config_path = sasl_config_path;
     qd_server->sasl_config_name = sasl_config_name;
diff --git a/tests/system_tests_log_level_update.py b/tests/system_tests_log_level_update.py
index b1ae588..9fa0f2e 100644
--- a/tests/system_tests_log_level_update.py
+++ b/tests/system_tests_log_level_update.py
@@ -26,6 +26,100 @@ from proton.reactor import AtMostOnce
 
 apply_options = AtMostOnce()
 
+
+class LogModuleProtocolTest(TestCase):
+    @classmethod
+    def setUpClass(cls):
+        super(LogModuleProtocolTest, cls).setUpClass()
+        name = "test-router"
+        LogModuleProtocolTest.listen_port = cls.tester.get_port()
+        config = Qdrouterd.Config([
+            ('router', {'mode': 'standalone', 'id': 'QDR'}),
+            ('listener', {'port': LogModuleProtocolTest.listen_port}),
+            ('address', {'prefix': 'closest', 'distribution': 'closest'}),
+            ('address', {'prefix': 'balanced', 'distribution': 'balanced'}),
+            ('address', {'prefix': 'multicast', 'distribution': 'multicast'})
+        ])
+        cls.router = cls.tester.qdrouterd(name, config)
+        cls.router.wait_ready()
+        cls.address = cls.router.addresses[0]
+
+    def create_sender_receiver(self, test_address, test_msg, blocking_connection=None):
+        if not blocking_connection:
+            blocking_connection = BlockingConnection(self.address)
+        blocking_receiver = blocking_connection.create_receiver(address=test_address)
+        blocking_sender = blocking_connection.create_sender(address=test_address,  options=apply_options)
+        msg = Message(body=test_msg)
+        blocking_sender.send(msg)
+        received_message = blocking_receiver.receive()
+        self.assertEqual(test_msg, received_message.body)
+
+    def test_turn_on_protocol_trace(self):
+        hello_world_0 = "Hello World_0!"
+        qd_manager = QdManager(self, self.address)
+        blocking_connection = BlockingConnection(self.address)
+
+        TEST_ADDR = "moduletest0"
+        self.create_sender_receiver(TEST_ADDR, hello_world_0, blocking_connection)
+
+        num_attaches = 0
+        logs = qd_manager.get_log()
+        for log in logs:
+            if u'PROTOCOL' in log[0]:
+                if "@attach" in log[2] and TEST_ADDR in log[2]:
+                    num_attaches += 1
+
+        # num_attaches for address TEST_ADDR must be 4, two attaches to/from sender and receiver
+        self.assertTrue(num_attaches == 4)
+
+        # Turn off trace logging using qdmanage
+        qd_manager.update("org.apache.qpid.dispatch.log", {"enable": "info+"}, name="log/DEFAULT")
+
+        # Turn on trace (not trace+) level logging for the PROTOCOL module. After doing
+        # this we will create a sender and a receiver and make sure that the PROTOCOL module
+        # is emitting proton frame trace messages.
+
+        # Before DISPATCH-1558, the only way to turn on proton frame trace logging was to
set
+        # enable to trace on the SERVER or the DEFAULT module. Turning on trace for the SERVER
+        # module would also spit out dispatch trace level messages from the SERVER module.
+        # DISPATCH-1558 adds the new PROTOCOL module which moves all protocol traces into
+        # that module.
+        qd_manager.update("org.apache.qpid.dispatch.log", {"enable": "trace+"}, name="log/PROTOCOL")
+
+        TEST_ADDR = "moduletest1"
+        hello_world_1 = "Hello World_1!"
+        self.create_sender_receiver(TEST_ADDR, hello_world_1, blocking_connection)
+
+        num_attaches = 0
+        logs = qd_manager.get_log()
+        for log in logs:
+            if u'PROTOCOL' in log[0]:
+                if "@attach" in log[2] and TEST_ADDR in log[2]:
+                    num_attaches += 1
+
+        # num_attaches for address TEST_ADDR must be 4, two attaches to/from sender and receiver
+        self.assertTrue(num_attaches == 4)
+
+        # Now turn off trace logging for the PROTOCOL module and make sure
+        # that there is no more proton frame trace messages appearing in the log
+        qd_manager.update("org.apache.qpid.dispatch.log",
+                          {"enable": "info+"}, name="log/PROTOCOL")
+
+        TEST_ADDR = "moduletest2"
+        hello_world_2 = "Hello World_2!"
+        self.create_sender_receiver(TEST_ADDR, hello_world_2, blocking_connection)
+
+        num_attaches = 0
+        logs = qd_manager.get_log()
+        for log in logs:
+            if u'PROTOCOL' in log[0]:
+                if "@attach" in log[2] and TEST_ADDR in log[2]:
+                    num_attaches += 1
+
+        # num_attaches for address TEST_ADDR must be 4, two attaches to/from sender and receiver
+        self.assertTrue(num_attaches == 0)
+
+
 class LogLevelUpdateTest(TestCase):
     @classmethod
     def setUpClass(cls):
@@ -71,7 +165,7 @@ class LogLevelUpdateTest(TestCase):
         num_attaches = 0
         logs = qd_manager.get_log()
         for log in logs:
-            if u'SERVER' in log[0]:
+            if u'PROTOCOL' in log[0]:
                 if "@attach" in log[2] and TEST_ADDR in log[2]:
                     num_attaches += 1
         # num_attaches for address TEST_ADDR must be 4, two attaches to/from sender and receiver
@@ -91,7 +185,7 @@ class LogLevelUpdateTest(TestCase):
         num_attaches = 0
         logs = qd_manager.get_log()
         for log in logs:
-            if u'SERVER' in log[0]:
+            if u'PROTOCOL' in log[0]:
                 if "@attach" in log[2] and TEST_ADDR in log[2]:
                     num_attaches += 1
         # There should be no attach frames with address TEST_ADDR
@@ -108,7 +202,7 @@ class LogLevelUpdateTest(TestCase):
         num_attaches = 0
         logs = qd_manager.get_log()
         for log in logs:
-            if u'SERVER' in log[0]:
+            if u'PROTOCOL' in log[0]:
                 if "@attach" in log[2] and TEST_ADDR in log[2]:
                     num_attaches += 1
         # There should be 4 attach frames with address TEST_ADDR
@@ -123,7 +217,7 @@ class LogLevelUpdateTest(TestCase):
         num_attaches = 0
         logs = qd_manager.get_log()
         for log in logs:
-            if u'SERVER' in log[0]:
+            if u'PROTOCOL' in log[0]:
                 if "@attach" in log[2] and TEST_ADDR in log[2]:
                     num_attaches += 1
 
@@ -141,12 +235,12 @@ class LogLevelUpdateTest(TestCase):
         TEST_ADDR = "apachetest5"
 
         # Step 1. Turn off trace logging for module DEFAULT and enable trace logging
-        #         for the SERVER module and make sure it works.
+        #         for the PROTOCOL module and make sure it works.
         qd_manager = QdManager(self, self.address)
         # Set log level to info+ on the DEFAULT module
         qd_manager.update("org.apache.qpid.dispatch.log", {"enable": "info+"}, name="log/DEFAULT")
-        # Set log level to trace+ on the SERVER module
-        qd_manager.update("org.apache.qpid.dispatch.log", {"enable": "trace+"}, name="log/SERVER")
+        # Set log level to trace+ on the PROTOCOL module
+        qd_manager.update("org.apache.qpid.dispatch.log", {"enable": "trace+"}, name="log/PROTOCOL")
         blocking_connection = BlockingConnection(self.address)
 
         self.create_sender_receiver(TEST_ADDR, hello_world_5,
@@ -155,7 +249,7 @@ class LogLevelUpdateTest(TestCase):
         num_attaches = 0
         logs = qd_manager.get_log()
         for log in logs:
-            if u'SERVER' in log[0]:
+            if u'PROTOCOL' in log[0]:
                 if "@attach" in log[2] and TEST_ADDR in log[2]:
                     num_attaches += 1
         # There should be 4 attach frames with address TEST_ADDR
@@ -163,7 +257,7 @@ class LogLevelUpdateTest(TestCase):
         self.assertTrue(num_attaches == 4)
 
         TEST_ADDR = "apachetest6"
-        qd_manager.update("org.apache.qpid.dispatch.log", {"enable": "info+"}, name="log/SERVER")
+        qd_manager.update("org.apache.qpid.dispatch.log", {"enable": "info+"}, name="log/PROTOCOL")
 
         self.create_sender_receiver(TEST_ADDR, hello_world_6, blocking_connection)
 
@@ -171,7 +265,7 @@ class LogLevelUpdateTest(TestCase):
         num_attaches = 0
         logs = qd_manager.get_log()
         for log in logs:
-            if u'SERVER' in log[0]:
+            if u'PROTOCOL' in log[0]:
                 if "@attach" in log[2] and TEST_ADDR in log[2]:
                     num_attaches += 1
         self.assertTrue(num_attaches == 0)
@@ -183,7 +277,7 @@ class LogLevelUpdateTest(TestCase):
         num_attaches = 0
         logs = qd_manager.get_log()
         for log in logs:
-            if u'SERVER' in log[0]:
+            if u'PROTOCOL' in log[0]:
                 if "@attach" in log[2] and TEST_ADDR in log[2]:
                     num_attaches += 1
 
diff --git a/tests/system_tests_topology_disposition.py.in b/tests/system_tests_topology_disposition.py.in
index b41c3ad..d69031c 100644
--- a/tests/system_tests_topology_disposition.py.in
+++ b/tests/system_tests_topology_disposition.py.in
@@ -406,7 +406,7 @@ class TopologyDispositionTests ( TestCase ):
         error = None
         if self.skip [ name ] :
             self.skipTest ( "Test skipped during development." )
-        st_key = "SERVER (trace) ["
+        st_key = "PROTOCOL (trace) ["
         qc_key = "qd.conn-id\"="
         for letter in ['A', 'B', 'C', 'D']:
             log_name = ('../setUpClass/%s.log' % letter)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message