VOL-398, VOL-399: Include vcoreids in the log and start the grpc local and global services after the reconcilation process has been completed
Change-Id: I5dece92c0d4cc8ea0724b07c5d8e76a06614278a
diff --git a/common/structlog_setup.py b/common/structlog_setup.py
index 6a149c0..be04ded 100644
--- a/common/structlog_setup.py
+++ b/common/structlog_setup.py
@@ -111,3 +111,38 @@
log = structlog.get_logger()
log.info("first-line")
return log
+
+
+def update_logging(instance_id, vcore_id):
+ """
+ Add the vcore id to the structured logger
+ :param vcore_id: The assigned vcore id
+ :return: structure logger
+ """
+ def add_exc_info_flag_for_exception(_, name, event_dict):
+ if name == 'exception':
+ event_dict['exc_info'] = True
+ return event_dict
+
+ def add_instance_id(_, __, event_dict):
+ event_dict['instance_id'] = instance_id
+ return event_dict
+
+ def add_vcore_id(_, __, event_dict):
+ event_dict['vcore_id'] = vcore_id
+ return event_dict
+
+ processors = [
+ add_exc_info_flag_for_exception,
+ structlog.processors.StackInfoRenderer(),
+ structlog.processors.format_exc_info,
+ add_instance_id,
+ add_vcore_id,
+ FluentRenderer(),
+ ]
+ structlog.configure(processors=processors)
+
+ # Mark first line of log
+ log = structlog.get_logger()
+ log.info("updated-logger")
+ return log
diff --git a/voltha/core/core.py b/voltha/core/core.py
index ab8b157..1b01f62 100644
--- a/voltha/core/core.py
+++ b/voltha/core/core.py
@@ -97,6 +97,11 @@
log.info('started')
returnValue(self)
+ @inlineCallbacks
+ def register_grpc_service(self):
+ yield self.local_handler.register_grpc_service()
+ yield self.global_handler.register_grpc_service()
+
def stop(self):
log.debug('stopping')
self.stopped = True
diff --git a/voltha/core/global_handler.py b/voltha/core/global_handler.py
index 56604a5..ac5c3aa 100644
--- a/voltha/core/global_handler.py
+++ b/voltha/core/global_handler.py
@@ -101,11 +101,15 @@
def start(self):
log.debug('starting')
self.root = ConfigRoot(Voltha(**self.init_kw))
- registry('grpc_server').register(
- add_VolthaGlobalServiceServicer_to_server, self)
log.info('started')
return self
+ def register_grpc_service(self):
+ log.debug('registering')
+ registry('grpc_server').register(
+ add_VolthaGlobalServiceServicer_to_server, self)
+ log.info('registered')
+
def stop(self):
log.debug('stopping')
self.stopped = True
diff --git a/voltha/core/local_handler.py b/voltha/core/local_handler.py
index c598911..7676fab 100644
--- a/voltha/core/local_handler.py
+++ b/voltha/core/local_handler.py
@@ -82,12 +82,16 @@
self.core.xpon_handler.start(self.root)
- registry('grpc_server').register(
- add_VolthaLocalServiceServicer_to_server, self)
-
log.info('started')
return self
+ def register_grpc_service(self):
+ log.debug('registering')
+ registry('grpc_server').register(
+ add_VolthaLocalServiceServicer_to_server, self)
+ log.info('registered')
+
+
def stop(self):
log.debug('stopping')
self.stopped = True
diff --git a/voltha/main.py b/voltha/main.py
index c5cb300..27b29f9 100755
--- a/voltha/main.py
+++ b/voltha/main.py
@@ -30,7 +30,7 @@
from common.event_bus import EventBusClient
from common.manhole import Manhole
-from common.structlog_setup import setup_logging
+from common.structlog_setup import setup_logging, update_logging
from common.utils.dockerhelpers import get_my_containers_name
from common.utils.nethelpers import get_my_primary_interface, \
get_my_primary_local_ipv4
@@ -344,6 +344,9 @@
self.log.info('store-id', core_store_id=self.core_store_id)
+ # Update the logger to output the vcore id.
+ self.log = update_logging(instance_id=self.instance_id, vcore_id=self.core_store_id)
+
yield registry.register(
'grpc_server',
VolthaGrpcServer(self.args.grpc_port)
@@ -398,6 +401,11 @@
yield registry('core').reconcile_data()
+ # Now that the data is in memory and the reconcile process
+ # within the core has completed (the reconciliation may still be
+ # in progress with the adapters) we expose the NBI of voltha core
+ yield registry('core').register_grpc_service()
+
self.log.info('started-internal-services')
except Exception as e: