Skip to content

Commit

Permalink
Merge pull request #3445 from anarkiwi/verlog
Browse files Browse the repository at this point in the history
Log version on startup.
  • Loading branch information
anarkiwi authored Feb 3, 2020
2 parents 863b5a9 + 404f067 commit c4f131d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
22 changes: 12 additions & 10 deletions clib/mininet_test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
15 changes: 7 additions & 8 deletions faucet/faucet.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,25 +100,24 @@ class Faucet(RyuAppBase):
logname = 'faucet'
exc_logname = logname + '.exception'
bgp = None
metrics = None
notifier = None
valves_manager = None
event_socket_heartbeat_time = 0

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)
Expand All @@ -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()
Expand Down
1 change: 0 additions & 1 deletion faucet/gauge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions faucet/prom_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions faucet/valve_ryuapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c4f131d

Please sign in to comment.