Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions include/envoy/api/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ class Api {
* @return a reference to the TimeSource
*/
virtual TimeSource& timeSource() PURE;

/**
* @return a reference to the Stats::Store
*/
virtual Stats::Store& statsStore() PURE;
Comment thread
jmarantz marked this conversation as resolved.
Outdated
};

typedef std::unique_ptr<Api> ApiPtr;
Expand Down
5 changes: 5 additions & 0 deletions include/envoy/server/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ class Instance {
*/
virtual TimeSource& timeSource() PURE;

/**
* @return the statistics symbol table.
*/
virtual Stats::SymbolTable& symbolTable() PURE;
Comment thread
jmarantz marked this conversation as resolved.
Outdated

/**
* @return the flush interval of stats sinks.
*/
Expand Down
8 changes: 7 additions & 1 deletion include/envoy/stats/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@ envoy_cc_library(
"tag_extractor.h",
"tag_producer.h",
],
deps = ["//include/envoy/common:interval_set_interface"],
deps = [
":symbol_table_interface",
"//include/envoy/common:interval_set_interface",
],
)

envoy_cc_library(
name = "symbol_table_interface",
hdrs = ["symbol_table.h"],
deps = [
"//source/common/common:hash_lib",
],
)

envoy_cc_library(
Expand Down
8 changes: 7 additions & 1 deletion include/envoy/stats/scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

#include <cstdint>
#include <memory>
#include <string>

#include "envoy/common/pure.h"
#include "envoy/stats/histogram.h"
#include "envoy/stats/stats_options.h"
#include "envoy/stats/symbol_table.h"

namespace Envoy {
namespace Stats {
Expand Down Expand Up @@ -61,6 +61,12 @@ class Scope {
* maximum allowable object name length and stat suffix length.
*/
virtual const Stats::StatsOptions& statsOptions() const PURE;

/**
* @return a reference to the symbol table.
*/
virtual const SymbolTable& symbolTable() const PURE;
virtual SymbolTable& symbolTable() PURE;
};

} // namespace Stats
Expand Down
4 changes: 4 additions & 0 deletions include/envoy/stats/stat_data_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "envoy/common/pure.h"
#include "envoy/stats/stats.h"
#include "envoy/stats/symbol_table.h"
#include "envoy/stats/tag.h"

#include "absl/strings/string_view.h"
Expand Down Expand Up @@ -52,6 +53,9 @@ class StatDataAllocator {
*/
virtual bool requiresBoundedStatNameSize() const PURE;

virtual const SymbolTable& symbolTable() const PURE;
virtual SymbolTable& symbolTable() PURE;

// TODO(jmarantz): create a parallel mechanism to instantiate histograms. At
// the moment, histograms don't fit the same pattern of counters and gauges
// as they are not actually created in the context of a stats allocator.
Expand Down
5 changes: 3 additions & 2 deletions source/common/api/api_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
namespace Envoy {
namespace Api {

Impl::Impl(Thread::ThreadFactory& thread_factory, Stats::Store&, Event::TimeSystem& time_system)
: thread_factory_(thread_factory), time_system_(time_system) {}
Impl::Impl(Thread::ThreadFactory& thread_factory, Stats::Store& stats_store,
Event::TimeSystem& time_system)
: thread_factory_(thread_factory), time_system_(time_system), stats_store_(stats_store) {}

Event::DispatcherPtr Impl::allocateDispatcher() {
return std::make_unique<Event::DispatcherImpl>(*this, time_system_);
Expand Down
6 changes: 5 additions & 1 deletion source/common/api/api_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "envoy/api/api.h"
#include "envoy/event/timer.h"
#include "envoy/filesystem/filesystem.h"
#include "envoy/stats/store.h"
#include "envoy/thread/thread.h"

#include "common/filesystem/filesystem_impl.h"
Expand All @@ -18,19 +19,22 @@ namespace Api {
*/
class Impl : public Api {
public:
Impl(Thread::ThreadFactory& thread_factory, Stats::Store&, Event::TimeSystem& time_system);
Impl(Thread::ThreadFactory& thread_factory, Stats::Store& stats_store,
Event::TimeSystem& time_system);

// Api::Api
Event::DispatcherPtr allocateDispatcher() override;
Event::DispatcherPtr allocateDispatcher(Buffer::WatermarkFactoryPtr&& watermark_factory) override;
Thread::ThreadFactory& threadFactory() override { return thread_factory_; }
Filesystem::Instance& fileSystem() override { return file_system_; }
TimeSource& timeSource() override { return time_system_; }
Stats::Store& statsStore() override { return stats_store_; }

private:
Thread::ThreadFactory& thread_factory_;
Filesystem::InstanceImpl file_system_;
Event::TimeSystem& time_system_;
Stats::Store& stats_store_;
};

} // namespace Api
Expand Down
5 changes: 5 additions & 0 deletions source/common/stats/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ envoy_cc_library(
srcs = ["heap_stat_data.cc"],
hdrs = ["heap_stat_data.h"],
deps = [
":metric_impl_lib",
":stat_data_allocator_lib",
"//source/common/common:assert_lib",
"//source/common/common:hash_lib",
Expand Down Expand Up @@ -42,6 +43,7 @@ envoy_cc_library(
srcs = ["isolated_store_impl.cc"],
hdrs = ["isolated_store_impl.h"],
deps = [
":fake_symbol_table_lib",
":histogram_lib",
":stats_lib",
":stats_options_lib",
Expand All @@ -54,6 +56,7 @@ envoy_cc_library(
name = "metric_impl_lib",
hdrs = ["metric_impl.h"],
deps = [
":symbol_table_lib",
"//include/envoy/stats:stats_interface",
"//source/common/common:assert_lib",
],
Expand Down Expand Up @@ -130,6 +133,7 @@ envoy_cc_library(
"//include/envoy/stats:symbol_table_interface",
"//source/common/common:assert_lib",
"//source/common/common:logger_lib",
"//source/common/common:stack_array",
"//source/common/common:thread_lib",
"//source/common/common:utility_lib",
],
Expand Down Expand Up @@ -202,4 +206,5 @@ envoy_cc_library(
name = "utility_lib",
srcs = ["utility.cc"],
hdrs = ["utility.h"],
deps = [":symbol_table_lib"],
)
2 changes: 0 additions & 2 deletions source/common/stats/heap_stat_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ HeapStatData::HeapStatData(absl::string_view key) {
StringUtil::strlcpy(name_, key.data(), key.size() + 1);
}

HeapStatDataAllocator::HeapStatDataAllocator() {}

HeapStatDataAllocator::~HeapStatDataAllocator() { ASSERT(stats_.empty()); }

HeapStatData* HeapStatDataAllocator::alloc(absl::string_view name) {
Expand Down
6 changes: 4 additions & 2 deletions source/common/stats/heap_stat_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <string>
#include <unordered_set>

#include "envoy/stats/symbol_table.h"

#include "common/common/hash.h"
#include "common/common/thread.h"
#include "common/common/thread_annotations.h"
Expand Down Expand Up @@ -53,8 +55,8 @@ struct HeapStatData {
*/
class HeapStatDataAllocator : public StatDataAllocatorImpl<HeapStatData> {
public:
HeapStatDataAllocator();
~HeapStatDataAllocator();
HeapStatDataAllocator(SymbolTable& symbol_table) : StatDataAllocatorImpl(symbol_table) {}
~HeapStatDataAllocator() override;

// StatDataAllocatorImpl
HeapStatData* alloc(absl::string_view name) override;
Expand Down
14 changes: 13 additions & 1 deletion source/common/stats/isolated_store_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,24 @@
#include <string>

#include "common/common/utility.h"
#include "common/stats/fake_symbol_table_impl.h"
#include "common/stats/histogram_impl.h"
#include "common/stats/utility.h"

namespace Envoy {
namespace Stats {

IsolatedStoreImpl::IsolatedStoreImpl()
: counters_([this](const std::string& name) -> CounterSharedPtr {
: IsolatedStoreImpl(std::make_unique<FakeSymbolTableImpl>()) {}

IsolatedStoreImpl::IsolatedStoreImpl(std::unique_ptr<SymbolTable> symbol_table)
Comment thread
jmarantz marked this conversation as resolved.
Outdated
: IsolatedStoreImpl(*symbol_table) {
symbol_table_storage_ = std::move(symbol_table);
}

IsolatedStoreImpl::IsolatedStoreImpl(SymbolTable& symbol_table)
: symbol_table_(symbol_table), alloc_(symbol_table_),
counters_([this](const std::string& name) -> CounterSharedPtr {
std::string tag_extracted_name = name;
std::vector<Tag> tags;
return alloc_.makeCounter(name, std::move(tag_extracted_name), std::move(tags));
Expand Down Expand Up @@ -42,6 +52,8 @@ struct IsolatedScopeImpl : public Scope {
return parent_.histogram(prefix_ + name);
}
const Stats::StatsOptions& statsOptions() const override { return parent_.statsOptions(); }
const SymbolTable& symbolTable() const override { return parent_.symbolTable(); }
SymbolTable& symbolTable() override { return parent_.symbolTable(); }

IsolatedStoreImpl& parent_;
const std::string prefix_;
Expand Down
13 changes: 11 additions & 2 deletions source/common/stats/isolated_store_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
#include "common/common/utility.h"
#include "common/stats/heap_stat_data.h"
#include "common/stats/stats_options_impl.h"
#include "common/stats/symbol_table_impl.h"
#include "common/stats/utility.h"

#include "absl/container/flat_hash_map.h"

namespace Envoy {
namespace Stats {

Expand All @@ -22,7 +25,7 @@ namespace Stats {
*/
template <class Base> class IsolatedStatsCache {
public:
typedef std::function<std::shared_ptr<Base>(const std::string& name)> Allocator;
using Allocator = std::function<std::shared_ptr<Base>(const std::string& name)>;

IsolatedStatsCache(Allocator alloc) : alloc_(alloc) {}

Expand All @@ -48,13 +51,15 @@ template <class Base> class IsolatedStatsCache {
}

private:
std::unordered_map<std::string, std::shared_ptr<Base>> stats_;
absl::flat_hash_map<std::string, std::shared_ptr<Base>> stats_;
Allocator alloc_;
};

class IsolatedStoreImpl : public Store {
public:
IsolatedStoreImpl();
explicit IsolatedStoreImpl(std::unique_ptr<SymbolTable> symbol_table);
explicit IsolatedStoreImpl(SymbolTable& symbol_table);

// Stats::Scope
Counter& counter(const std::string& name) override { return counters_.get(name); }
Expand All @@ -66,6 +71,8 @@ class IsolatedStoreImpl : public Store {
return histogram;
}
const Stats::StatsOptions& statsOptions() const override { return stats_options_; }
const SymbolTable& symbolTable() const override { return symbol_table_; }
virtual SymbolTable& symbolTable() override { return symbol_table_; }

// Stats::Store
std::vector<CounterSharedPtr> counters() const override { return counters_.toVector(); }
Expand All @@ -75,6 +82,8 @@ class IsolatedStoreImpl : public Store {
}

private:
std::unique_ptr<SymbolTable> symbol_table_storage_;
SymbolTable& symbol_table_;
HeapStatDataAllocator alloc_;
IsolatedStatsCache<Counter> counters_;
IsolatedStatsCache<Gauge> gauges_;
Expand Down
6 changes: 4 additions & 2 deletions source/common/stats/raw_stat_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "envoy/stats/stat_data_allocator.h"
#include "envoy/stats/stats_options.h"
#include "envoy/stats/symbol_table.h"

#include "common/common/assert.h"
#include "common/common/block_memory_hash_set.h"
Expand Down Expand Up @@ -97,8 +98,9 @@ using RawStatDataSet = BlockMemoryHashSet<Stats::RawStatData>;
class RawStatDataAllocator : public StatDataAllocatorImpl<RawStatData> {
public:
RawStatDataAllocator(Thread::BasicLockable& mutex, RawStatDataSet& stats_set,
const StatsOptions& options)
: mutex_(mutex), stats_set_(stats_set), options_(options) {}
const StatsOptions& options, SymbolTable& symbol_table)
: StatDataAllocatorImpl(symbol_table), mutex_(mutex), stats_set_(stats_set),
options_(options) {}

// StatDataAllocator
bool requiresBoundedStatNameSize() const override { return true; }
Expand Down
9 changes: 9 additions & 0 deletions source/common/stats/stat_data_allocator_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "envoy/stats/stat_data_allocator.h"
#include "envoy/stats/stats.h"
#include "envoy/stats/symbol_table.h"

#include "common/common/assert.h"
#include "common/stats/metric_impl.h"
Expand All @@ -29,6 +30,8 @@ namespace Stats {
// available. This could be resolved with placed new, or another nesting level.
template <class StatData> class StatDataAllocatorImpl : public StatDataAllocator {
public:
explicit StatDataAllocatorImpl(SymbolTable& symbol_table) : symbol_table_(symbol_table) {}

// StatDataAllocator
CounterSharedPtr makeCounter(absl::string_view name, std::string&& tag_extracted_name,
std::vector<Tag>&& tags) override;
Expand All @@ -50,6 +53,12 @@ template <class StatData> class StatDataAllocatorImpl : public StatDataAllocator
* @param data the data returned by alloc().
*/
virtual void free(StatData& data) PURE;

SymbolTable& symbolTable() override { return symbol_table_; }
const SymbolTable& symbolTable() const override { return symbol_table_; }

private:
SymbolTable& symbol_table_;
};

/**
Expand Down
3 changes: 2 additions & 1 deletion source/common/stats/thread_local_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ ThreadLocalStoreImpl::ThreadLocalStoreImpl(const StatsOptions& stats_options,
: stats_options_(stats_options), alloc_(alloc), default_scope_(createScope("")),
tag_producer_(std::make_unique<TagProducerImpl>()),
stats_matcher_(std::make_unique<StatsMatcherImpl>()),
num_last_resort_stats_(default_scope_->counter("stats.overflow")), source_(*this) {}
num_last_resort_stats_(default_scope_->counter("stats.overflow")),
heap_allocator_(alloc.symbolTable()), source_(*this) {}

ThreadLocalStoreImpl::~ThreadLocalStoreImpl() {
ASSERT(shutting_down_);
Expand Down
4 changes: 4 additions & 0 deletions source/common/stats/thread_local_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ class ThreadLocalStoreImpl : Logger::Loggable<Logger::Id::stats>, public StoreRo
Histogram& histogram(const std::string& name) override {
return default_scope_->histogram(name);
};
const SymbolTable& symbolTable() const override { return alloc_.symbolTable(); }
SymbolTable& symbolTable() override { return alloc_.symbolTable(); }

// Stats::Store
std::vector<CounterSharedPtr> counters() const override;
Expand Down Expand Up @@ -197,6 +199,8 @@ class ThreadLocalStoreImpl : Logger::Loggable<Logger::Id::stats>, public StoreRo
ScopePtr createScope(const std::string& name) override {
return parent_.createScope(prefix_ + name);
}
const SymbolTable& symbolTable() const override { return parent_.symbolTable(); }
SymbolTable& symbolTable() override { return parent_.symbolTable(); }
void deliverHistogramToSinks(const Histogram& histogram, uint64_t value) override;
Gauge& gauge(const std::string& name) override;
Histogram& histogram(const std::string& name) override;
Expand Down
1 change: 1 addition & 0 deletions source/exe/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ envoy_cc_library(
"//source/common/common:compiler_requirements_lib",
"//source/common/http/http2:codec_lib",
"//source/common/common:perf_annotation_lib",
"//source/common/stats:fake_symbol_table_lib",
"//source/common/thread:thread_factory_singleton_lib",
"//source/server:hot_restart_lib",
"//source/server:hot_restart_nop_lib",
Expand Down
6 changes: 3 additions & 3 deletions source/exe/main_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ MainCommonBase::MainCommonBase(const OptionsImpl& options, Event::TimeSystem& ti
case Server::Mode::Serve: {
#ifdef ENVOY_HOT_RESTART
if (!options.hotRestartDisabled()) {
restarter_ = std::make_unique<Server::HotRestartImpl>(options_);
restarter_ = std::make_unique<Server::HotRestartImpl>(options_, symbol_table_);
}
#endif
if (restarter_ == nullptr) {
restarter_ = std::make_unique<Server::HotRestartNopImpl>();
restarter_ = std::make_unique<Server::HotRestartNopImpl>(symbol_table_);
}

tls_ = std::make_unique<ThreadLocal::InstanceImpl>();
Expand All @@ -88,7 +88,7 @@ MainCommonBase::MainCommonBase(const OptionsImpl& options, Event::TimeSystem& ti
break;
}
case Server::Mode::Validate:
restarter_ = std::make_unique<Server::HotRestartNopImpl>();
restarter_ = std::make_unique<Server::HotRestartNopImpl>(symbol_table_);
logging_context_ = std::make_unique<Logger::Context>(options_.logLevel(), options_.logFormat(),
restarter_->logLock());
break;
Expand Down
Loading