Skip to content

Commit

Permalink
[show priority-group drop counters] Remove backup with cached PG drop…
Browse files Browse the repository at this point in the history
… counters after 'config reload' (sonic-net#1679)

- What I did
Explanation how show/clear counters works:

Suppose we got from SDK some count of dropped packets for priority group (№3) per interface (Ehernet4). (for example Ethernet4 PG-3 123 packets)
Stats can be shown via show priority-group drop counters
Then we run sonic-clear priority-group drop counters. This command will save data "Ethernet4 PG-3 123 packets" to backup. It saved in /tmp/dropstat-{user_id} folder
When we run show priority-group drop counters again, script will take data from SDK and data saved from backup. In backup it will find 123. In SDK it may still be number 123 for Ethernet4 (like in backup) or bigger (for example 126.)
Our sonic-clear priority-group drop counters command does not change anything in SDK. It just show difference beetwen SDK data and last saved data.
So if in SDK data is 123, show priority-group drop counters will show 0 (123 minus 123) - data is cleared
If in SDK data is bigger than saved 124, or higher show priority-group drop counters will show 1 (124 minus 123)
FIX
After config reload all counters drop counters data retrieved from SDK become cleared. All counters become zeros.
In this case show priority-group drop counters will show -123 ( 0 (from SDK) minus 123 (saved backup))
So we don't need backup after config reload

- How I did it
remove /tmp/dropstat-{user_id} folders with counters backup

Signed-off-by: Andriy Yurkiv <ayurkiv@nvidia.com>
  • Loading branch information
ayurkiv-nvda authored Jul 2, 2021
1 parent 24fe1ac commit 793b847
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,11 @@ def reload(db, filename, yes, load_sysinfo, no_service_restart, disable_arp_cach
if multi_asic.is_multi_asic():
num_cfg_file += num_asic

# Remove cached PG drop counters data
dropstat_dir_prefix = '/tmp/dropstat'
command = "rm -rf {}-*".format(dropstat_dir_prefix)
clicommon.run_command(command, display_cmd=True)

# If the user give the filename[s], extract the file names.
if filename is not None:
cfg_files = filename.split(',')
Expand Down
15 changes: 15 additions & 0 deletions tests/pgdropstat_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import show.main as show
import clear.main as clear
import config.main as config

from click.testing import CliRunner

Expand Down Expand Up @@ -62,6 +63,20 @@ def executor(self, clear_before_show):
assert result.exit_code == 0
assert result.output == show_output

def test_show_pg_drop_config_reload(self):
runner = CliRunner()
self.test_show_pg_drop_clear()

# simulate 'config reload' to provoke counters recalculation (remove backup from /tmp folder)
result = runner.invoke(config.config.commands["reload"], [ "--no_service_restart", "-y"])

print(result.exit_code)
print(result.output)

assert result.exit_code == 0

self.test_show_pg_drop_show()

@classmethod
def teardown_class(cls):
os.environ["PATH"] = os.pathsep.join(os.environ["PATH"].split(os.pathsep)[:-1])
Expand Down

0 comments on commit 793b847

Please sign in to comment.