Skip to content
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

Open
wants to merge 28 commits into
base: master
Choose a base branch
from

Conversation

kanza-latif
Copy link

@kanza-latif kanza-latif commented Oct 14, 2024

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

@kanza-latif kanza-latif changed the title added show and config commands Memory Statistics Config and Show Commands Oct 16, 2024
@ridahanif96
Copy link
Contributor

/azpw run Azure.sonic-utilities

@kanza-latif
Copy link
Author

/azpw run

@mssonicbld
Copy link
Collaborator

/AzurePipelines run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@ridahanif96
Copy link
Contributor

@qiluo-msft @xincunli-sonic @zbud-msft @FengPan-Frank We have linked the code PRs. Please help review the feature.
Target 202411, please help with expedite review.

@FengPan-Frank
Copy link
Contributor

pls fix pretest analysis failure. thanks

@kanza-latif
Copy link
Author

@FengPan-Frank I've resolved it, kindly review.

@FengPan-Frank
Copy link
Contributor

@FengPan-Frank I've resolved it, kindly review.

seems python test is failed. could you double check?

@kanza-latif
Copy link
Author

@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
Copy link
Contributor

@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
you can create dummy PR for verify if it's current pipeline issue or your code issue.

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

echo

for all click.echo, suggest to add corresponding message to syslog?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added them to syslog as well

@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"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"""Set the retention period for Memory Statistics"""

Can we add an explaining the expected input and any limitations, like valid range or unit. Same as sampling_interval.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have now added the explanations as well. KIndly help review again

@kanza-latif
Copy link
Author

@FengPan-Frank @xincunli-sonic I have incorporated the changes you suggested. Kindly help review it

@kanza-latif
Copy link
Author

@FengPan-Frank @xincunli-sonic please review this feature again

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Pull request contains merge conflicts.

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Arham-Nasir
Copy link

Hi @xincunli-sonic , all suggested changes have been addressed. kindly review and help merge this PR. Thank you!

@Arham-Nasir
Copy link

Hi @FengPan-Frank , kindly review and help merge this PR. Thank you!

syslog.syslog(level, message)


def get_db_connection():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like every command we are creating a new connection to config db. Perhaps we can create a class variable and create only one connection and reuse?

Copy link

@Arham-Nasir Arham-Nasir Dec 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @zbud-msft ,Thanks for the feedback. I have implemented a Singleton pattern for the database connection, ensuring a single connection is reused across all commands.

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

level (int): The syslog log level.
"""
syslog.openlog("memory_statistics", syslog.LOG_PID | syslog.LOG_CONS, syslog.LOG_USER)
syslog.syslog(level, message)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syslog

Suggest to close the log after msg being logged.

def log_message(...):
try:
syslog.openlog(...)
syslog.syslog(...)
finally:
syslog.closelog()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the suggestion. I have added a try-finally block to ensure syslog.closelog() is always called after logging the message. Please let me know if there is anything else you’d like me to adjust.

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

@FengPan-Frank FengPan-Frank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants