Skip to content

Commit

Permalink
[xcvrd] add support for logging mux_metrics events into state DB (son…
Browse files Browse the repository at this point in the history
…ic-net#185)

* [xcvrd] add support for logging mux_metrics events into state DB

Description
This PR adds support for logging events for change requests received by xcvrd from swss into state DB.
a typical log would look like this:
1) "xcvrd_switch_standby_start"
2) "2021-05-13 10:01:15.690835"
3) "xcvrd_switch_standby_end"
4) "2021-05-13 10:01:15.696051"

where the key-value pairs signify the type of event requested out of
active/standby/unknown and the timestamp associated with the event.

Motivation and Context
This is required for xcvrd to log the events which it receives in form of requests from swss or any other module into the DB. The timestamp will be useful for debugging the timeline of an event processing from a perspective of other modules as well as xcvrd itself.

How Has This Been Tested?
ran the changes on starlab testbed, by changing the file in the container.

Signed-off-by: vaibhav-dahiya <[email protected]>
  • Loading branch information
vdahiya12 authored May 17, 2021
1 parent 807b304 commit e60804c
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions sonic-xcvrd/xcvrd/xcvrd_utilities/y_cable_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
helper utlities configuring y_cable for xcvrd daemon
"""

import datetime
import threading

from sonic_py_common import daemon_base, logger
Expand Down Expand Up @@ -1010,6 +1011,7 @@ def task_worker(self):
appl_db, state_db, status_tbl, y_cable_tbl = {}, {}, {}, {}
y_cable_tbl_keys = {}
mux_cable_command_tbl, y_cable_command_tbl = {}, {}
mux_metrics_tbl = {}

sel = swsscommon.Select()

Expand All @@ -1028,6 +1030,8 @@ def task_worker(self):
state_db[asic_id] = daemon_base.db_connect("STATE_DB", namespace)
y_cable_tbl[asic_id] = swsscommon.Table(
state_db[asic_id], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME)
mux_metrics_tbl[asic_id] = swsscommon.Table(
state_db[asic_id], swsscommon.STATE_MUX_METRICS_TABLE_NAME)
y_cable_tbl_keys[asic_id] = y_cable_tbl[asic_id].getKeys()
sel.addSelectable(status_tbl[asic_id])
sel.addSelectable(mux_cable_command_tbl[asic_id])
Expand Down Expand Up @@ -1058,6 +1062,10 @@ def task_worker(self):
(port, op, fvp) = status_tbl[asic_index].pop()
if not port:
break

# entering this section signifies a start for xcvrd state
# change request from swss so initiate recording in mux_metrics table
time_start = datetime.datetime.utcnow().strftime("%Y-%b-%d %H:%M:%S.%f")
if fvp:
# This check might be redundant, to check, the presence of this Port in keys
# in logical_port_list but keep for now for coherency
Expand Down Expand Up @@ -1091,6 +1099,10 @@ def task_worker(self):
y_cable_tbl[asic_index].set(port, fvs_updated)
helper_logger.log_info("Got a change event for toggle the mux-direction active side for port {} state from {} to {}".format(
port, old_status, new_status))
time_end = datetime.datetime.utcnow().strftime("%Y-%b-%d %H:%M:%S.%f")
fvs_metrics = swsscommon.FieldValuePairs([('xcvrd_switch_{}_start'.format(new_status), str(time_start)),
('xcvrd_switch_{}_end'.format(new_status), str(time_end))])
mux_metrics_tbl[asic_index].set(port, fvs_metrics)
else:
helper_logger.log_info("Got a change event on port {} of table {} that does not contain state".format(
port, swsscommon.APP_HW_MUX_CABLE_TABLE_NAME))
Expand Down

0 comments on commit e60804c

Please sign in to comment.