Skip to content

Commit ec3a269

Browse files
authored
Fix ProcessStatsST column name issue and add test case to cover check (#281)
What I did Fix ProcessStatsST column issue Why I did it #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.
1 parent d231ed2 commit ec3a269

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

scripts/procdockerstatsd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,9 @@ class ProcDockerStats(daemon_base.DaemonBase):
193193
ppid = row.get('PPID')
194194
update_value['PPID'] = str(ppid)
195195
cpu = row.get('%CPU')
196-
update_value['CPU'] = str(cpu)
196+
update_value['%CPU'] = str(cpu)
197197
mem = round(row.get('%MEM'), 1)
198-
update_value['MEM'] = str(mem)
198+
update_value['%MEM'] = str(mem)
199199
stime = row.get('STIME')
200200
update_value['STIME'] = str(stime)
201201
tty = row.get('TT')

tests/procdockerstatsd_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def __init__(self, uids, pid, ppid, memory_percent, cpu_percent, create_time, cm
3636
def uids(self):
3737
return self._uids
3838

39+
@property
3940
def pid(self):
4041
return self._pid
4142

@@ -131,6 +132,11 @@ def test_update_processstats_command(self):
131132
mock_process_iter.assert_called_once()
132133
assert(len(pdstatsd.all_process_obj)== 3)
133134

135+
expected_fields = {'UID', 'PPID', '%CPU', '%MEM', 'STIME', 'TT', 'TIME', 'CMD'}
136+
for field in expected_fields:
137+
value = pdstatsd.state_db.get('STATE_DB', 'PROCESS_STATS|1234', field)
138+
assert value is not None, f"Missing expected field: {field}"
139+
134140
@patch('procdockerstatsd.getstatusoutput_noshell_pipe', return_value=([0, 0], ''))
135141
def test_update_fipsstats_command(self, mock_cmd):
136142
pdstatsd = procdockerstatsd.ProcDockerStats(procdockerstatsd.SYSLOG_IDENTIFIER)

0 commit comments

Comments
 (0)