Skip to content

Commit e60804c

Browse files
authored
[xcvrd] add support for logging mux_metrics events into state DB (#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 <vdahiya@microsoft.com>
1 parent 807b304 commit e60804c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

sonic-xcvrd/xcvrd/xcvrd_utilities/y_cable_helper.py

+12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
helper utlities configuring y_cable for xcvrd daemon
44
"""
55

6+
import datetime
67
import threading
78

89
from sonic_py_common import daemon_base, logger
@@ -1010,6 +1011,7 @@ def task_worker(self):
10101011
appl_db, state_db, status_tbl, y_cable_tbl = {}, {}, {}, {}
10111012
y_cable_tbl_keys = {}
10121013
mux_cable_command_tbl, y_cable_command_tbl = {}, {}
1014+
mux_metrics_tbl = {}
10131015

10141016
sel = swsscommon.Select()
10151017

@@ -1028,6 +1030,8 @@ def task_worker(self):
10281030
state_db[asic_id] = daemon_base.db_connect("STATE_DB", namespace)
10291031
y_cable_tbl[asic_id] = swsscommon.Table(
10301032
state_db[asic_id], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME)
1033+
mux_metrics_tbl[asic_id] = swsscommon.Table(
1034+
state_db[asic_id], swsscommon.STATE_MUX_METRICS_TABLE_NAME)
10311035
y_cable_tbl_keys[asic_id] = y_cable_tbl[asic_id].getKeys()
10321036
sel.addSelectable(status_tbl[asic_id])
10331037
sel.addSelectable(mux_cable_command_tbl[asic_id])
@@ -1058,6 +1062,10 @@ def task_worker(self):
10581062
(port, op, fvp) = status_tbl[asic_index].pop()
10591063
if not port:
10601064
break
1065+
1066+
# entering this section signifies a start for xcvrd state
1067+
# change request from swss so initiate recording in mux_metrics table
1068+
time_start = datetime.datetime.utcnow().strftime("%Y-%b-%d %H:%M:%S.%f")
10611069
if fvp:
10621070
# This check might be redundant, to check, the presence of this Port in keys
10631071
# in logical_port_list but keep for now for coherency
@@ -1091,6 +1099,10 @@ def task_worker(self):
10911099
y_cable_tbl[asic_index].set(port, fvs_updated)
10921100
helper_logger.log_info("Got a change event for toggle the mux-direction active side for port {} state from {} to {}".format(
10931101
port, old_status, new_status))
1102+
time_end = datetime.datetime.utcnow().strftime("%Y-%b-%d %H:%M:%S.%f")
1103+
fvs_metrics = swsscommon.FieldValuePairs([('xcvrd_switch_{}_start'.format(new_status), str(time_start)),
1104+
('xcvrd_switch_{}_end'.format(new_status), str(time_end))])
1105+
mux_metrics_tbl[asic_index].set(port, fvs_metrics)
10941106
else:
10951107
helper_logger.log_info("Got a change event on port {} of table {} that does not contain state".format(
10961108
port, swsscommon.APP_HW_MUX_CABLE_TABLE_NAME))

0 commit comments

Comments
 (0)