Skip to content

Commit 9e2f739

Browse files
authored
Move time stamp to time stamp table in counter database to avoid frequently update the counter table (#1567)
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 Signed-off-by: Stephen Sun <[email protected]>
1 parent 80eb929 commit 9e2f739

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,
@@ -166,6 +178,8 @@ void testAddRemoveCounter(
166178

167179
std::vector<std::string> keys;
168180
countersTable.getKeys(keys);
181+
// We have a dedicated item for all timestamps for counters using bulk counter polling
182+
removeTimeStamp(keys, countersTable);
169183
EXPECT_EQ(keys.size(), object_ids.size());
170184

171185
for (size_t i = 0; i < object_ids.size(); i++)
@@ -185,6 +199,7 @@ void testAddRemoveCounter(
185199
EXPECT_EQ(fc.isEmpty(), true);
186200

187201
countersTable.getKeys(keys);
202+
removeTimeStamp(keys, countersTable);
188203
ASSERT_TRUE(keys.empty());
189204
}
190205

@@ -1708,6 +1723,7 @@ void testDashMeterAddRemoveCounter(
17081723

17091724
std::vector<std::string> keys;
17101725
countersTable.getKeys(keys);
1726+
removeTimeStamp(keys, countersTable);
17111727
ASSERT_TRUE(keys.empty());
17121728
}
17131729

0 commit comments

Comments
 (0)