-
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
stats: Remember recent lookups and display them in an admin endpoint #8116
Changes from 66 commits
f871f2b
be02163
7f404a0
4eeb7eb
c1a1a32
e2e384e
33c0f88
8808258
8bc22f6
86e9204
cd83c62
fd3bbbd
cfa1634
49dfcb4
e8498a2
312d389
491ab32
45a4feb
90327f7
7b867b3
52793db
3e9e3a5
e9662a0
fd23fbe
1bf7773
c949893
14f9eae
56b0fec
8cdf5fc
9b65b71
b920220
2e4f122
82c03cd
fa447d8
cb828f8
60c0673
9b92a3f
c0ad91d
e08c677
b38b505
e6935fc
a8f685f
88c5dc5
c536bed
67b0f49
0760e00
09c948c
25cbe85
514fb31
c9dddb4
5ec6fce
422d15d
049cab3
e4ea14e
106d75d
af6d5de
6cdf862
9f0b754
6bca221
14cbbcf
d82b1df
ff84c2c
e8cb00c
faf1cfa
a70b2de
c18f184
a7bb051
f17bcdb
298210c
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 |
---|---|---|
|
@@ -200,7 +200,7 @@ modify different aspects of the server: | |
.. http:post:: /reset_counters | ||
|
||
Reset all counters to zero. This is useful along with :http:get:`/stats` during debugging. Note | ||
that this does not drop any data sent to statsd. It just effects local output of the | ||
that this does not drop any data sent to statsd. It just affects local output of the | ||
:http:get:`/stats` command. | ||
|
||
.. http:get:: /server_info | ||
|
@@ -354,6 +354,55 @@ modify different aspects of the server: | |
Envoy has updated (counters incremented at least once, gauges changed at least once, | ||
and histograms added to at least once) | ||
|
||
.. http:get:: /stats/recentlookups | ||
|
||
This endpoint helps Envoy developers debug potential contention | ||
issues in the stats system. Initially, only the count of StatName | ||
lookups is acumulated, not the specific names that are being looked | ||
up. In order to see specific recent requests, you must enable the | ||
feature by POSTing to `/stats/recentlookups/enable`. There may be | ||
approximately 40-100 nanoseconds of added overhead per lookup. | ||
|
||
When enabled, this endpoint emits a table of stat names that were | ||
recently accessed as strings by Envoy. Ideally, strings should be | ||
converted into StatNames, counters, gauges, and histograms by Envoy | ||
code only during startup or when receiving a new configuration via | ||
xDS. This is because when stats are looked up as strings they must | ||
take a global symbol table lock. During startup this is acceptable, | ||
but in response to user requests on high core-count machines, this | ||
can cause performance issues due to mutex contention. | ||
|
||
This option requires Envoy to be started with `use-fake-symbol-table 0`. | ||
|
||
See :repo:`source/docs/stats.md` for more details. | ||
|
||
Note also that actual mutex contention can be tracked via :http:get:`/contention`. | ||
|
||
.. http:post:: /stats/recentlookups/enable | ||
|
||
Turns on collection of recent lookup of stat-names, thus enabling | ||
`/stats/recentlookups`. | ||
|
||
See :repo:`source/docs/stats.md` for more details. | ||
|
||
.. http:post:: /stats/recentlookups/disable | ||
|
||
Turns off collection of recent lookup of stat-names, thus disabling | ||
`/stats/recentlookups`. It also clears the list of lookups. However, | ||
the total count, visible as stat `server.stats_recent_lookups`, is | ||
not cleared, and continues to accumulate. | ||
|
||
See :repo:`source/docs/stats.md` for more details. | ||
|
||
.. http:post:: /stats/recentlookups/clear | ||
|
||
Clears all outstanding lookups and counts. If called when recent lookup | ||
collection is enabled, this clears all the, but collection | ||
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. typo 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. fixed, and I simplified this, as I don't think it adds anything to the paragraph to discuss the two different cases. commit coming. |
||
continues. If called when recent lookup collection is disabled, | ||
there is no effect, as disabling collection clears the data. | ||
|
||
See :repo:`source/docs/stats.md` for more details. | ||
|
||
.. _operations_admin_interface_runtime: | ||
|
||
.. http:get:: /runtime | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
#include "common/common/stack_array.h" | ||
#include "common/common/thread.h" | ||
#include "common/common/utility.h" | ||
#include "common/stats/recent_lookups.h" | ||
|
||
#include "absl/container/flat_hash_map.h" | ||
#include "absl/strings/str_join.h" | ||
|
@@ -161,6 +162,10 @@ class SymbolTableImpl : public SymbolTable { | |
|
||
StatNameSetPtr makeSet(absl::string_view name) override; | ||
void forgetSet(StatNameSet& stat_name_set) override; | ||
uint64_t getRecentLookups(const RecentLookupsFn&) const override; | ||
void clearRecentLookups() override; | ||
void setRecentLookupCapacity(uint64_t capacity) override; | ||
uint64_t recentLookupCapacity() const override; | ||
|
||
private: | ||
friend class StatName; | ||
|
@@ -176,6 +181,9 @@ class SymbolTableImpl : public SymbolTable { | |
// This must be held during both encode() and free(). | ||
mutable Thread::MutexBasicLockable lock_; | ||
|
||
// This must be held while updating stat_name_sets_. | ||
mutable Thread::MutexBasicLockable stat_name_set_mutex_; | ||
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 we do need a separate mutex for this or we get deadlock detection triggered by absl when calling getDynamic(). |
||
|
||
/** | ||
* Decodes a vector of symbols back into its period-delimited stat name. If | ||
* decoding fails on any part of the symbol_vec, we release_assert and crash | ||
|
@@ -241,7 +249,9 @@ class SymbolTableImpl : public SymbolTable { | |
// TODO(ambuc): There might be an optimization here relating to storing ranges of freed symbols | ||
// using an Envoy::IntervalSet. | ||
std::stack<Symbol> pool_ GUARDED_BY(lock_); | ||
absl::flat_hash_set<StatNameSet*> stat_name_sets_ GUARDED_BY(lock_); | ||
RecentLookups recent_lookups_ GUARDED_BY(lock_); | ||
|
||
absl::flat_hash_set<StatNameSet*> stat_name_sets_ GUARDED_BY(stat_name_set_mutex_); | ||
}; | ||
|
||
/** | ||
|
@@ -709,19 +719,33 @@ class StatNameSet { | |
return pool_.add(str); | ||
} | ||
|
||
/** | ||
* Clears recent lookups. | ||
*/ | ||
void clearRecentLookups(); | ||
|
||
/** | ||
* Sets the number of names recorded in the recent-lookups set. | ||
* | ||
* @param capacity the capacity to configure. | ||
*/ | ||
void setRecentLookupCapacity(uint64_t capacity); | ||
|
||
private: | ||
friend class FakeSymbolTableImpl; | ||
friend class SymbolTableImpl; | ||
|
||
StatNameSet(SymbolTable& symbol_table, absl::string_view name); | ||
uint64_t getRecentLookups(const RecentLookups::IterFn& iter) const; | ||
|
||
const std::string name_; | ||
Stats::SymbolTable& symbol_table_; | ||
Stats::StatNamePool pool_ GUARDED_BY(mutex_); | ||
absl::Mutex mutex_; | ||
mutable absl::Mutex mutex_; | ||
using StringStatNameMap = absl::flat_hash_map<std::string, Stats::StatName>; | ||
StringStatNameMap builtin_stat_names_; | ||
StringStatNameMap dynamic_stat_names_ GUARDED_BY(mutex_); | ||
RecentLookups recent_lookups_ GUARDED_BY(mutex_); | ||
}; | ||
|
||
} // namespace Stats | ||
|
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: I think you can use an
:option
ref link here.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; thanks.
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.
Actually I backed this out, as
use-fake-symbol-table
is not docced, as it was meant to be temporary.