Skip to content

stats: skip symbolizing empty tokens#16239

Closed
jessicayuen wants to merge 1 commit intoenvoyproxy:mainfrom
jessicayuen:az-stat-fix
Closed

stats: skip symbolizing empty tokens#16239
jessicayuen wants to merge 1 commit intoenvoyproxy:mainfrom
jessicayuen:az-stat-fix

Conversation

@jessicayuen
Copy link
Copy Markdown
Member

Commit Message: Prevents stats with invalid metric formats, where there are consecutive .. from being emitted.
Additional Description: For example, drop stats with the format cluster.egress_dynamodb_iad.zone.1a..upstream_rq_2xx
Risk Level: Medium
Testing: Unit
Docs Changes: N/A
Release Notes: N/A
Platform Specific Features: N/A
Fixes #15541

Prevents stats with invalid metric formats, where there are
consecutive `..` from being emitted.

For example, `cluster.egress_dynamodb_iad.zone.1a..upstream_rq_2xx`

Fixes envoyproxy#15541

Signed-off-by: Jess Yuen <jyuen@lyft.com>
@jmarantz jmarantz self-assigned this Apr 29, 2021
Copy link
Copy Markdown
Contributor

@jmarantz jmarantz left a comment

Choose a reason for hiding this comment

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

Looks great! Just a couple of test nits.

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("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?

@jmarantz
Copy link
Copy Markdown
Contributor

Looks like test/common/stats:symbol_table_fuzz_test might need some tweaking as well for the new behavior.

@jmarantz
Copy link
Copy Markdown
Contributor

jmarantz commented May 3, 2021

/wait

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid metric format emitted for stats where to-zone/from-zone is empty

2 participants