-
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 all 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 |
---|---|---|
|
@@ -21,8 +21,8 @@ namespace Stats { | |
*/ | ||
class MetricHelper { | ||
public: | ||
MetricHelper(absl::string_view name, absl::string_view tag_extracted_name, | ||
const std::vector<Tag>& tags, SymbolTable& symbol_table); | ||
MetricHelper(StatName name, absl::string_view tag_extracted_name, const std::vector<Tag>& tags, | ||
SymbolTable& symbol_table); | ||
~MetricHelper(); | ||
|
||
StatName statName() const; | ||
|
@@ -55,21 +55,15 @@ class MetricHelper { | |
*/ | ||
template <class BaseClass> class MetricImpl : public BaseClass { | ||
public: | ||
MetricImpl(absl::string_view name, absl::string_view tag_extracted_name, | ||
const std::vector<Tag>& tags, SymbolTable& symbol_table) | ||
: helper_(name, tag_extracted_name, tags, symbol_table) {} | ||
|
||
// Alternate API to take the name as a StatName, which is needed at most call-sites. | ||
// TODO(jmarantz): refactor impl to either be able to pass string_view at call-sites | ||
// always, or to make it more efficient to populate a StatNameList with a mixture of | ||
// StatName and string_view. | ||
// TODO(jmarantz): Use StatName for tag_extracted_name. | ||
MetricImpl(StatName name, absl::string_view tag_extracted_name, const std::vector<Tag>& tags, | ||
SymbolTable& symbol_table) | ||
: MetricImpl(symbol_table.toString(name), tag_extracted_name, tags, symbol_table) {} | ||
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. 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. |
||
: helper_(name, tag_extracted_name, tags, symbol_table) {} | ||
|
||
// Empty construction of a MetricImpl; used for null stats. | ||
explicit MetricImpl(SymbolTable& symbol_table) | ||
: MetricImpl("", "", std::vector<Tag>(), symbol_table) {} | ||
|
||
: MetricImpl(StatNameManagedStorage("", symbol_table).statName(), "", std::vector<Tag>(), | ||
symbol_table) {} | ||
std::vector<Tag> tags() const override { return helper_.tags(constSymbolTable()); } | ||
StatName statName() const override { return helper_.statName(); } | ||
StatName tagExtractedStatName() const override { return helper_.tagExtractedStatName(); } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
#include "common/stats/symbol_table_impl.h" | ||
|
||
#include <algorithm> | ||
#include <iostream> | ||
#include <memory> | ||
#include <unordered_map> | ||
#include <vector> | ||
|
||
#include "common/common/assert.h" | ||
|
@@ -40,20 +40,23 @@ uint64_t StatName::dataSize() const { | |
|
||
#ifndef ENVOY_CONFIG_COVERAGE | ||
void StatName::debugPrint() { | ||
// TODO(jmarantz): capture this functionality (always prints regardless of | ||
// loglevel) in an ENVOY_LOG macro variant or similar, perhaps | ||
// ENVOY_LOG_MISC(stderr, ...); | ||
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 +527,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 */ | ||
|
||
absl::FixedArray<Encoding> encodings(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.sizeAndData(), 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,11 @@ 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::MixedStatNames stat_names( | ||
cm_.thread_local_cluster_.cluster_.info_->stats_store_); | ||
EXPECT_EQ(1U, stat_names.counterValue("`alt_stat`.upstream_rq_200")); | ||
EXPECT_EQ(1U, stat_names.counterValue("`alt_stat`.zone.zone_name.to_az.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.
nit: update doc comments here and below
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.
done