-
Notifications
You must be signed in to change notification settings - Fork 656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory Statistics Config and Show Commands #3575
base: master
Are you sure you want to change the base?
Conversation
/azpw run Azure.sonic-utilities |
/azpw run |
/AzurePipelines run |
Azure Pipelines successfully started running 1 pipeline(s). |
@qiluo-msft @xincunli-sonic @zbud-msft @FengPan-Frank We have linked the code PRs. Please help review the feature. |
pls fix pretest analysis failure. thanks |
@FengPan-Frank I've resolved it, kindly review. |
seems python test is failed. could you double check? |
@FengPan-Frank there are some test cases failing but those are not related to memory statistics feature. The memory_statistics_test have passed, could you guide what should i do |
|
@FengPan-Frank I've made all the necessary changes and all the checks have passed. Kindly review. |
@qiluo-msft @xincunli-sonic pls help review this feature |
config/memory_statistics.py
Outdated
@@ -0,0 +1,114 @@ | |||
import click | |||
from swsscommon.swsscommon import ConfigDBConnector | |||
# from utilities_common.cli import AbbreviationGroup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If not needed, please remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thankyou for reviewing. I just removed it
@memory_statistics.command(name="enable", short_help="Enable the Memory Statistics feature") | ||
def memory_statistics_enable(): | ||
"""Enable the Memory Statistics feature""" | ||
db = ConfigDBConnector() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return # Exit gracefully on error | ||
|
||
try: | ||
db.mod_entry("MEMORY_STATISTICS", "memory_statistics", {"enabled": "true", "disabled": "false"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
@memory_statistics.command(name="disable", short_help="Disable the Memory Statistics feature") | ||
def memory_statistics_disable(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
click.echo("Unable to retrieve key 'memory_statistics' from MEMORY_STATISTICS table.", err=True) | ||
return False | ||
|
||
return True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
def get_memory_statistics_table(db): | ||
"""Get the MEMORY_STATISTICS table from the database.""" | ||
return db.get_table("MEMORY_STATISTICS") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
click.echo("Unable to retrieve 'MEMORY_STATISTICS' table from Config DB.", err=True) | ||
return False | ||
|
||
if "memory_statistics" not in memory_statistics_table: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
@memory_statistics.command(name="retention-period", short_help="Configure the retention period for Memory Statistics") | ||
@click.argument('retention_period', metavar='<retention_period>', required=True, type=int) | ||
def memory_statistics_retention_period(retention_period): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
@memory_statistics.command(name="sampling-interval", short_help="Configure the sampling interval for Memory Statistics") | ||
@click.argument('sampling_interval', metavar='<sampling_interval>', required=True, type=int) | ||
def memory_statistics_sampling_interval(sampling_interval): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
except Exception as e: | ||
click.echo(f"Error setting retention period: {str(e)}", err=True) | ||
|
||
click.echo("Save SONiC configuration using 'config save' to persist the changes.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
click.echo("Save SONiC configuration using 'config save' to persist the changes.")
After each command (e.g., enable, disable), there’s a reminder to run 'config save' to persist changes. It could be helpful to wrap these reminders with conditional checks to only show the message when a change is successful.
def check_memory_statistics_table_existence(memory_statistics_table): | ||
"""Checks whether the 'MEMORY_STATISTICS' table is configured in Config DB.""" | ||
if not memory_statistics_table: | ||
click.echo("Unable to retrieve 'MEMORY_STATISTICS' table from Config DB.", err=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@memory_statistics.command(name="retention-period", short_help="Configure the retention period for Memory Statistics") | ||
@click.argument('retention_period', metavar='<retention_period>', required=True, type=int) | ||
def memory_statistics_retention_period(retention_period): | ||
"""Set the retention period for Memory Statistics""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I did
Provided support for the configuration and show commands of memory statistics feature.
How I did it
I added a new config file config/memory_statistics.py for the configuration commands of memory statistics feature.
Added a show file show/memory_statistics.py for the show commands of memory statistics feature.
Added a test file tests/memory_statistics_test.py to test the config and show commands of memory statistics feature
How to verify it
Cli support for config and show file is available