-
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: Add option to switch between fake and real symbol-tables on the command-line. #7882
Changes from 19 commits
d4744bd
313d591
bee7b67
56ab602
a0e1d7c
92442ef
96f4e85
f9c4f82
08f444e
5021cc2
6ce2eec
0605670
a8860bb
9266115
8d3cb07
a4cee7b
d1eced2
2ae8431
753aff4
6d2a2ac
bf55388
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include "common/stats/symbol_table_creator.h" | ||
|
||
namespace Envoy { | ||
namespace Stats { | ||
|
||
bool SymbolTableCreator::initialized_ = false; | ||
bool SymbolTableCreator::use_fake_symbol_tables_ = true; | ||
|
||
SymbolTablePtr SymbolTableCreator::initAndMakeSymbolTable(bool use_fake) { | ||
ASSERT(!initialized_ || (use_fake_symbol_tables_ == use_fake)); | ||
initialized_ = true; | ||
use_fake_symbol_tables_ = use_fake; | ||
return makeSymbolTable(); | ||
} | ||
|
||
SymbolTablePtr SymbolTableCreator::makeSymbolTable() { | ||
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 we add some logic in here to make sure we only read one value out of this function? Meaning, IMO we should only ever make 1 type of symbol table in the process. Can we assert that? 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 feel like we've covered that by asserting in initAndMakeSymbolTable above, and by making the setter private with a testing-peer friend. And we do create different types of symbol tables in tests, so putting an assert at this level would require some kind of test-mode override, like:
IMO that doesn't add anything and the assert/private strategy here should be sufficient, but I'm OK adding that if you think it helps. WDYT? 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 still don't see how this prevents code from using 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. You are right; PTAL again; I think I just needed to set the 'initialized' bit from makeSymblTable to prevent that scenario. |
||
if (use_fake_symbol_tables_) { | ||
return std::make_unique<FakeSymbolTableImpl>(); | ||
} | ||
return std::make_unique<SymbolTableImpl>(); | ||
} | ||
|
||
} // namespace Stats | ||
} // namespace Envoy |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#pragma once | ||
|
||
#include "common/stats/fake_symbol_table_impl.h" | ||
#include "common/stats/symbol_table_impl.h" | ||
|
||
namespace Envoy { | ||
namespace Stats { | ||
|
||
namespace TestUtil { | ||
class SymbolTableCreatorTestPeer; | ||
} | ||
|
||
class SymbolTableCreator { | ||
public: | ||
/** | ||
* Initializes the symbol-table creation system. Once this is called, it is a | ||
* runtime assertion to call this again in production code, changing the | ||
* use_fakes setting. However, tests can change the setting via | ||
* TestUtil::SymbolTableCreatorTestPeer::setUseFakeSymbolTables(use_fakes). | ||
* | ||
* @param use_fakes Whether to use fake symbol tables; typically from a command-line option. | ||
* @return a SymbolTable. | ||
*/ | ||
static SymbolTablePtr initAndMakeSymbolTable(bool use_fakes); | ||
|
||
/** | ||
* Factory method to create SymbolTables. This is needed to help make it | ||
* possible to flag-flip use of real symbol tables, and ultimately should be | ||
* removed. | ||
* | ||
* @return a SymbolTable. | ||
*/ | ||
static SymbolTablePtr makeSymbolTable(); | ||
|
||
/** | ||
* @return whether the system is initialized to use fake symbol tables. | ||
*/ | ||
static bool useFakeSymbolTables() { return use_fake_symbol_tables_; } | ||
|
||
private: | ||
friend class TestUtil::SymbolTableCreatorTestPeer; | ||
|
||
/** | ||
* Sets whether fake or real symbol tables should be used. Tests that alter | ||
* this should restore previous value at the end of the test. This must be | ||
* called via TestUtil::SymbolTableCreatorTestPeer. | ||
* | ||
* *param use_fakes whether to use fake symbol tables. | ||
*/ | ||
static void setUseFakeSymbolTables(bool use_fakes) { use_fake_symbol_tables_ = use_fakes; } | ||
|
||
static bool initialized_; | ||
static bool use_fake_symbol_tables_; | ||
}; | ||
|
||
} // namespace Stats | ||
} // namespace Envoy |
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.
Use of SymbolTable for the IsolatedStoreImpl used by HostDescriptionImpl and ClusterInfoImpl::load_report_stats_store_ is likely to increase memory noticeably.
Can we continue using FakeSymbolTable for IsolatedStoreImpl?
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.
I assume the reason for this is that you've observed that there is no "." structure in the stat names used in those contexts?
In that case I think you are right --- but there may be other contexts with isolated stats where it does make sense. Also right now isolated stores are used in unit tests for code that would otherwise use the main thread local stats store. Switching them to use fake symbol tables makes those tests behave less like prod
I have an in-progress branch to try to add a stats memory test for large numbers of hosts. Maybe I can send you the diff a bit later and you can get it working?
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.
I assume the reason for this is that you've observed that there is no "." structure in the stat names used in those contexts?
In that case I think you are right --- but there may be other contexts with isolated stats where it does make sense. Also right now isolated stores are used in unit tests for code that would otherwise use the main thread local stats store. Switching them to use fake symbol tables makes those tests behave less like prod
I have an in-progress branch to try to add a stats memory test for large numbers of hosts. Maybe I can send you the diff a bit later and you can get it working?
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.
Also @antoniovicente it seems like the better solution is the one you proposed offline -- to make those particular stats just be some atomics and a reference/view to the string-literal name.