-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[deprecated] stats: do not canonicalize StatNames when storing in allocator, using a special syntax in tests for identifying dynamic stat names. #9774
Changes from 4 commits
dc52bf3
f404467
4ff0cc2
e0a2621
15b4c4d
cf20b1b
33487ad
2e12464
6b14938
bf85244
c96d934
2a2bc25
7f034e2
71add0f
e28e81a
3ca7717
ff93c40
ab0edd5
b0e0c32
c9129c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#include "common/stats/symbol_table_impl.h" | ||
|
||
#include <algorithm> | ||
#include <iostream> | ||
#include <memory> | ||
#include <unordered_map> | ||
#include <vector> | ||
|
@@ -41,19 +42,19 @@ uint64_t StatName::dataSize() const { | |
#ifndef ENVOY_CONFIG_COVERAGE | ||
void StatName::debugPrint() { | ||
if (size_and_data_ == nullptr) { | ||
ENVOY_LOG_MISC(info, "Null StatName"); | ||
std::cerr << "Null StatName" << std::endl; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer to use std::cerr so that I can call this from the debugger and see the results without restarting the binary with a differing logging level. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: should this possibly be wrapped in a different LOG macro? Don't feel strongly about this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can I leave a TODO here? the logging code is currently in flux from Jose's PR; no need to create a merge conflict. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure that's fine. |
||
} else { | ||
const uint64_t nbytes = dataSize(); | ||
std::string msg = absl::StrCat("dataSize=", nbytes, ":"); | ||
std::cerr << "dataSize=" << nbytes << ":"; | ||
for (uint64_t i = 0; i < nbytes; ++i) { | ||
absl::StrAppend(&msg, " ", static_cast<uint64_t>(data()[i])); | ||
std::cerr << " " << static_cast<uint64_t>(data()[i]); | ||
} | ||
const SymbolVec encoding = SymbolTableImpl::Encoding::decodeSymbols(data(), dataSize()); | ||
absl::StrAppend(&msg, ", numSymbols=", encoding.size(), ":"); | ||
std::cerr << ", numSymbols=" << encoding.size() << ":"; | ||
for (Symbol symbol : encoding) { | ||
absl::StrAppend(&msg, " ", symbol); | ||
std::cerr << " " << symbol; | ||
} | ||
ENVOY_LOG_MISC(info, "{}", msg); | ||
std::cerr << std::endl; | ||
} | ||
} | ||
#endif | ||
|
@@ -524,26 +525,24 @@ SymbolTable::StoragePtr SymbolTableImpl::join(const StatNameVec& stat_names) con | |
return mem_block.release(); | ||
} | ||
|
||
void SymbolTableImpl::populateList(const absl::string_view* names, uint32_t num_names, | ||
StatNameList& list) { | ||
void SymbolTableImpl::populateList(const StatName* names, uint32_t num_names, StatNameList& list) { | ||
RELEASE_ASSERT(num_names < 256, "Maximum number elements in a StatNameList exceeded"); | ||
|
||
// First encode all the names. | ||
size_t total_size_bytes = 1; /* one byte for holding the number of names */ | ||
|
||
STACK_ARRAY(encodings, Encoding, num_names); | ||
for (uint32_t i = 0; i < num_names; ++i) { | ||
Encoding& encoding = encodings[i]; | ||
addTokensToEncoding(names[i], encoding); | ||
total_size_bytes += encoding.bytesRequired(); | ||
total_size_bytes += names[i].size(); | ||
} | ||
|
||
// Now allocate the exact number of bytes required and move the encodings | ||
// into storage. | ||
MemBlockBuilder<uint8_t> mem_block(total_size_bytes); | ||
mem_block.appendOne(num_names); | ||
for (auto& encoding : encodings) { | ||
encoding.moveToMemBlock(mem_block); | ||
for (uint32_t i = 0; i < num_names; ++i) { | ||
const StatName stat_name = names[i]; | ||
incRefCount(stat_name); | ||
mem_block.appendData(absl::MakeSpan(stat_name.dataIncludingSize(), stat_name.size())); | ||
} | ||
|
||
// This assertion double-checks the arithmetic where we computed | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
#include "common/upstream/upstream_impl.h" | ||
|
||
#include "test/common/http/common.h" | ||
#include "test/common/stats/stat_test_utility.h" | ||
#include "test/mocks/http/mocks.h" | ||
#include "test/mocks/local_info/mocks.h" | ||
#include "test/mocks/network/mocks.h" | ||
|
@@ -3671,15 +3672,13 @@ TEST_F(RouterTest, AltStatName) { | |
EXPECT_EQ(1U, | ||
cm_.thread_local_cluster_.cluster_.info_->stats_store_.counter("canary.upstream_rq_200") | ||
.value()); | ||
EXPECT_EQ( | ||
1U, cm_.thread_local_cluster_.cluster_.info_->stats_store_.counter("alt_stat.upstream_rq_200") | ||
.value()); | ||
EXPECT_EQ(1U, cm_.thread_local_cluster_.cluster_.info_->stats_store_ | ||
.counter("alt_stat.zone.zone_name.to_az.upstream_rq_200") | ||
.value()); | ||
EXPECT_EQ(1U, cm_.thread_local_cluster_.cluster_.info_->stats_store_ | ||
.counter("alt_stat.zone.zone_name.to_az.upstream_rq_200") | ||
.value()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: in the existing code, this same exact stanza is repeated twice. I am not sure if the intent was to test a different stat-name in the second stanza. |
||
|
||
Stats::TestUtil::StatNames stat_names(cm_.thread_local_cluster_.cluster_.info_->stats_store_); | ||
Stats::StatName alt_stat = stat_names.dynamic("alt_stat"); | ||
EXPECT_EQ(1U, stat_names.counterValue({alt_stat, stat_names.symbolic("upstream_rq_200")})); | ||
EXPECT_EQ(1U, stat_names.counterValue( | ||
{alt_stat, stat_names.symbolic("zone.zone_name.to_az.upstream_rq_200")})); | ||
EXPECT_EQ(1U, stat_names.counterValue({alt_stat, stat_names.symbolic("upstream_rq_200")})); | ||
} | ||
|
||
TEST_F(RouterTest, Redirect) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI this is where the bug was, because we lost the structure of the original StatName, and which components of it were dynamic, which matters for hash-tables.