diff --git a/source/common/stats/symbol_table_impl.cc b/source/common/stats/symbol_table_impl.cc index 22529eadab7e..a31a6bbfc3de 100644 --- a/source/common/stats/symbol_table_impl.cc +++ b/source/common/stats/symbol_table_impl.cc @@ -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)); + } } } diff --git a/test/common/stats/symbol_table_impl_test.cc b/test/common/stats/symbol_table_impl_test.cc index 7fd540803a15..19522921d90c 100644 --- a/test/common/stats/symbol_table_impl_test.cc +++ b/test/common/stats/symbol_table_impl_test.cc @@ -94,7 +94,7 @@ TEST_F(StatNameTest, SerializeStrings) { TEST_F(StatNameTest, AllocFree) { encodeDecode("hello.world"); } TEST_F(StatNameTest, TestArbitrarySymbolRoundtrip) { - const std::vector stat_names = {"", " ", " ", ",", "\t", "$", "%", "`", ".x"}; + const std::vector stat_names = {"", " ", " ", ",", "\t", "$", "%", "`"}; for (auto& stat_name : stat_names) { EXPECT_EQ(stat_name, encodeDecode(stat_name)); } @@ -207,11 +207,18 @@ TEST_F(StatNameTest, TestLongSequence) { } TEST_F(StatNameTest, TestUnusualDelimitersRoundtrip) { - const std::vector 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) {