Skip to content
Closed
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
12 changes: 7 additions & 5 deletions source/common/stats/symbol_table_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,13 @@ void SymbolTableImpl::addTokensToEncoding(const absl::string_view name, Encoding
Thread::LockGuard lock(lock_);
recent_lookups_.lookup(name);
for (auto& token : tokens) {
// TODO(jmarantz): consider using StatNameDynamicStorage for tokens with
// length below some threshold, say 4 bytes. It might be preferable not to
// reserve Symbols for every 3 digit number found (for example) in ipv4
// addresses.
symbols.push_back(toSymbol(token));
if (!token.empty()) {
// TODO(jmarantz): consider using StatNameDynamicStorage for tokens with
// length below some threshold, say 4 bytes. It might be preferable not to
// reserve Symbols for every 3 digit number found (for example) in ipv4
// addresses.
symbols.push_back(toSymbol(token));
}
}
}

Expand Down
19 changes: 13 additions & 6 deletions test/common/stats/symbol_table_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ TEST_F(StatNameTest, SerializeStrings) {
TEST_F(StatNameTest, AllocFree) { encodeDecode("hello.world"); }

TEST_F(StatNameTest, TestArbitrarySymbolRoundtrip) {
const std::vector<std::string> stat_names = {"", " ", " ", ",", "\t", "$", "%", "`", ".x"};
const std::vector<std::string> stat_names = {"", " ", " ", ",", "\t", "$", "%", "`"};
for (auto& stat_name : stat_names) {
EXPECT_EQ(stat_name, encodeDecode(stat_name));
}
Expand Down Expand Up @@ -207,11 +207,18 @@ TEST_F(StatNameTest, TestLongSequence) {
}

TEST_F(StatNameTest, TestUnusualDelimitersRoundtrip) {
const std::vector<std::string> stat_names = {".x", "..x", "...x", "foo", "foo.x",
".foo", ".foo.x", ".foo..x", "..foo.x", "..foo..x"};
for (auto& stat_name : stat_names) {
EXPECT_EQ(stat_name, encodeDecode(stat_name));
}
EXPECT_EQ("x", encodeDecode(".x"));
EXPECT_EQ("x", encodeDecode("..x"));
EXPECT_EQ("x", encodeDecode("...x"));
EXPECT_EQ("foo", encodeDecode("foo"));
EXPECT_EQ("foo.x", encodeDecode("foo.x"));
EXPECT_EQ("foo", encodeDecode(".foo"));
EXPECT_EQ("foo.x", encodeDecode(".foo.x"));
EXPECT_EQ("foo.x", encodeDecode(".foo..x"));
EXPECT_EQ("foo.x", encodeDecode("..foo.x"));
EXPECT_EQ("foo.x", encodeDecode("..foo..x"));
EXPECT_EQ("foo.x", encodeDecode("foo.x."));
EXPECT_EQ("foo.x", encodeDecode("foo.x.."));
}

TEST_F(StatNameTest, TestSuccessfulDoubleLookup) {
Expand Down