From e108423c4673fe588e909d546171a23ad1278c49 Mon Sep 17 00:00:00 2001 From: Arham-Nasir <100487254+Arham-Nasir@users.noreply.github.com> Date: Wed, 4 Dec 2024 00:17:38 +0500 Subject: [PATCH] Add YANG Model and Configuration Support for Memory Statistics (#20354) This PR introduces a new YANG model for configuring memory statistics in SONiC, along with necessary updates to the configuration database and test cases. The following changes have been made: YANG Model: Created a new YANG module sonic-memory-statistics.yang for managing memory statistics configuration parameters, including: enabled: Boolean flag to enable or disable memory statistics collection. sampling_interval: Configurable time interval for sampling memory statistics. retention_period: Configurable retention period for memory statistics data. Configuration Database: Updated sample_config_db.json to include default values for the memory statistics configuration, ensuring seamless integration with the existing configuration management. Test Cases: Added comprehensive test cases in memory_statistics.json to validate the configuration parameters, including valid configurations and error scenarios for invalid sampling intervals and retention periods. These changes aim to enhance the monitoring capabilities of SONiC by providing a structured way to configure memory statistics, thereby improving overall system performance and resource management. --- src/sonic-yang-models/doc/Configuration.md | 20 ++++++++ src/sonic-yang-models/setup.py | 2 + .../tests/files/sample_config_db.json | 7 +++ .../tests/memory_statistics.json | 18 +++++++ .../tests_config/memory_statistics.json | 47 +++++++++++++++++++ .../yang-models/sonic-memory-statistics.yang | 47 +++++++++++++++++++ 6 files changed, 141 insertions(+) create mode 100644 src/sonic-yang-models/tests/yang_model_tests/tests/memory_statistics.json create mode 100644 src/sonic-yang-models/tests/yang_model_tests/tests_config/memory_statistics.json create mode 100644 src/sonic-yang-models/yang-models/sonic-memory-statistics.yang diff --git a/src/sonic-yang-models/doc/Configuration.md b/src/sonic-yang-models/doc/Configuration.md index 1f45b32a3e83..60a4222721f0 100644 --- a/src/sonic-yang-models/doc/Configuration.md +++ b/src/sonic-yang-models/doc/Configuration.md @@ -50,6 +50,7 @@ Table of Contents * [L2 Neighbors](#l2-neighbors) * [Loopback Interface](#loopback-interface) * [LOSSLESS_TRAFFIC_PATTERN](#LOSSLESS_TRAFFIC_PATTERN) + * [Memory Statistics](#memory-statistics) * [Management Interface](#management-interface) * [Management port](#management-port) * [Management VRF](#management-vrf) @@ -1482,6 +1483,25 @@ lossless traffic for dynamic buffer calculation } ``` +### Memory Statistics +The memory statistics configuration is stored in the **MEMORY_STATISTICS** table. This table is used by the memory statistics daemon to manage memory monitoring settings. The configuration allows enabling or disabling memory collection, specifying how frequently memory statistics are sampled, and defining how long the memory data is retained. + +``` +{ + "MEMORY_STATISTICS": { + "memory_statistics": { + "enabled": "false", + "sampling_interval": "5", + "retention_period": "15" + } + } +} + +``` +- **enabled**: Defines whether the memory statistics collection is active (true or false). +- **sampling_interval**: Interval between data collection. +- **retention_period**: Time to retain collected data. + ### Management Interface Management interfaces are defined in **MGMT_INTERFACE** table. Object diff --git a/src/sonic-yang-models/setup.py b/src/sonic-yang-models/setup.py index 04b652208ec7..60dba6c410aa 100644 --- a/src/sonic-yang-models/setup.py +++ b/src/sonic-yang-models/setup.py @@ -137,6 +137,7 @@ def run(self): './yang-models/sonic-kubernetes_master.yang', './yang-models/sonic-loopback-interface.yang', './yang-models/sonic-lossless-traffic-pattern.yang', + './yang-models/sonic-memory-statistics.yang', './yang-models/sonic-mgmt_interface.yang', './yang-models/sonic-mgmt_port.yang', './yang-models/sonic-mgmt_vrf.yang', @@ -242,6 +243,7 @@ def run(self): './cvlyang-models/sonic-kubernetes_master.yang', './cvlyang-models/sonic-loopback-interface.yang', './cvlyang-models/sonic-mgmt_interface.yang', + './cvlyang-models/sonic-memory-statistics.yang', './cvlyang-models/sonic-mgmt_port.yang', './cvlyang-models/sonic-mgmt_vrf.yang', './cvlyang-models/sonic-ntp.yang', diff --git a/src/sonic-yang-models/tests/files/sample_config_db.json b/src/sonic-yang-models/tests/files/sample_config_db.json index 5d22bc3f81cc..4c76237ddb46 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -2782,6 +2782,13 @@ "motd": "Some message of the day", "logout": "Some logout message" } + }, + "MEMORY_STATISTICS": { + "memory_statistics": { + "enabled": "false", + "sampling_interval": "5", + "retention_period": "15" + } } }, "SAMPLE_CONFIG_DB_UNKNOWN": { diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/memory_statistics.json b/src/sonic-yang-models/tests/yang_model_tests/tests/memory_statistics.json new file mode 100644 index 000000000000..e466e9cf92c6 --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/memory_statistics.json @@ -0,0 +1,18 @@ +{ + "MEMORY_STATISTICS_VALID_CONFIG": { + "desc": "Configuring memory statistics with valid values." + }, + "MEMORY_STATISTICS_WITH_INVALID_SAMPLING_INTERVAL": { + "desc": "Configuring memory statistics with an invalid sampling_interval ( out of acceptable range).", + "eStrKey": "Range", + "eStr": "3..15" + }, + "MEMORY_STATISTICS_WITH_INVALID_RETENTION_PERIOD": { + "desc": "Configuring memory statistics with an invalid retention_period (out of acceptable range).", + "eStrKey": "Range", + "eStr": "1..30" + }, + "MEMORY_STATISTICS_WITH_ENABLE_FEATURE": { + "desc": "Enabling memory statistics feature with valid values." + } +} \ No newline at end of file diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/memory_statistics.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/memory_statistics.json new file mode 100644 index 000000000000..22529187c958 --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/memory_statistics.json @@ -0,0 +1,47 @@ +{ + "MEMORY_STATISTICS_VALID_CONFIG": { + "sonic-memory-statistics:sonic-memory-statistics": { + "sonic-memory-statistics:MEMORY_STATISTICS": { + "memory_statistics":{ + "enabled": "false", + "sampling_interval": "5", + "retention_period": "15" + } + } + } + }, + "MEMORY_STATISTICS_WITH_INVALID_SAMPLING_INTERVAL": { + "sonic-memory-statistics:sonic-memory-statistics": { + "sonic-memory-statistics:MEMORY_STATISTICS": { + "memory_statistics":{ + "enabled": "true", + "sampling_interval": "45", + "retention_period": "20" + } + } + } + }, + "MEMORY_STATISTICS_WITH_INVALID_RETENTION_PERIOD": { + "sonic-memory-statistics:sonic-memory-statistics": { + "sonic-memory-statistics:MEMORY_STATISTICS": { + "memory_statistics":{ + "enabled": "true", + "sampling_interval": "5", + "retention_period": "45" + } + } + } + }, + "MEMORY_STATISTICS_WITH_ENABLE_FEATURE": { + "sonic-memory-statistics:sonic-memory-statistics": { + "sonic-memory-statistics:MEMORY_STATISTICS": { + "memory_statistics":{ + "enabled": "true", + "sampling_interval": "5", + "retention_period": "30" + } + } + } + } + +} \ No newline at end of file diff --git a/src/sonic-yang-models/yang-models/sonic-memory-statistics.yang b/src/sonic-yang-models/yang-models/sonic-memory-statistics.yang new file mode 100644 index 000000000000..f69344db53b5 --- /dev/null +++ b/src/sonic-yang-models/yang-models/sonic-memory-statistics.yang @@ -0,0 +1,47 @@ +module sonic-memory-statistics { + yang-version 1.1; + + namespace "http://github.com/sonic-net/sonic-memory-statistics"; + prefix memstats; + + import sonic-types { + prefix stypes; + } + + description "YANG module for configuring memory statistics in SONiC-based OS."; + + revision 2024-07-22 { + description "First Revision"; + } + + container sonic-memory-statistics { + container MEMORY_STATISTICS { + description "Memory statistics configuration parameters."; + container memory_statistics{ + leaf enabled { + type boolean; + default false; + description "Flag to enable or disable memory statistics collection. If set to false, the memory statistics collection will stop."; + } + + leaf sampling_interval { + type uint8 { + range "3..15"; + } + units "minutes"; + default 5; + description "Time interval in minutes for sampling memory statistics. Valid range, is between 3 minutes to 30 minutes."; + } + + leaf retention_period { + type uint8 { + range "1..30"; + } + units "days"; + default 15; + description "Retention period for memory statistics data, defined in days. Valid range is from 1 day to 30 days."; + } + } + } + } +} \ No newline at end of file