Skip to content

Commit d1c9d1a

Browse files
[show][config] Add CLI support for configurable drop monitor feature (sonic-net#3756)
* [show][config] Add CLI support for configurable drop monitor feature * Implements commands to configure persistent drop monitor thresholds. * Adds support for setting monitoring window size, drop count threshold, and incident count threshold. * Includes `show dropcounters persistent_drops` command to display persistent drop alerts. * Provides `config dropcounters enable_monitor/disbale_monitor` command to enable/disable the feature. * Adds unit tests to cover the new CLI functionality. * Fix test failures and minor edits * Add more testcases for coverage * Update CLI to reflect changes in HLD
1 parent 7baa75b commit d1c9d1a

11 files changed

Lines changed: 545 additions & 29 deletions

File tree

config/main.py

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7671,6 +7671,11 @@ def dropcounters():
76717671
@click.option("-a", "--alias", type=str, help="Alias for this counter")
76727672
@click.option("-g", "--group", type=str, help="Group for this counter")
76737673
@click.option("-d", "--desc", type=str, help="Description for this counter")
7674+
@click.option("-w", "--window", type=int, help="Window size in seconds")
7675+
@click.option("-dct", "--drop-count-threshold", type=int,
7676+
help="Minimum threshold for drop counts to be classified as an incident")
7677+
@click.option('-ict', '--incident-count-threshold', type=int,
7678+
help="Minimum number of incidents to trigger a persistent drop alert")
76747679
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
76757680
@click.option('--namespace',
76767681
'-n',
@@ -7680,7 +7685,8 @@ def dropcounters():
76807685
show_default=True,
76817686
help='Namespace name or all',
76827687
callback=multi_asic_util.multi_asic_namespace_validation_callback)
7683-
def install(counter_name, alias, group, counter_type, desc, reasons, verbose, namespace):
7688+
def install(counter_name, alias, group, counter_type, desc, reasons, window,
7689+
incident_count_threshold, drop_count_threshold, verbose, namespace):
76847690
"""Install a new drop counter"""
76857691
command = ['dropconfig', '-c', 'install', '-n', str(counter_name), '-t', str(counter_type), '-r', str(reasons)]
76867692
if alias:
@@ -7691,10 +7697,76 @@ def install(counter_name, alias, group, counter_type, desc, reasons, verbose, na
76917697
command += ['-d', str(desc)]
76927698
if namespace:
76937699
command += ['-ns', str(namespace)]
7700+
if window:
7701+
command += ['-w', str(window)]
7702+
if drop_count_threshold:
7703+
command += ['-dct', str(drop_count_threshold)]
7704+
if incident_count_threshold:
7705+
command += ['-ict', str(incident_count_threshold)]
76947706

76957707
clicommon.run_command(command, display_cmd=verbose)
76967708

76977709

7710+
#
7711+
# 'enable drop monitor' subcommand ('config dropcounters enable_monitor')
7712+
#
7713+
@dropcounters.command()
7714+
@click.option("-c", "--counter-name", type=str, help="Name of the counter", default=None)
7715+
@click.option("-w", "--window", type=int, help="Window size in seconds")
7716+
@click.option("-dct", "--drop-count-threshold", type=int,
7717+
help="Minimum threshold for drop counts to be classified as an incident")
7718+
@click.option('-ict', '--incident-count-threshold', type=int,
7719+
help="Minimum number of incidents to trigger a persistent drop alert")
7720+
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
7721+
@click.option('--namespace',
7722+
'-n',
7723+
'namespace',
7724+
default=None,
7725+
type=str,
7726+
show_default=True,
7727+
help='Namespace name or all',
7728+
callback=multi_asic_util.multi_asic_namespace_validation_callback)
7729+
def enable_monitor(counter_name, window, incident_count_threshold, drop_count_threshold, verbose, namespace):
7730+
"""Enable drop monitor feature. If no counter is provided, global feature status is set to enabled."""
7731+
command = ['dropconfig', '-c', 'enable_drop_monitor']
7732+
if counter_name:
7733+
command += ['-n', str(counter_name)]
7734+
if window:
7735+
command += ['-w', str(window)]
7736+
if drop_count_threshold:
7737+
command += ['-dct', str(drop_count_threshold)]
7738+
if incident_count_threshold:
7739+
command += ['-ict', str(incident_count_threshold)]
7740+
if namespace:
7741+
command += ['-ns', str(namespace)]
7742+
7743+
clicommon.run_command(command, display_cmd=verbose)
7744+
7745+
7746+
#
7747+
# 'disable drop monitor' subcommand ('config dropcounters disable_monitor')
7748+
#
7749+
@dropcounters.command()
7750+
@click.option("-c", "--counter-name", type=str, help="Name of the counter", default=None)
7751+
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
7752+
@click.option('--namespace',
7753+
'-n',
7754+
'namespace',
7755+
default=None,
7756+
type=str,
7757+
show_default=True,
7758+
help='Namespace name or all',
7759+
callback=multi_asic_util.multi_asic_namespace_validation_callback)
7760+
def disable_monitor(counter_name, verbose, namespace):
7761+
"""Disable drop monitor feature. If no counter is provided, global feature status is set to disabled."""
7762+
command = ['dropconfig', '-c', 'disable_drop_monitor']
7763+
if counter_name:
7764+
command += ['-n', str(counter_name)]
7765+
if namespace:
7766+
command += ['-ns', str(namespace)]
7767+
clicommon.run_command(command, display_cmd=verbose)
7768+
7769+
76987770
#
76997771
# 'delete' subcommand ('config dropcounters delete')
77007772
#

0 commit comments

Comments
 (0)