From e60804cd823090291ad1032e2ef3e9edb11d5a65 Mon Sep 17 00:00:00 2001 From: vdahiya12 <67608553+vdahiya12@users.noreply.github.com> Date: Mon, 17 May 2021 11:20:59 -0700 Subject: [PATCH] [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 --- sonic-xcvrd/xcvrd/xcvrd_utilities/y_cable_helper.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sonic-xcvrd/xcvrd/xcvrd_utilities/y_cable_helper.py b/sonic-xcvrd/xcvrd/xcvrd_utilities/y_cable_helper.py index 3d0e2294a62f..ac2fc4e0dbe3 100644 --- a/sonic-xcvrd/xcvrd/xcvrd_utilities/y_cable_helper.py +++ b/sonic-xcvrd/xcvrd/xcvrd_utilities/y_cable_helper.py @@ -3,6 +3,7 @@ helper utlities configuring y_cable for xcvrd daemon """ +import datetime import threading from sonic_py_common import daemon_base, logger @@ -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() @@ -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]) @@ -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 @@ -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))