Skip to content

Commit

Permalink
[crm] Fix issue with continues EXCEEDED and CLEAR logs for ACL group/…
Browse files Browse the repository at this point in the history
…table counters (sonic-net#2463)

*Moved exceededLogCounter from CrmResourceEntry to CrmResourceCounter.
  • Loading branch information
volodymyrsamotiy authored Sep 30, 2022
1 parent b61d24c commit e46dd29
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
23 changes: 14 additions & 9 deletions orchagent/crmorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,18 @@ void CrmOrch::handleSetCommand(const string& key, const vector<FieldValueTuple>&
}
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())
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) },
Expand All @@ -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", &params);
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
Expand Down
2 changes: 1 addition & 1 deletion orchagent/crmorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -88,7 +89,6 @@ class CrmOrch : public Orch

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

uint32_t exceededLogCounter = 0;
CrmResourceStatus resStatus = CrmResourceStatus::CRM_RES_SUPPORTED;
};

Expand Down
22 changes: 16 additions & 6 deletions tests/test_crm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down

0 comments on commit e46dd29

Please sign in to comment.