Skip to content

Commit e46dd29

Browse files
[crm] Fix issue with continues EXCEEDED and CLEAR logs for ACL group/table counters (sonic-net#2463)
*Moved exceededLogCounter from CrmResourceEntry to CrmResourceCounter.
1 parent b61d24c commit e46dd29

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

orchagent/crmorch.cpp

+14-9
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,18 @@ void CrmOrch::handleSetCommand(const string& key, const vector<FieldValueTuple>&
340340
}
341341
else if (crmThreshTypeResMap.find(field) != crmThreshTypeResMap.end())
342342
{
343-
auto resourceType = crmThreshTypeResMap.at(field);
344343
auto thresholdType = crmThreshTypeMap.at(value);
344+
auto resourceType = crmThreshTypeResMap.at(field);
345+
auto &resource = m_resourcesMap.at(resourceType);
345346

346-
if (m_resourcesMap.at(resourceType).thresholdType != thresholdType)
347+
if (resource.thresholdType != thresholdType)
347348
{
348-
m_resourcesMap.at(resourceType).thresholdType = thresholdType;
349-
m_resourcesMap.at(resourceType).exceededLogCounter = 0;
349+
resource.thresholdType = thresholdType;
350+
351+
for (auto &cnt : resource.countersMap)
352+
{
353+
cnt.second.exceededLogCounter = 0;
354+
}
350355
}
351356
}
352357
else if (crmThreshLowResMap.find(field) != crmThreshLowResMap.end())
@@ -723,7 +728,7 @@ void CrmOrch::checkCrmThresholds()
723728
{
724729
auto &res = i.second;
725730

726-
for (const auto &j : i.second.countersMap)
731+
for (auto &j : i.second.countersMap)
727732
{
728733
auto &cnt = j.second;
729734
uint64_t utilization = 0;
@@ -762,7 +767,7 @@ void CrmOrch::checkCrmThresholds()
762767
throw runtime_error("Unknown threshold type for CRM resource");
763768
}
764769

765-
if ((utilization >= res.highThreshold) && (res.exceededLogCounter < CRM_EXCEEDED_MSG_MAX))
770+
if ((utilization >= res.highThreshold) && (cnt.exceededLogCounter < CRM_EXCEEDED_MSG_MAX))
766771
{
767772
event_params_t params = {
768773
{ "percent", to_string(percentageUtil) },
@@ -773,14 +778,14 @@ void CrmOrch::checkCrmThresholds()
773778
res.name.c_str(), threshType.c_str(), percentageUtil, cnt.usedCounter, cnt.availableCounter);
774779

775780
event_publish(g_events_handle, "chk_crm_threshold", &params);
776-
res.exceededLogCounter++;
781+
cnt.exceededLogCounter++;
777782
}
778-
else if ((utilization <= res.lowThreshold) && (res.exceededLogCounter > 0) && (res.highThreshold != res.lowThreshold))
783+
else if ((utilization <= res.lowThreshold) && (cnt.exceededLogCounter > 0) && (res.highThreshold != res.lowThreshold))
779784
{
780785
SWSS_LOG_WARN("%s THRESHOLD_CLEAR for %s %u%% Used count %u free count %u",
781786
res.name.c_str(), threshType.c_str(), percentageUtil, cnt.usedCounter, cnt.availableCounter);
782787

783-
res.exceededLogCounter = 0;
788+
cnt.exceededLogCounter = 0;
784789
}
785790
} // end of counters loop
786791
} // end of resources loop

orchagent/crmorch.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class CrmOrch : public Orch
7474
sai_object_id_t id = 0;
7575
uint32_t availableCounter = 0;
7676
uint32_t usedCounter = 0;
77+
uint32_t exceededLogCounter = 0;
7778
};
7879

7980
struct CrmResourceEntry
@@ -88,7 +89,6 @@ class CrmOrch : public Orch
8889

8990
std::map<std::string, CrmResourceCounter> countersMap;
9091

91-
uint32_t exceededLogCounter = 0;
9292
CrmResourceStatus resStatus = CrmResourceStatus::CRM_RES_SUPPORTED;
9393
};
9494

tests/test_crm.py

+16-6
Original file line numberDiff line numberDiff line change
@@ -697,12 +697,22 @@ def test_CrmAclGroup(self, dvs, testlog):
697697
entry_used_counter = getCrmCounterValue(dvs, 'ACL_STATS:INGRESS:PORT', 'crm_stats_acl_group_used')
698698
assert entry_used_counter == 3
699699

700-
# remove ACL table
701-
#tbl._del("test-aclv6")
702-
#time.sleep(2)
703-
#atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE_GROUP")
704-
#table_used_counter = getCrmCounterValue(dvs, 'ACL_STATS:INGRESS:PORT', 'crm_stats_acl_group_used')
705-
#assert table_used_counter == 0
700+
marker = dvs.add_log_marker()
701+
crm_update(dvs, "polling_interval", "1")
702+
crm_update(dvs, "acl_group_threshold_type", "used")
703+
crm_update(dvs, "acl_group_low_threshold", str(0))
704+
crm_update(dvs, "acl_group_high_threshold", str(2))
705+
706+
time.sleep(2)
707+
check_syslog(dvs, marker, "ACL_GROUP THRESHOLD_EXCEEDED for TH_USED", 1)
708+
check_syslog(dvs, marker, "ACL_GROUP THRESHOLD_CLEAR for TH_USED", 0)
709+
710+
tbl._del("test-aclv6")
711+
time.sleep(2)
712+
check_syslog(dvs, marker, "ACL_GROUP THRESHOLD_CLEAR for TH_USED", 1)
713+
714+
table_used_counter = getCrmCounterValue(dvs, 'ACL_STATS:INGRESS:PORT', 'crm_stats_acl_group_used')
715+
assert table_used_counter == 0
706716

707717
def test_CrmSnatEntry(self, dvs, testlog):
708718

0 commit comments

Comments
 (0)