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 29 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.

@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).

FengPan-Frank
FengPan-Frank previously approved these changes Jan 7, 2025
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

xincunli-sonic
xincunli-sonic previously approved these changes Jan 7, 2025
@wajahatrazi
Copy link
Contributor

@qiluo-msft

This PR has been approved with the latest updates and modifications, kindly help merge this into the SONiC master.

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@zhangyanzhao
Copy link
Collaborator

Reviewers,
Can you please help to review this PR? Thanks.

click.echo(msg)
log_to_syslog(msg)
return True, None
except Exception as e:
Copy link
Contributor

Choose a reason for hiding this comment

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

Exception

Could you except more specific exception type?

the action and returns a tuple indicating whether the operation was successful.
Args:
status (str): The status to set for memory statistics ("true" or "false").
Copy link
Contributor

Choose a reason for hiding this comment

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

str

Is it better to use boolean type?

click.echo(success_msg)
log_to_syslog(success_msg)
click.echo("Reminder: Please run 'config save' to persist changes.")
except Exception as e:
Copy link
Contributor

Choose a reason for hiding this comment

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

Exception

Could you except more specific exception type?

self.config_db.connect()
syslog.syslog(syslog.LOG_INFO, "Successfully connected to SONiC config database")
return
except Exception as e:
Copy link
Contributor

Choose a reason for hiding this comment

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

Exception

Could you except more specific exception type?

syslog.syslog(syslog.LOG_WARNING,
f"Failed to connect to database"
f"(attempt {retries}/{max_retries}): {str(e)}")
time.sleep(retry_delay)
Copy link
Contributor

Choose a reason for hiding this comment

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

sleep

Could you make except block minimal size? Normally there is no complex retry logic or sleep inside this block.

except Exception as e:
error_msg = f"Error retrieving memory statistics configuration: {str(e)}"
syslog.syslog(syslog.LOG_ERR, error_msg)
raise RuntimeError(error_msg)
Copy link
Contributor

Choose a reason for hiding this comment

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

raise

lose the exception stack, which make debug harder.


self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
self.sock.settimeout(Config.SOCKET_TIMEOUT)
self.sock.connect(self.socket_path)
Copy link
Contributor

Choose a reason for hiding this comment

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

socket_path

What is the socket file permission by design? If allow RO user read and write, is it possible to be exploited by malicious RO user?

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.

10 participants