Skip to content

Commit 8c8a2b6

Browse files
committed
Move time stamp to time stamp table in counter database to avoid frequently update the counter table
Move the timestamp out of the COUNTER table to avoid updating the table too frequently and overwhelming the telemetry system. Fixes sonic-net/sonic-buildimage#22201
1 parent 99a9585 commit 8c8a2b6

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

syncd/FlexCounter.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -1311,11 +1311,18 @@ class CounterContext : public BaseCounterContext
13111311
{
13121312
values.emplace_back(serializeStat(ctx.counter_ids[j]), std::to_string(ctx.counters[i * ctx.counter_ids.size() + j]));
13131313
}
1314-
values.emplace_back(m_instanceId + "_time_stamp", std::to_string(time_stamp));
1314+
13151315
countersTable.set(sai_serialize_object_id(vid), values, "");
13161316
values.clear();
13171317
}
13181318

1319+
// First generate the key, then replace spaces with underscores to avoid issues when Lua plugins handle the timestamp
1320+
std::string timestamp_key = m_instanceId + "_" + m_name + "_time_stamp";
1321+
std::replace(timestamp_key.begin(), timestamp_key.end(), ' ', '_');
1322+
1323+
values.emplace_back(timestamp_key, std::to_string(time_stamp));
1324+
countersTable.set("TIME_STAMP", values, "");
1325+
13191326
SWSS_LOG_DEBUG("After pushing db %s %s %s", m_instanceId.c_str(), m_name.c_str(), ctx.name.c_str());
13201327
}
13211328

unittest/syncd/TestFlexCounter.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ std::vector<sai_object_id_t> generateOids(
7777
return object_ids;
7878
}
7979

80+
void removeTimeStamp(std::vector<std::string>& keys, swss::Table& countersTable)
81+
{
82+
SWSS_LOG_ENTER();
83+
84+
auto it = std::find(keys.begin(), keys.end(), "TIME_STAMP");
85+
if (it != keys.end())
86+
{
87+
countersTable.del("TIME_STAMP");
88+
keys.erase(it);
89+
}
90+
}
91+
8092
void testAddRemoveCounter(
8193
unsigned int numOid,
8294
sai_object_type_t object_type,
@@ -177,6 +189,8 @@ void testAddRemoveCounter(
177189

178190
std::vector<std::string> keys;
179191
countersTable.getKeys(keys);
192+
// We have a dedicated item for all timestamps for counters using bulk counter polling
193+
removeTimeStamp(keys, countersTable);
180194
EXPECT_EQ(keys.size(), object_ids.size());
181195

182196
for (size_t i = 0; i < object_ids.size(); i++)
@@ -196,6 +210,7 @@ void testAddRemoveCounter(
196210
EXPECT_EQ(fc.isEmpty(), true);
197211

198212
countersTable.getKeys(keys);
213+
removeTimeStamp(keys, countersTable);
199214
ASSERT_TRUE(keys.empty());
200215
}
201216

@@ -1719,6 +1734,7 @@ void testDashMeterAddRemoveCounter(
17191734

17201735
std::vector<std::string> keys;
17211736
countersTable.getKeys(keys);
1737+
removeTimeStamp(keys, countersTable);
17221738
ASSERT_TRUE(keys.empty());
17231739
}
17241740

0 commit comments

Comments
 (0)