From e46dd294092f9267d9352fdc1e4889d8db2a9e6a Mon Sep 17 00:00:00 2001 From: Volodymyr Samotiy Date: Fri, 30 Sep 2022 20:52:31 +0300 Subject: [PATCH] [crm] Fix issue with continues EXCEEDED and CLEAR logs for ACL group/table counters (#2463) *Moved exceededLogCounter from CrmResourceEntry to CrmResourceCounter. --- orchagent/crmorch.cpp | 23 ++++++++++++++--------- orchagent/crmorch.h | 2 +- tests/test_crm.py | 22 ++++++++++++++++------ 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/orchagent/crmorch.cpp b/orchagent/crmorch.cpp index 54e2df78c7e6..f02bbd68f26d 100644 --- a/orchagent/crmorch.cpp +++ b/orchagent/crmorch.cpp @@ -340,13 +340,18 @@ void CrmOrch::handleSetCommand(const string& key, const vector& } else if (crmThreshTypeResMap.find(field) != crmThreshTypeResMap.end()) { - auto resourceType = crmThreshTypeResMap.at(field); auto thresholdType = crmThreshTypeMap.at(value); + auto resourceType = crmThreshTypeResMap.at(field); + auto &resource = m_resourcesMap.at(resourceType); - if (m_resourcesMap.at(resourceType).thresholdType != thresholdType) + if (resource.thresholdType != thresholdType) { - m_resourcesMap.at(resourceType).thresholdType = thresholdType; - m_resourcesMap.at(resourceType).exceededLogCounter = 0; + resource.thresholdType = thresholdType; + + for (auto &cnt : resource.countersMap) + { + cnt.second.exceededLogCounter = 0; + } } } else if (crmThreshLowResMap.find(field) != crmThreshLowResMap.end()) @@ -723,7 +728,7 @@ void CrmOrch::checkCrmThresholds() { auto &res = i.second; - for (const auto &j : i.second.countersMap) + for (auto &j : i.second.countersMap) { auto &cnt = j.second; uint64_t utilization = 0; @@ -762,7 +767,7 @@ void CrmOrch::checkCrmThresholds() throw runtime_error("Unknown threshold type for CRM resource"); } - if ((utilization >= res.highThreshold) && (res.exceededLogCounter < CRM_EXCEEDED_MSG_MAX)) + if ((utilization >= res.highThreshold) && (cnt.exceededLogCounter < CRM_EXCEEDED_MSG_MAX)) { event_params_t params = { { "percent", to_string(percentageUtil) }, @@ -773,14 +778,14 @@ void CrmOrch::checkCrmThresholds() res.name.c_str(), threshType.c_str(), percentageUtil, cnt.usedCounter, cnt.availableCounter); event_publish(g_events_handle, "chk_crm_threshold", ¶ms); - res.exceededLogCounter++; + cnt.exceededLogCounter++; } - else if ((utilization <= res.lowThreshold) && (res.exceededLogCounter > 0) && (res.highThreshold != res.lowThreshold)) + else if ((utilization <= res.lowThreshold) && (cnt.exceededLogCounter > 0) && (res.highThreshold != res.lowThreshold)) { SWSS_LOG_WARN("%s THRESHOLD_CLEAR for %s %u%% Used count %u free count %u", res.name.c_str(), threshType.c_str(), percentageUtil, cnt.usedCounter, cnt.availableCounter); - res.exceededLogCounter = 0; + cnt.exceededLogCounter = 0; } } // end of counters loop } // end of resources loop diff --git a/orchagent/crmorch.h b/orchagent/crmorch.h index a9c32a83bde7..b57d4b2947c9 100644 --- a/orchagent/crmorch.h +++ b/orchagent/crmorch.h @@ -74,6 +74,7 @@ class CrmOrch : public Orch sai_object_id_t id = 0; uint32_t availableCounter = 0; uint32_t usedCounter = 0; + uint32_t exceededLogCounter = 0; }; struct CrmResourceEntry @@ -88,7 +89,6 @@ class CrmOrch : public Orch std::map countersMap; - uint32_t exceededLogCounter = 0; CrmResourceStatus resStatus = CrmResourceStatus::CRM_RES_SUPPORTED; }; diff --git a/tests/test_crm.py b/tests/test_crm.py index 31d0b57ae569..bee145c34feb 100644 --- a/tests/test_crm.py +++ b/tests/test_crm.py @@ -697,12 +697,22 @@ def test_CrmAclGroup(self, dvs, testlog): entry_used_counter = getCrmCounterValue(dvs, 'ACL_STATS:INGRESS:PORT', 'crm_stats_acl_group_used') assert entry_used_counter == 3 - # remove ACL table - #tbl._del("test-aclv6") - #time.sleep(2) - #atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE_GROUP") - #table_used_counter = getCrmCounterValue(dvs, 'ACL_STATS:INGRESS:PORT', 'crm_stats_acl_group_used') - #assert table_used_counter == 0 + marker = dvs.add_log_marker() + crm_update(dvs, "polling_interval", "1") + crm_update(dvs, "acl_group_threshold_type", "used") + crm_update(dvs, "acl_group_low_threshold", str(0)) + crm_update(dvs, "acl_group_high_threshold", str(2)) + + time.sleep(2) + check_syslog(dvs, marker, "ACL_GROUP THRESHOLD_EXCEEDED for TH_USED", 1) + check_syslog(dvs, marker, "ACL_GROUP THRESHOLD_CLEAR for TH_USED", 0) + + tbl._del("test-aclv6") + time.sleep(2) + check_syslog(dvs, marker, "ACL_GROUP THRESHOLD_CLEAR for TH_USED", 1) + + table_used_counter = getCrmCounterValue(dvs, 'ACL_STATS:INGRESS:PORT', 'crm_stats_acl_group_used') + assert table_used_counter == 0 def test_CrmSnatEntry(self, dvs, testlog):