Skip to content

Commit

Permalink
Merge pull request #3560 from anarkiwi/v
Browse files Browse the repository at this point in the history
minor prom var refactoring.
  • Loading branch information
anarkiwi authored May 11, 2020
2 parents 34b3c7e + 023c482 commit 018eaf0
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions faucet/valve.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
from faucet.valve_lldp import ValveLLDPManager
from faucet.valve_outonly import OutputOnlyManager
from faucet.valve_switch_stack import ValveSwitchStackManagerBase
from faucet.vlan import NullVLAN


# TODO: has to be here to avoid eventlet monkey patch in faucet_dot1x.
Expand Down Expand Up @@ -165,6 +164,9 @@ def _set_var(self, var, val, labels=None):
metrics_var = getattr(self.metrics, var)
metrics_var.labels(**labels).set(val)

def _set_port_var(self, var, val, port):
self._set_var(var, val, labels=self.dp.port_labels(port.number))

def _remove_var(self, var, labels=None):
if labels is None:
labels = self.dp.base_prom_labels()
Expand Down Expand Up @@ -450,8 +452,7 @@ def _set_port_status(self, port_no, port_status, now):
port = self.dp.ports.get(port_no, None)
if port is None:
return
port_labels = self.dp.port_labels(port.number)
self._set_var('port_status', port_status, labels=port_labels)
self._set_port_var('port_status', port_status, port)
port.dyn_update_time = now

def port_status_handler(self, port_no, reason, state, _other_valves, now):
Expand Down Expand Up @@ -632,10 +633,7 @@ def _update_stack_link_state(self, ports, now, other_valves):
next_state = self._next_stack_link_state(port, now)
if next_state is not None:
next_state()
self._set_var(
'port_stack_state',
port.dyn_stack_current_state,
labels=self.dp.port_labels(port.number))
self._set_port_var('port_stack_state', port.dyn_stack_current_state, port)
self.notify({'STACK_STATE': {
'port': port.number,
'state': port.dyn_stack_current_state
Expand Down Expand Up @@ -735,10 +733,7 @@ def fast_state_expire(self, now, other_valves):
return self._update_stack_link_state(self.dp.stack_ports, now, other_valves)

def _reset_dp_status(self):
if self.dp.dyn_running:
self._set_var('dp_status', 1)
else:
self._set_var('dp_status', 0)
self._set_var('dp_status', int(self.dp.dyn_running))

def datapath_connect(self, now, discovered_up_ports):
"""Handle Ryu datapath connection event and provision pipeline.
Expand Down Expand Up @@ -834,8 +829,7 @@ def ports_add(self, port_nums, cold_start=False, log_msg='up'):
ofmsgs.extend(self.lacp_update(port, False))
if port.lacp_active:
ofmsgs.extend(self._lacp_actions(port.dyn_last_lacp_pkt, port))
self._set_var('lacp_port_id',
port.lacp_port_id, labels=self.dp.port_labels(port.number))
self._set_port_var('lacp_port_id', port.lacp_port_id, port)

if port.stack:
port_vlans = self.dp.vlans.values()
Expand Down Expand Up @@ -901,7 +895,7 @@ def port_delete(self, port_num, keep_cache=False, other_valves=None):
def _reset_lacp_status(self, port):
lacp_state = port.actor_state()
lacp_role = port.lacp_port_state()
self._set_var('port_lacp_state', lacp_state, labels=self.dp.port_labels(port.number))
self._set_port_var('port_lacp_state', lacp_state, port)
self.notify(
{'LAG_CHANGE': {'port_no': port.number, 'state': lacp_state, 'role': lacp_role}})

Expand Down Expand Up @@ -964,7 +958,7 @@ def lacp_update_port_selection_state(self, port, other_valves=None, cold_start=F
self.logger.info('LAG %u %s %s (previous state %s)' % (
port.lacp, port, port.port_role_name(new_state),
port.port_role_name(prev_state)))
self._set_var('port_lacp_role', new_state, labels=self.dp.port_labels(port.number))
self._set_port_var('port_lacp_role', new_state, port)
return new_state != prev_state

def lacp_update_actor_state(self, port, lacp_up, now=None, lacp_pkt=None, cold_start=False):
Expand Down Expand Up @@ -1457,11 +1451,10 @@ def _update_vlan(vlan, now, rate_limited):
return True

def _update_port(vlan, port):
port_labels = self.dp.port_labels(port.number)
port_vlan_labels = self._port_vlan_labels(port, vlan)
port_vlan_hosts_learned = port.hosts_count(vlans=[vlan])
self._set_var(
'port_learn_bans', port.dyn_learn_ban_count, labels=port_labels)
self._set_port_var(
'port_learn_bans', port.dyn_learn_ban_count, port)
self._set_var(
'port_vlan_hosts_learned', port_vlan_hosts_learned, labels=port_vlan_labels)
highwater = self._port_highwater[vlan.vid][port.number]
Expand Down

0 comments on commit 018eaf0

Please sign in to comment.