diff --git a/include/envoy/stats/allocator.h b/include/envoy/stats/allocator.h index 5ab8dc2cdcfc8..681befa5f3b3b 100644 --- a/include/envoy/stats/allocator.h +++ b/include/envoy/stats/allocator.h @@ -35,7 +35,7 @@ class Allocator { * @return CounterSharedPtr a counter, or nullptr if allocation failed, in which case * tag_extracted_name and tags are not moved. */ - virtual CounterSharedPtr makeCounter(StatName name, absl::string_view tag_extracted_name, + virtual CounterSharedPtr makeCounter(StatName name, StatName tag_extracted_name, const StatNameTagVector& stat_name_tags) PURE; /** @@ -45,7 +45,7 @@ class Allocator { * @return GaugeSharedPtr a gauge, or nullptr if allocation failed, in which case * tag_extracted_name and tags are not moved. */ - virtual GaugeSharedPtr makeGauge(StatName name, absl::string_view tag_extracted_name, + virtual GaugeSharedPtr makeGauge(StatName name, StatName tag_extracted_name, const StatNameTagVector& stat_name_tags, Gauge::ImportMode import_mode) PURE; diff --git a/source/common/stats/allocator_impl.cc b/source/common/stats/allocator_impl.cc index c83aee07ed5d7..3286aeb7834ef 100644 --- a/source/common/stats/allocator_impl.cc +++ b/source/common/stats/allocator_impl.cc @@ -49,7 +49,7 @@ void AllocatorImpl::debugPrint() { // wasted in the alignment padding next to flags_. template class StatsSharedImpl : public MetricImpl { public: - StatsSharedImpl(StatName name, AllocatorImpl& alloc, absl::string_view tag_extracted_name, + StatsSharedImpl(StatName name, AllocatorImpl& alloc, StatName tag_extracted_name, const StatNameTagVector& stat_name_tags) : MetricImpl(name, tag_extracted_name, stat_name_tags, alloc.symbolTable()), alloc_(alloc) {} @@ -121,7 +121,7 @@ template class StatsSharedImpl : public MetricImpl class CounterImpl : public StatsSharedImpl { public: - CounterImpl(StatName name, AllocatorImpl& alloc, absl::string_view tag_extracted_name, + CounterImpl(StatName name, AllocatorImpl& alloc, StatName tag_extracted_name, const StatNameTagVector& stat_name_tags) : StatsSharedImpl(name, alloc, tag_extracted_name, stat_name_tags) {} @@ -149,7 +149,7 @@ class CounterImpl : public StatsSharedImpl { class GaugeImpl : public StatsSharedImpl { public: - GaugeImpl(StatName name, AllocatorImpl& alloc, absl::string_view tag_extracted_name, + GaugeImpl(StatName name, AllocatorImpl& alloc, StatName tag_extracted_name, const StatNameTagVector& stat_name_tags, ImportMode import_mode) : StatsSharedImpl(name, alloc, tag_extracted_name, stat_name_tags) { switch (import_mode) { @@ -228,7 +228,7 @@ class GaugeImpl : public StatsSharedImpl { } }; -CounterSharedPtr AllocatorImpl::makeCounter(StatName name, absl::string_view tag_extracted_name, +CounterSharedPtr AllocatorImpl::makeCounter(StatName name, StatName tag_extracted_name, const StatNameTagVector& stat_name_tags) { Thread::LockGuard lock(mutex_); ASSERT(gauges_.find(name) == gauges_.end()); @@ -241,7 +241,7 @@ CounterSharedPtr AllocatorImpl::makeCounter(StatName name, absl::string_view tag return counter; } -GaugeSharedPtr AllocatorImpl::makeGauge(StatName name, absl::string_view tag_extracted_name, +GaugeSharedPtr AllocatorImpl::makeGauge(StatName name, StatName tag_extracted_name, const StatNameTagVector& stat_name_tags, Gauge::ImportMode import_mode) { Thread::LockGuard lock(mutex_); diff --git a/source/common/stats/allocator_impl.h b/source/common/stats/allocator_impl.h index f6803156954c2..2c4ba307f797f 100644 --- a/source/common/stats/allocator_impl.h +++ b/source/common/stats/allocator_impl.h @@ -23,9 +23,9 @@ class AllocatorImpl : public Allocator { ~AllocatorImpl() override; // Allocator - CounterSharedPtr makeCounter(StatName name, absl::string_view tag_extracted_name, + CounterSharedPtr makeCounter(StatName name, StatName tag_extracted_name, const StatNameTagVector& stat_name_tags) override; - GaugeSharedPtr makeGauge(StatName name, absl::string_view tag_extracted_name, + GaugeSharedPtr makeGauge(StatName name, StatName tag_extracted_name, const StatNameTagVector& stat_name_tags, Gauge::ImportMode import_mode) override; SymbolTable& symbolTable() override { return symbol_table_; } diff --git a/source/common/stats/fake_symbol_table_impl.h b/source/common/stats/fake_symbol_table_impl.h index ceadb6ff74096..bf23cb466242f 100644 --- a/source/common/stats/fake_symbol_table_impl.h +++ b/source/common/stats/fake_symbol_table_impl.h @@ -73,8 +73,7 @@ class FakeSymbolTableImpl : public SymbolTable { MemBlockBuilder mem_block(total_size_bytes); mem_block.appendOne(num_names); for (uint32_t i = 0; i < num_names; ++i) { - const StatName name = names[i]; - mem_block.appendData(absl::MakeSpan(name.sizeAndData(), name.size())); + SymbolTableImpl::Encoding::appendToMemBlock(names[i], mem_block); } // This assertion double-checks the arithmetic where we computed diff --git a/source/common/stats/histogram_impl.h b/source/common/stats/histogram_impl.h index c342d9ffa9769..332fca0e2b078 100644 --- a/source/common/stats/histogram_impl.h +++ b/source/common/stats/histogram_impl.h @@ -49,7 +49,7 @@ class HistogramStatisticsImpl : public HistogramStatistics, NonCopyable { class HistogramImplHelper : public MetricImpl { public: - HistogramImplHelper(StatName name, const std::string& tag_extracted_name, + HistogramImplHelper(StatName name, StatName tag_extracted_name, const StatNameTagVector& stat_name_tags, SymbolTable& symbol_table) : MetricImpl(name, tag_extracted_name, stat_name_tags, symbol_table) {} HistogramImplHelper(SymbolTable& symbol_table) : MetricImpl(symbol_table) {} @@ -68,7 +68,7 @@ class HistogramImplHelper : public MetricImpl { */ class HistogramImpl : public HistogramImplHelper { public: - HistogramImpl(StatName name, Unit unit, Store& parent, const std::string& tag_extracted_name, + HistogramImpl(StatName name, Unit unit, Store& parent, StatName tag_extracted_name, const StatNameTagVector& stat_name_tags) : HistogramImplHelper(name, tag_extracted_name, stat_name_tags, parent.symbolTable()), unit_(unit), parent_(parent) {} diff --git a/source/common/stats/isolated_store_impl.cc b/source/common/stats/isolated_store_impl.cc index b2ad1e3537c63..c3600c98d815c 100644 --- a/source/common/stats/isolated_store_impl.cc +++ b/source/common/stats/isolated_store_impl.cc @@ -24,14 +24,13 @@ IsolatedStoreImpl::IsolatedStoreImpl(std::unique_ptr&& symbol_table IsolatedStoreImpl::IsolatedStoreImpl(SymbolTable& symbol_table) : StoreImpl(symbol_table), alloc_(symbol_table), counters_([this](StatName name) -> CounterSharedPtr { - return alloc_.makeCounter(name, toString(name), StatNameTagVector{}); + return alloc_.makeCounter(name, name, StatNameTagVector{}); }), gauges_([this](StatName name, Gauge::ImportMode import_mode) -> GaugeSharedPtr { - return alloc_.makeGauge(name, toString(name), StatNameTagVector{}, import_mode); + return alloc_.makeGauge(name, name, StatNameTagVector{}, import_mode); }), histograms_([this](StatName name, Histogram::Unit unit) -> HistogramSharedPtr { - return HistogramSharedPtr( - new HistogramImpl(name, unit, *this, toString(name), StatNameTagVector{})); + return HistogramSharedPtr(new HistogramImpl(name, unit, *this, name, StatNameTagVector{})); }), null_counter_(new NullCounterImpl(symbol_table)), null_gauge_(new NullGaugeImpl(symbol_table)) {} diff --git a/source/common/stats/isolated_store_impl.h b/source/common/stats/isolated_store_impl.h index 792407a02c1ed..46150516f69c7 100644 --- a/source/common/stats/isolated_store_impl.h +++ b/source/common/stats/isolated_store_impl.h @@ -160,8 +160,6 @@ class IsolatedStoreImpl : public StoreImpl { private: IsolatedStoreImpl(std::unique_ptr&& symbol_table); - std::string toString(StatName stat_name) { return alloc_.symbolTable().toString(stat_name); } - SymbolTablePtr symbol_table_storage_; AllocatorImpl alloc_; IsolatedStatsCache counters_; diff --git a/source/common/stats/metric_impl.cc b/source/common/stats/metric_impl.cc index 3cf096d4f8950..12801e90fafe4 100644 --- a/source/common/stats/metric_impl.cc +++ b/source/common/stats/metric_impl.cc @@ -14,7 +14,7 @@ MetricHelper::~MetricHelper() { ASSERT(!stat_names_.populated()); } -MetricHelper::MetricHelper(StatName name, absl::string_view tag_extracted_name, +MetricHelper::MetricHelper(StatName name, StatName tag_extracted_name, const StatNameTagVector& stat_name_tags, SymbolTable& symbol_table) { // Encode all the names and tags into transient storage so we can count the // required bytes. 2 is added to account for the name and tag_extracted_name, @@ -23,8 +23,7 @@ MetricHelper::MetricHelper(StatName name, absl::string_view tag_extracted_name, const uint32_t num_names = 2 + 2 * stat_name_tags.size(); absl::FixedArray names(num_names); names[0] = name; - StatNameManagedStorage storage(tag_extracted_name, symbol_table); - names[1] = storage.statName(); + names[1] = tag_extracted_name; int index = 1; for (auto& stat_name_tag : stat_name_tags) { names[++index] = stat_name_tag.first; diff --git a/source/common/stats/metric_impl.h b/source/common/stats/metric_impl.h index 250fccb9e1a27..c923395b992d4 100644 --- a/source/common/stats/metric_impl.h +++ b/source/common/stats/metric_impl.h @@ -21,8 +21,8 @@ namespace Stats { */ class MetricHelper { public: - MetricHelper(StatName name, absl::string_view tag_extracted_name, - const StatNameTagVector& stat_name_tags, SymbolTable& symbol_table); + MetricHelper(StatName name, StatName tag_extracted_name, const StatNameTagVector& stat_name_tags, + SymbolTable& symbol_table); ~MetricHelper(); StatName statName() const; @@ -55,15 +55,14 @@ class MetricHelper { */ template class MetricImpl : public BaseClass { public: - // TODO(jmarantz): Use StatName for tag_extracted_name. - MetricImpl(StatName name, absl::string_view tag_extracted_name, - const StatNameTagVector& stat_name_tags, SymbolTable& symbol_table) + MetricImpl(StatName name, StatName tag_extracted_name, const StatNameTagVector& stat_name_tags, + SymbolTable& symbol_table) : helper_(name, tag_extracted_name, stat_name_tags, symbol_table) {} // Empty construction of a MetricImpl; used for null stats. explicit MetricImpl(SymbolTable& symbol_table) - : MetricImpl(StatNameManagedStorage("", symbol_table).statName(), "", StatNameTagVector{}, - symbol_table) {} + : MetricImpl(StatName(), StatName(), StatNameTagVector(), symbol_table) {} + TagVector tags() const override { return helper_.tags(constSymbolTable()); } StatName statName() const override { return helper_.statName(); } StatName tagExtractedStatName() const override { return helper_.tagExtractedStatName(); } diff --git a/source/common/stats/symbol_table_impl.cc b/source/common/stats/symbol_table_impl.cc index bc6aecc265892..cdef645b5a267 100644 --- a/source/common/stats/symbol_table_impl.cc +++ b/source/common/stats/symbol_table_impl.cc @@ -173,6 +173,16 @@ void SymbolTableImpl::Encoding::moveToMemBlock(MemBlockBuilder& mem_blo mem_block_.reset(); // Logically transfer ownership, enabling empty assert on destruct. } +void SymbolTableImpl::Encoding::appendToMemBlock(StatName stat_name, + MemBlockBuilder& mem_block) { + const uint8_t* data = stat_name.dataIncludingSize(); + if (data == nullptr) { + mem_block.appendOne(0); + } else { + mem_block.appendData(absl::MakeSpan(data, stat_name.size())); + } +} + SymbolTableImpl::SymbolTableImpl() // Have to be explicitly initialized, if we want to use the GUARDED_BY macro. : next_symbol_(FirstValidSymbol), monotonic_counter_(FirstValidSymbol) {} @@ -516,7 +526,9 @@ void StatNameStorageSet::free(SymbolTable& symbol_table) { SymbolTable::StoragePtr SymbolTableImpl::join(const StatNameVec& stat_names) const { uint64_t num_bytes = 0; for (StatName stat_name : stat_names) { - num_bytes += stat_name.dataSize(); + if (!stat_name.empty()) { + num_bytes += stat_name.dataSize(); + } } MemBlockBuilder mem_block(Encoding::totalSizeBytes(num_bytes)); Encoding::appendEncoding(num_bytes, mem_block); @@ -543,8 +555,8 @@ void SymbolTableImpl::populateList(const StatName* names, uint32_t num_names, St mem_block.appendOne(num_names); for (uint32_t i = 0; i < num_names; ++i) { const StatName stat_name = names[i]; + Encoding::appendToMemBlock(stat_name, mem_block); incRefCount(stat_name); - mem_block.appendData(absl::MakeSpan(stat_name.sizeAndData(), stat_name.size())); } // This assertion double-checks the arithmetic where we computed diff --git a/source/common/stats/symbol_table_impl.h b/source/common/stats/symbol_table_impl.h index f1459d04fb741..5440906a78072 100644 --- a/source/common/stats/symbol_table_impl.h +++ b/source/common/stats/symbol_table_impl.h @@ -157,6 +157,15 @@ class SymbolTableImpl : public SymbolTable { */ static void appendEncoding(uint64_t number, MemBlockBuilder& mem_block); + /** + * Appends stat_name's bytes into mem_block, which must have been allocated to + * allow for stat_name.size() bytes. + * + * @param stat_name the stat_name to append. + * @param mem_block the block of memory to append to. + */ + static void appendToMemBlock(StatName stat_name, MemBlockBuilder& mem_block); + /** * Decodes a byte-array containing a variable-length number. * @@ -452,6 +461,8 @@ class StatName { return size_and_data_ + SymbolTableImpl::Encoding::encodingSizeBytes(dataSize()); } + const uint8_t* dataIncludingSize() const { return size_and_data_; } + /** * @return A pointer to the buffer, including the size bytes. */ diff --git a/source/common/stats/thread_local_store.cc b/source/common/stats/thread_local_store.cc index 6f9bb037e8238..1051077dce230 100644 --- a/source/common/stats/thread_local_store.cc +++ b/source/common/stats/thread_local_store.cc @@ -280,23 +280,23 @@ class StatNameTagHelper { if (!stat_name_tags) { TagVector tags; tls.symbolTable().callWithStringView(name, [&tags, &tls, this](absl::string_view name_str) { - tag_extracted_name_ = tls.tagProducer().produceTags(name_str, tags); + tag_extracted_name_ = pool_.add(tls.tagProducer().produceTags(name_str, tags)); }); for (const auto& tag : tags) { stat_name_tags_.emplace_back(pool_.add(tag.name_), pool_.add(tag.value_)); } } else { - tag_extracted_name_ = tls.symbolTable().toString(name); + tag_extracted_name_ = name; } } const StatNameTagVector& statNameTags() const { return stat_name_tags_; } - const std::string& tagExtractedName() { return tag_extracted_name_; } + StatName tagExtractedName() const { return tag_extracted_name_; } private: StatNamePool pool_; StatNameTagVector stat_name_tags_; - std::string tag_extracted_name_; + StatName tag_extracted_name_; }; bool ThreadLocalStoreImpl::checkAndRememberRejection(StatName name, @@ -420,9 +420,9 @@ Counter& ThreadLocalStoreImpl::ScopeImpl::counterFromStatNameWithTags( return safeMakeStat( final_stat_name, joiner.tagExtractedName(), stat_name_tags, central_cache_->counters_, central_cache_->rejected_stats_, - [](Allocator& allocator, StatName name, absl::string_view final_name, + [](Allocator& allocator, StatName name, StatName tag_extracted_name, const StatNameTagVector& tags) -> CounterSharedPtr { - return allocator.makeCounter(name, final_name, tags); + return allocator.makeCounter(name, tag_extracted_name, tags); }, tls_cache, tls_rejected_stats, parent_.null_counter_); } @@ -471,7 +471,7 @@ Gauge& ThreadLocalStoreImpl::ScopeImpl::gaugeFromStatNameWithTags( Gauge& gauge = safeMakeStat( final_stat_name, joiner.tagExtractedName(), stat_name_tags, central_cache_->gauges_, central_cache_->rejected_stats_, - [import_mode](Allocator& allocator, StatName name, absl::string_view tag_extracted_name, + [import_mode](Allocator& allocator, StatName name, StatName tag_extracted_name, const StatNameTagVector& tags) -> GaugeSharedPtr { return allocator.makeGauge(name, tag_extracted_name, tags, import_mode); }, @@ -587,7 +587,7 @@ Histogram& ThreadLocalStoreImpl::ScopeImpl::tlsHistogram(StatName name, } ThreadLocalHistogramImpl::ThreadLocalHistogramImpl(StatName name, Histogram::Unit unit, - const std::string& tag_extracted_name, + StatName tag_extracted_name, const StatNameTagVector& stat_name_tags, SymbolTable& symbol_table) : HistogramImplHelper(name, tag_extracted_name, stat_name_tags, symbol_table), unit_(unit), @@ -616,7 +616,7 @@ void ThreadLocalHistogramImpl::merge(histogram_t* target) { } ParentHistogramImpl::ParentHistogramImpl(StatName name, Histogram::Unit unit, Store& parent, - TlsScope& tls_scope, absl::string_view tag_extracted_name, + TlsScope& tls_scope, StatName tag_extracted_name, const StatNameTagVector& stat_name_tags) : MetricImpl(name, tag_extracted_name, stat_name_tags, parent.symbolTable()), unit_(unit), parent_(parent), tls_scope_(tls_scope), interval_histogram_(hist_alloc()), diff --git a/source/common/stats/thread_local_store.h b/source/common/stats/thread_local_store.h index cfb36d447f7d6..4b26fdc1b0a50 100644 --- a/source/common/stats/thread_local_store.h +++ b/source/common/stats/thread_local_store.h @@ -32,8 +32,7 @@ namespace Stats { */ class ThreadLocalHistogramImpl : public HistogramImplHelper { public: - ThreadLocalHistogramImpl(StatName name, Histogram::Unit unit, - const std::string& tag_extracted_name, + ThreadLocalHistogramImpl(StatName name, Histogram::Unit unit, StatName tag_extracted_name, const StatNameTagVector& stat_name_tags, SymbolTable& symbol_table); ~ThreadLocalHistogramImpl() override; @@ -81,8 +80,7 @@ class TlsScope; class ParentHistogramImpl : public MetricImpl { public: ParentHistogramImpl(StatName name, Histogram::Unit unit, Store& parent, TlsScope& tls_scope, - absl::string_view tag_extracted_name, - const StatNameTagVector& stat_name_tags); + StatName tag_extracted_name, const StatNameTagVector& stat_name_tags); ~ParentHistogramImpl() override; void addTlsHistogram(const TlsHistogramSharedPtr& hist_ptr); @@ -320,9 +318,8 @@ class ThreadLocalStoreImpl : Logger::Loggable, public StoreRo HistogramOptConstRef findHistogram(StatName name) const override; template - using MakeStatFn = std::function(Allocator&, StatName name, - absl::string_view tag_extracted_name, - const StatNameTagVector& tags)>; + using MakeStatFn = std::function( + Allocator&, StatName name, StatName tag_extracted_name, const StatNameTagVector& tags)>; /** * Makes a stat either by looking it up in the central cache, diff --git a/test/common/stats/BUILD b/test/common/stats/BUILD index 8c59b79f289f3..0a9227a553b58 100644 --- a/test/common/stats/BUILD +++ b/test/common/stats/BUILD @@ -27,6 +27,7 @@ envoy_cc_test( srcs = ["isolated_store_impl_test.cc"], deps = [ "//source/common/stats:isolated_store_lib", + "//source/common/stats:symbol_table_creator_lib", ], ) diff --git a/test/common/stats/allocator_impl_test.cc b/test/common/stats/allocator_impl_test.cc index 173f8d892e1ab..b6579fdae6962 100644 --- a/test/common/stats/allocator_impl_test.cc +++ b/test/common/stats/allocator_impl_test.cc @@ -39,9 +39,9 @@ class AllocatorImplTest : public testing::Test { // Allocate 2 counters of the same name, and you'll get the same object. TEST_F(AllocatorImplTest, CountersWithSameName) { StatName counter_name = makeStat("counter.name"); - CounterSharedPtr c1 = alloc_.makeCounter(counter_name, "", {}); + CounterSharedPtr c1 = alloc_.makeCounter(counter_name, StatName(), {}); EXPECT_EQ(1, c1->use_count()); - CounterSharedPtr c2 = alloc_.makeCounter(counter_name, "", {}); + CounterSharedPtr c2 = alloc_.makeCounter(counter_name, StatName(), {}); EXPECT_EQ(2, c1->use_count()); EXPECT_EQ(2, c2->use_count()); EXPECT_EQ(c1.get(), c2.get()); @@ -57,9 +57,9 @@ TEST_F(AllocatorImplTest, CountersWithSameName) { TEST_F(AllocatorImplTest, GaugesWithSameName) { StatName gauge_name = makeStat("gauges.name"); - GaugeSharedPtr g1 = alloc_.makeGauge(gauge_name, "", {}, Gauge::ImportMode::Accumulate); + GaugeSharedPtr g1 = alloc_.makeGauge(gauge_name, StatName(), {}, Gauge::ImportMode::Accumulate); EXPECT_EQ(1, g1->use_count()); - GaugeSharedPtr g2 = alloc_.makeGauge(gauge_name, "", {}, Gauge::ImportMode::Accumulate); + GaugeSharedPtr g2 = alloc_.makeGauge(gauge_name, StatName(), {}, Gauge::ImportMode::Accumulate); EXPECT_EQ(2, g1->use_count()); EXPECT_EQ(2, g2->use_count()); EXPECT_EQ(g1.get(), g2.get()); @@ -92,8 +92,8 @@ TEST_F(AllocatorImplTest, RefCountDecAllocRaceOrganic) { threads.push_back(thread_factory.createThread([&]() { go.WaitForNotification(); for (uint32_t i = 0; i < iters; ++i) { - alloc_.makeCounter(counter_name, "", {}); - alloc_.makeGauge(gauge_name, "", {}, Gauge::ImportMode::NeverImport); + alloc_.makeCounter(counter_name, StatName(), {}); + alloc_.makeGauge(gauge_name, StatName(), {}, Gauge::ImportMode::NeverImport); } })); } @@ -116,7 +116,7 @@ TEST_F(AllocatorImplTest, RefCountDecAllocRaceSynchronized) { alloc_.sync().enable(); alloc_.sync().waitOn(AllocatorImpl::DecrementToZeroSyncPoint); Thread::ThreadPtr thread = thread_factory.createThread([&]() { - CounterSharedPtr counter = alloc_.makeCounter(counter_name, "", {}); + CounterSharedPtr counter = alloc_.makeCounter(counter_name, StatName(), {}); counter->inc(); counter->reset(); // Blocks in thread synchronizer waiting on DecrementToZeroSyncPoint }); diff --git a/test/common/stats/metric_impl_test.cc b/test/common/stats/metric_impl_test.cc index 910615aca3e63..75652e21f9891 100644 --- a/test/common/stats/metric_impl_test.cc +++ b/test/common/stats/metric_impl_test.cc @@ -33,12 +33,12 @@ class MetricImplTest : public testing::Test { // No truncation occurs in the implementation of HeapStatData. TEST_F(MetricImplTest, NoTags) { - CounterSharedPtr counter = alloc_.makeCounter(makeStat("counter"), "", {}); + CounterSharedPtr counter = alloc_.makeCounter(makeStat("counter"), StatName(), {}); EXPECT_EQ(0, counter->tags().size()); } TEST_F(MetricImplTest, OneTag) { - CounterSharedPtr counter = alloc_.makeCounter(makeStat("counter.name.value"), "counter", + CounterSharedPtr counter = alloc_.makeCounter(makeStat("counter.name.value"), makeStat("counter"), {{makeStat("name"), makeStat("value")}}); TagVector tags = counter->tags(); ASSERT_EQ(1, tags.size()); @@ -51,7 +51,7 @@ TEST_F(MetricImplTest, OneTag) { TEST_F(MetricImplTest, TwoTagsIterOnce) { CounterSharedPtr counter = alloc_.makeCounter( - makeStat("counter.name.value"), "counter", + makeStat("counter.name.value"), makeStat("counter"), {{makeStat("name1"), makeStat("value1")}, {makeStat("name2"), makeStat("value2")}}); StatName name1 = makeStat("name1"); StatName value1 = makeStat("value1"); @@ -67,7 +67,7 @@ TEST_F(MetricImplTest, TwoTagsIterOnce) { TEST_F(MetricImplTest, FindTag) { CounterSharedPtr counter = alloc_.makeCounter( - makeStat("counter.name.value"), "counter", + makeStat("counter.name.value"), makeStat("counter"), {{makeStat("name1"), makeStat("value1")}, {makeStat("name2"), makeStat("value2")}}); EXPECT_EQ(makeStat("value1"), Utility::findTag(*counter, makeStat("name1"))); EXPECT_EQ(makeStat("value2"), Utility::findTag(*counter, makeStat("name2"))); @@ -76,4 +76,4 @@ TEST_F(MetricImplTest, FindTag) { } // namespace } // namespace Stats -} // namespace Envoy \ No newline at end of file +} // namespace Envoy diff --git a/test/common/stats/symbol_table_impl_test.cc b/test/common/stats/symbol_table_impl_test.cc index 268176811a313..b7def5f190390 100644 --- a/test/common/stats/symbol_table_impl_test.cc +++ b/test/common/stats/symbol_table_impl_test.cc @@ -190,6 +190,14 @@ TEST_P(StatNameTest, TestDynamicPools) { EXPECT_NE(dynamic2.data(), dynamic.data()); } +TEST_P(StatNameTest, TestDynamicHash) { + StatNameDynamicPool dynamic(*table_); + const StatName d1 = dynamic.add("dynamic"); + const StatName d2 = dynamic.add("dynamic"); + EXPECT_EQ(d1, d2); + EXPECT_EQ(d1.hash(), d2.hash()); +} + TEST_P(StatNameTest, Test100KSymbolsRoundtrip) { for (int i = 0; i < 100 * 1000; ++i) { const std::string stat_name = absl::StrCat("symbol_", i); diff --git a/test/common/stats/thread_local_store_test.cc b/test/common/stats/thread_local_store_test.cc index bf4cea82fe6d8..502175756140e 100644 --- a/test/common/stats/thread_local_store_test.cc +++ b/test/common/stats/thread_local_store_test.cc @@ -1397,7 +1397,8 @@ TEST_F(ClusterShutdownCleanupStarvationTest, TwelveThreadsWithBlockade) { main_dispatch_block(); // Here we show that the counter cleanups have finished, because the use-count is 1. - CounterSharedPtr counter = alloc_.makeCounter(my_counter_scoped_name_, "", StatNameTagVector{}); + CounterSharedPtr counter = + alloc_.makeCounter(my_counter_scoped_name_, StatName(), StatNameTagVector{}); EXPECT_EQ(1, counter->use_count()) << "index=" << i; } } @@ -1421,7 +1422,8 @@ TEST_F(ClusterShutdownCleanupStarvationTest, TwelveThreadsWithoutBlockade) { // running the test: NumScopes*NumThreads*NumIters == 70000, We use a timer // so we don't time out on asan/tsan tests, In opt builds this test takes // less than a second, and in fastbuild it takes less than 5. - CounterSharedPtr counter = alloc_.makeCounter(my_counter_scoped_name_, "", StatNameTagVector{}); + CounterSharedPtr counter = + alloc_.makeCounter(my_counter_scoped_name_, StatName(), StatNameTagVector{}); uint32_t use_count = counter->use_count() - 1; // Subtract off this instance. EXPECT_EQ((i + 1) * NumScopes * NumThreads, use_count); } diff --git a/test/server/http/admin_test.cc b/test/server/http/admin_test.cc index a70dab0c3b42f..8541b8f803233 100644 --- a/test/server/http/admin_test.cc +++ b/test/server/http/admin_test.cc @@ -1632,13 +1632,15 @@ class PrometheusStatsFormatterTest : public testing::Test { void addCounter(const std::string& name, Stats::StatNameTagVector cluster_tags) { Stats::StatNameManagedStorage storage(name, *symbol_table_); - counters_.push_back(alloc_.makeCounter(storage.statName(), name, cluster_tags)); + Stats::StatName stat_name = storage.statName(); + counters_.push_back(alloc_.makeCounter(stat_name, stat_name, cluster_tags)); } void addGauge(const std::string& name, Stats::StatNameTagVector cluster_tags) { Stats::StatNameManagedStorage storage(name, *symbol_table_); - gauges_.push_back(alloc_.makeGauge(storage.statName(), name, cluster_tags, - Stats::Gauge::ImportMode::Accumulate)); + Stats::StatName stat_name = storage.statName(); + gauges_.push_back( + alloc_.makeGauge(stat_name, stat_name, cluster_tags, Stats::Gauge::ImportMode::Accumulate)); } void addHistogram(const Stats::ParentHistogramSharedPtr histogram) {