From ac612ba0f9cbf7e6390a836b029a161c6a477a56 Mon Sep 17 00:00:00 2001 From: Sonic Build Admin Date: Thu, 3 Jul 2025 17:14:43 +0000 Subject: [PATCH] Fix ProcessStatsST column name issue and add test case to cover check What I did Fix ProcessStatsST column issue Why I did it https://github.com/sonic-net/sonic-host-services/pull/176, when did optimization of the state_db update into batch as dict, not realized "%" is missed, which is a regression issue. ![image](https://github.com/user-attachments/assets/b544ce77-9670-479b-822f-5b7ca74192ba) How I verified it Correct typo and added corresponding unit test to cover column name check. --- scripts/procdockerstatsd | 4 ++-- tests/procdockerstatsd_test.py | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/procdockerstatsd b/scripts/procdockerstatsd index 6f5a29c0..d679f6c3 100755 --- a/scripts/procdockerstatsd +++ b/scripts/procdockerstatsd @@ -193,9 +193,9 @@ class ProcDockerStats(daemon_base.DaemonBase): ppid = row.get('PPID') update_value['PPID'] = str(ppid) cpu = row.get('%CPU') - update_value['CPU'] = str(cpu) + update_value['%CPU'] = str(cpu) mem = round(row.get('%MEM'), 1) - update_value['MEM'] = str(mem) + update_value['%MEM'] = str(mem) stime = row.get('STIME') update_value['STIME'] = str(stime) tty = row.get('TT') diff --git a/tests/procdockerstatsd_test.py b/tests/procdockerstatsd_test.py index 4e39561f..41fd60ba 100644 --- a/tests/procdockerstatsd_test.py +++ b/tests/procdockerstatsd_test.py @@ -36,6 +36,7 @@ def __init__(self, uids, pid, ppid, memory_percent, cpu_percent, create_time, cm def uids(self): return self._uids + @property def pid(self): return self._pid @@ -131,6 +132,11 @@ def test_update_processstats_command(self): mock_process_iter.assert_called_once() assert(len(pdstatsd.all_process_obj)== 3) + expected_fields = {'UID', 'PPID', '%CPU', '%MEM', 'STIME', 'TT', 'TIME', 'CMD'} + for field in expected_fields: + value = pdstatsd.state_db.get('STATE_DB', 'PROCESS_STATS|1234', field) + assert value is not None, f"Missing expected field: {field}" + @patch('procdockerstatsd.getstatusoutput_noshell_pipe', return_value=([0, 0], '')) def test_update_fipsstats_command(self, mock_cmd): pdstatsd = procdockerstatsd.ProcDockerStats(procdockerstatsd.SYSLOG_IDENTIFIER)