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
13 changes: 13 additions & 0 deletions test/common/http/codes_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,19 @@ TEST_F(CodeUtilityTest, PerZoneStats) {
EXPECT_EQ(1U, cluster_scope_.counter("prefix.zone.from_az.to_az.upstream_rq_2xx").value());
}

TEST_F(CodeUtilityTest, EmptyPerZoneStats) {
// Empty from-zone / to-zone stats should not be emitted.
addResponse(200, false, false, "", "", "from_az");
EXPECT_EQ(0U, cluster_scope_.counter("prefix.zone.from_az..upstream_rq_completed").value());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of allocating the counter and checking that it's zero, can you use TestStore::findCounterByString(...) here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, a couple of things occurred to me about this test that might require more tweaks:

  • I think you should pair a negative test ("can't find stat, or stat is 0") with a positive test to be sure that stats are recorded where expected
  • Depending on the implementation of the string lookup method, you might actually get a counter returned for this when you don't expect it, because with your change to symbol_table_impl.cc the name will be corrected and then the stat found. So a better test might be to do the name lookup, expect that there's a counter, but get the counter's name back and test it against the expected string. I'm a little surprised that you don't find a match with counter() which will convert the string to a StatName, eliding the empty segment. So I think your test might not be spelling the stat-name correctly, even ignoring the ... In the new method, it will use a string-map maintained test/common/stats/stat_test_utility.cc and I'd expect the lookup to fail.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test doesn't really do what's intended due to this in codes.cc:

if (!info.from_zone_.empty() && !info.to_zone_.empty()) {

So in #16675 I am just reverting this file.

EXPECT_EQ(0U, cluster_scope_.counter("prefix.zone.from_az..upstream_rq_200").value());
EXPECT_EQ(0U, cluster_scope_.counter("prefix.zone.from_az..upstream_rq_2xx").value());

addResponse(200, false, false, "", "", "", "to_az");
EXPECT_EQ(0U, cluster_scope_.counter("prefix.zone..to_az.upstream_rq_completed").value());
EXPECT_EQ(0U, cluster_scope_.counter("prefix.zone..to_az.upstream_rq_200").value());
EXPECT_EQ(0U, cluster_scope_.counter("prefix.zone..to_az.upstream_rq_2xx").value());
}

TEST_F(CodeUtilityTest, ResponseTimingTest) {
Stats::MockStore global_store;
Stats::MockStore cluster_scope;
Expand Down
17 changes: 11 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,16 @@ 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"));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why these weren't added in the first place, but can you add some tests with trailing dots also?

}

TEST_F(StatNameTest, TestSuccessfulDoubleLookup) {
Expand Down