Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion syncd/FlexCounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1311,11 +1311,18 @@ class CounterContext : public BaseCounterContext
{
values.emplace_back(serializeStat(ctx.counter_ids[j]), std::to_string(ctx.counters[i * ctx.counter_ids.size() + j]));
}
values.emplace_back(m_instanceId + "_time_stamp", std::to_string(time_stamp));

countersTable.set(sai_serialize_object_id(vid), values, "");
values.clear();
}

// First generate the key, then replace spaces with underscores to avoid issues when Lua plugins handle the timestamp
std::string timestamp_key = m_instanceId + "_" + m_name + "_time_stamp";
std::replace(timestamp_key.begin(), timestamp_key.end(), ' ', '_');

values.emplace_back(timestamp_key, std::to_string(time_stamp));
countersTable.set("TIME_STAMP", values, "");

SWSS_LOG_DEBUG("After pushing db %s %s %s", m_instanceId.c_str(), m_name.c_str(), ctx.name.c_str());
}

Expand Down
16 changes: 16 additions & 0 deletions unittest/syncd/TestFlexCounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ std::vector<sai_object_id_t> generateOids(
return object_ids;
}

void removeTimeStamp(std::vector<std::string>& keys, swss::Table& countersTable)
{
SWSS_LOG_ENTER();

auto it = std::find(keys.begin(), keys.end(), "TIME_STAMP");
if (it != keys.end())
{
countersTable.del("TIME_STAMP");
keys.erase(it);
}
}

void testAddRemoveCounter(
unsigned int numOid,
sai_object_type_t object_type,
Expand Down Expand Up @@ -166,6 +178,8 @@ void testAddRemoveCounter(

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

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

countersTable.getKeys(keys);
removeTimeStamp(keys, countersTable);
ASSERT_TRUE(keys.empty());
}

Expand Down Expand Up @@ -1708,6 +1723,7 @@ void testDashMeterAddRemoveCounter(

std::vector<std::string> keys;
countersTable.getKeys(keys);
removeTimeStamp(keys, countersTable);
ASSERT_TRUE(keys.empty());
}

Expand Down
Loading