Skip to content

Commit

Permalink
Merge pull request #3467 from gizmoguy/gauge-no-response-fix
Browse files Browse the repository at this point in the history
update() -> _update() for prom pollers
  • Loading branch information
gizmoguy authored Feb 18, 2020
2 parents 903df03 + 00adeb9 commit 52c1e22
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion faucet/gauge.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ def _start_watchers(self, ryu_dp, watchers, timestamp):
for i, watcher in enumerate(watchers_by_name):
is_active = i == 0
watcher.report_dp_status(1)
watcher.start(ryu_dp, is_active)
if isinstance(watcher, GaugePortStatePoller):
for port in ryu_dp.ports.values():
msg = parser.OFPPortStatus(
ryu_dp, desc=port, reason=ofp.OFPPR_ADD)
watcher.update(timestamp, msg)
watcher.start(ryu_dp, is_active)

@kill_on_exception(exc_logname)
def _datapath_connect(self, ryu_event):
Expand Down
7 changes: 6 additions & 1 deletion faucet/gauge_pollers.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ def send_req(self):

def no_response(self):
"""Called when a polling cycle passes without receiving a response."""
self.logger.info('no response to %s' % self.req)

dpid_str = ''
if self.req and 'datapath' in self.req:
dpid_str = 'DPID %s (%s)' % (self.req.datapath.id, hex(self.req.datapath.id))

self.logger.info('%s no response to %s', dpid_str, self.req)

def update(self, rcv_time, msg):
"""Handle the responses to requests.
Expand Down
8 changes: 4 additions & 4 deletions faucet/gauge_prom.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def _format_stat_pairs(self, delim, stat):
for prom_var in PROM_PORT_VARS)
return self._format_stats(delim, stat_pairs)

def update(self, rcv_time, msg):
def _update(self, rcv_time, msg):
for stat in msg.body:
port_labels = self.dp.port_labels(stat.port_no)
for stat_name, stat_val in self._format_stat_pairs(
Expand Down Expand Up @@ -136,7 +136,7 @@ def _format_stat_pairs(self, delim, stat):
)
return self._format_stats(delim, stat_pairs)

def update(self, rcv_time, msg):
def _update(self, rcv_time, msg):
for stat in msg.body:
meter_labels = self.dp.base_prom_labels()
meter_labels.update({'meter_id': stat.meter_id})
Expand All @@ -149,7 +149,7 @@ def update(self, rcv_time, msg):
class GaugePortStatePrometheusPoller(GaugePortStatePoller):
"""Export port state changes to Prometheus."""

def update(self, rcv_time, msg):
def _update(self, rcv_time, msg):
port_no = msg.desc.port_no
port = self.dp.ports.get(port_no, None)
if port is None:
Expand All @@ -164,7 +164,7 @@ def update(self, rcv_time, msg):
class GaugeFlowTablePrometheusPoller(GaugeFlowTablePoller):
"""Export flow table entries to Prometheus."""

def update(self, rcv_time, msg):
def _update(self, rcv_time, msg):
jsondict = msg.to_jsondict()
for stats_reply in jsondict['OFPFlowStatsReply']['body']:
stats = stats_reply['OFPFlowStats']
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/gauge/test_gauge.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ def test_poller(self):
)

prom_poller = gauge_prom.GaugePortStatsPrometheusPoller(conf, '__name__', self.prom_client)
prom_poller._running = True
msg = port_stats_msg(datapath)
prom_poller.update(time.time(), msg)

Expand Down Expand Up @@ -316,6 +317,7 @@ def test_port_state(self):
)

prom_poller = gauge_prom.GaugePortStatePrometheusPoller(conf, '__name__', self.prom_client)
prom_poller._running = True
reasons = [ofproto.OFPPR_ADD, ofproto.OFPPR_DELETE, ofproto.OFPPR_MODIFY]
for i in range(1, len(conf.dp.ports) + 1):

Expand Down

0 comments on commit 52c1e22

Please sign in to comment.