From 0c14e232f56bdaa23b816ff64f526e27a0d514e2 Mon Sep 17 00:00:00 2001 From: Josh Bailey Date: Mon, 3 Feb 2020 10:31:41 +1300 Subject: [PATCH 1/2] Log version on startup. Verify Gauge has no exceptions also. --- clib/mininet_test_base.py | 22 ++++++++++++---------- faucet/faucet.py | 15 +++++++-------- faucet/gauge.py | 1 - faucet/prom_client.py | 4 ++-- faucet/valve_ryuapp.py | 3 +++ 5 files changed, 24 insertions(+), 21 deletions(-) diff --git a/clib/mininet_test_base.py b/clib/mininet_test_base.py index 7f2d5bba9b..59a9daaa8f 100644 --- a/clib/mininet_test_base.py +++ b/clib/mininet_test_base.py @@ -460,18 +460,20 @@ def tearDown(self, ignore_oferrors=False): switch_ovs_log_name = os.path.join(self.tmpdir, os.path.basename(ovs_log)) with open(switch_ovs_log_name, 'w') as switch_ovs_log: switch_ovs_log.write('\n'.join(lines)) - # Must not be any controller exception. - self.verify_no_exception(self.env['faucet']['FAUCET_EXCEPTION_LOG']) - # Check for OFErrors - oferrors = '\n\n'.join( - self.matching_lines_from_file( - r'^.+(OFError.+)$', self.env['faucet']['FAUCET_LOG'])) - if not ignore_oferrors: - self.assertFalse( - oferrors, - msg='log has OFPErrorMsgs: %s' % oferrors) with open(os.path.join(self.tmpdir, 'test_duration_secs'), 'w') as duration_file: duration_file.write(str(int(time.time() - self.start_time))) + # Must not be any controller exception. + for exceptionlog in ( + self.env['faucet']['FAUCET_EXCEPTION_LOG'], self.env['gauge']['GAUGE_EXCEPTION_LOG']): + self.verify_no_exception(exceptionlog) + oferrors = '' + for logfile in (self.env['faucet']['FAUCET_LOG'], self.env['gauge']['GAUGE_LOG']): + # Verify version is logged. + self.assertTrue(self.matching_lines_from_file(r'^.+version\s+(\S+)$', logfile)) + # Verify no OFErrors. + oferrors += '\n\n'.join(self.matching_lines_from_file(r'^.+(OFError.+)$', logfile)) + if not ignore_oferrors: + self.assertFalse(oferrors, msg=oferrors) return oferrors def _block_non_faucet_packets(self): diff --git a/faucet/faucet.py b/faucet/faucet.py index 62c4899e61..2052b7468c 100644 --- a/faucet/faucet.py +++ b/faucet/faucet.py @@ -100,7 +100,6 @@ class Faucet(RyuAppBase): logname = 'faucet' exc_logname = logname + '.exception' bgp = None - metrics = None notifier = None valves_manager = None event_socket_heartbeat_time = 0 @@ -108,17 +107,17 @@ class Faucet(RyuAppBase): def __init__(self, *args, **kwargs): super(Faucet, self).__init__(*args, **kwargs) self.api = kwargs['faucet_experimental_api'] - self.metrics = faucet_metrics.FaucetMetrics(reg=self._reg) + self.prom_client = faucet_metrics.FaucetMetrics(reg=self._reg) self.bgp = faucet_bgp.FaucetBgp( - self.logger, self.exc_logname, self.metrics, self._send_flow_msgs) + self.logger, self.exc_logname, self.prom_client, self._send_flow_msgs) self.dot1x = faucet_dot1x.FaucetDot1x( - self.logger, self.exc_logname, self.metrics, self._send_flow_msgs) + self.logger, self.exc_logname, self.prom_client, self._send_flow_msgs) self.notifier = faucet_event.FaucetEventNotifier( - self.get_setting('EVENT_SOCK'), self.metrics, self.logger) + self.get_setting('EVENT_SOCK'), self.prom_client, self.logger) self.valves_manager = valves_manager.ValvesManager( - self.logname, self.logger, self.metrics, self.notifier, self.bgp, + self.logname, self.logger, self.prom_client, self.notifier, self.bgp, self.dot1x, self.get_setting('CONFIG_AUTO_REVERT'), self._send_flow_msgs) - self.thread_managers = (self.bgp, self.dot1x, self.metrics, self.notifier) + self.thread_managers = (self.bgp, self.dot1x, self.prom_client, self.notifier) self.event_sock_hrtbeat_time = int(self.get_setting('EVENT_SOCK_HEARTBEAT') or 0) if self.event_sock_hrtbeat_time > 0: self._VALVE_SERVICES[EventFaucetEventSockHeartbeat] = ('event_sock_heartbeat', self.event_sock_hrtbeat_time) @@ -134,7 +133,7 @@ def start(self): # Start Prometheus prom_port = int(self.get_setting('PROMETHEUS_PORT')) prom_addr = self.get_setting('PROMETHEUS_ADDR') - self.metrics.start(prom_port, prom_addr) + self.prom_client.start(prom_port, prom_addr) # Start event notifier notifier_thread = self.notifier.start() diff --git a/faucet/gauge.py b/faucet/gauge.py index a614b4c7e3..cbce73bc42 100644 --- a/faucet/gauge.py +++ b/faucet/gauge.py @@ -44,7 +44,6 @@ class Gauge(RyuAppBase): """ logname = 'gauge' exc_logname = logname + '.exception' - prom_client = None def __init__(self, *args, **kwargs): super(Gauge, self).__init__(*args, **kwargs) diff --git a/faucet/prom_client.py b/faucet/prom_client.py index e7351529f5..19d7f34d99 100644 --- a/faucet/prom_client.py +++ b/faucet/prom_client.py @@ -54,13 +54,13 @@ def __init__(self, reg=None): if reg is not None: self._reg = reg # TODO: investigate faster alternative (https://bugs.launchpad.net/pbr/+bug/1688405) - version = VersionInfo('faucet').semantic_version().release_string() + self.version = VersionInfo('faucet').semantic_version().release_string() self.faucet_version = PromGauge( # pylint: disable=unexpected-keyword-arg 'faucet_pbr_version', 'Faucet PBR version', ['version'], registry=self._reg) - self.faucet_version.labels(version=version).set(1) # pylint: disable=no-member + self.faucet_version.labels(version=self.version).set(1) # pylint: disable=no-member self.server = None self.thread = None diff --git a/faucet/valve_ryuapp.py b/faucet/valve_ryuapp.py index 9d5406943e..5e928a61f2 100644 --- a/faucet/valve_ryuapp.py +++ b/faucet/valve_ryuapp.py @@ -66,6 +66,7 @@ def __init__(self, *args, **kwargs): self.exc_logname, exc_logfile, logging.DEBUG, 1) self.threads = [] self.thread_managers = [] + self.prom_client = None def _get_threads(self): """Return started threads.""" @@ -138,6 +139,8 @@ def _config_file_stat(self): def start(self): """Start controller.""" super(RyuAppBase, self).start() + if self.prom_client: + self.logger.info('version %s' % self.prom_client.version) if self.stat_reload: self.logger.info('will automatically reload new config on changes') self.reload_config(None) From 404f067066dcd111a53272f2697615cb735001ba Mon Sep 17 00:00:00 2001 From: Josh Bailey Date: Mon, 3 Feb 2020 10:41:32 +1300 Subject: [PATCH 2/2] Stickler. --- faucet/prom_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/faucet/prom_client.py b/faucet/prom_client.py index 19d7f34d99..2ce6b3f136 100644 --- a/faucet/prom_client.py +++ b/faucet/prom_client.py @@ -60,7 +60,7 @@ def __init__(self, reg=None): 'Faucet PBR version', ['version'], registry=self._reg) - self.faucet_version.labels(version=self.version).set(1) # pylint: disable=no-member + self.faucet_version.labels(version=self.version).set(1) # pylint: disable=no-member self.server = None self.thread = None