-
Notifications
You must be signed in to change notification settings - Fork 5.3k
stat: Add counterFromStatName(), gaugeFromStatName(), and histogramFromStatName() #6475
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
47e7937
Add counterFromStatName etc into the Store and Scope interface.
jmarantz 9cda4f9
add new files
jmarantz 4f086c3
Add tests for new counterFromStatName() methods.
jmarantz b6e3584
Add tests for new methods.
jmarantz 9c9b9b2
Address review comments.
jmarantz 4ba840f
Merge branch 'master' into stat-from-stat-name
jmarantz c037425
Remove speculative generality on memory management of ScopePrefixer's…
jmarantz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #include "common/stats/scope_prefixer.h" | ||
|
|
||
| #include "envoy/stats/scope.h" | ||
|
|
||
| #include "common/stats/symbol_table_impl.h" | ||
| #include "common/stats/utility.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Stats { | ||
|
|
||
| ScopePrefixer::ScopePrefixer(absl::string_view prefix, Scope& scope) | ||
| : prefix_(Utility::sanitizeStatsName(prefix)), scope_(scope) {} | ||
|
|
||
| ScopePtr ScopePrefixer::createScope(const std::string& name) { | ||
| return std::make_unique<ScopePrefixer>(prefix_ + name, scope_); | ||
| } | ||
|
|
||
| Counter& ScopePrefixer::counterFromStatName(StatName name) { | ||
| return counter(symbolTable().toString(name)); | ||
| } | ||
|
|
||
| Gauge& ScopePrefixer::gaugeFromStatName(StatName name) { | ||
| return gauge(symbolTable().toString(name)); | ||
| } | ||
|
|
||
| Histogram& ScopePrefixer::histogramFromStatName(StatName name) { | ||
| return histogram(symbolTable().toString(name)); | ||
| } | ||
|
|
||
| void ScopePrefixer::deliverHistogramToSinks(const Histogram& histograms, uint64_t val) { | ||
| scope_.deliverHistogramToSinks(histograms, val); | ||
| } | ||
|
|
||
| } // namespace Stats | ||
| } // namespace Envoy | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| #include "envoy/stats/scope.h" | ||
|
|
||
| #include "common/stats/symbol_table_impl.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Stats { | ||
|
|
||
| // Implements a Scope that delegates to a passed-in scope, prefixing all names | ||
| // prior to creation. | ||
| class ScopePrefixer : public Scope { | ||
| public: | ||
| ScopePrefixer(absl::string_view prefix, Scope& scope); | ||
|
|
||
| // Scope | ||
| ScopePtr createScope(const std::string& name) override; | ||
| Counter& counter(const std::string& name) override { return scope_.counter(prefix_ + name); } | ||
| Gauge& gauge(const std::string& name) override { return scope_.gauge(prefix_ + name); } | ||
| Histogram& histogram(const std::string& name) override { | ||
| return scope_.histogram(prefix_ + name); | ||
| } | ||
| void deliverHistogramToSinks(const Histogram& histograms, uint64_t val) override; | ||
| Counter& counterFromStatName(StatName name) override; | ||
| Gauge& gaugeFromStatName(StatName name) override; | ||
| Histogram& histogramFromStatName(StatName name) override; | ||
|
|
||
| const Stats::StatsOptions& statsOptions() const override { return scope_.statsOptions(); } | ||
| const SymbolTable& symbolTable() const override { return scope_.symbolTable(); } | ||
| virtual SymbolTable& symbolTable() override { return scope_.symbolTable(); } | ||
|
|
||
| NullGaugeImpl& nullGauge(const std::string& str) override { return scope_.nullGauge(str); } | ||
|
|
||
| private: | ||
| std::string prefix_; | ||
| Scope& scope_; | ||
| }; | ||
|
|
||
| } // namespace Stats | ||
| } // namespace Envoy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #pragma once | ||
|
|
||
| #include "envoy/stats/stats.h" | ||
| #include "envoy/stats/store.h" | ||
|
|
||
| #include "common/stats/symbol_table_impl.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Stats { | ||
|
|
||
| /** | ||
| * Implements common parts of the Store API needed by multiple derivations of Store. | ||
| */ | ||
| class StoreImpl : public Store { | ||
| public: | ||
| explicit StoreImpl(SymbolTable& symbol_table) : symbol_table_(symbol_table) {} | ||
|
|
||
| Counter& counterFromStatName(StatName name) override { | ||
| return counter(symbol_table_.toString(name)); | ||
| } | ||
|
|
||
| Gauge& gaugeFromStatName(StatName name) override { return gauge(symbol_table_.toString(name)); } | ||
|
|
||
| Histogram& histogramFromStatName(StatName name) override { | ||
| return histogram(symbol_table_.toString(name)); | ||
| } | ||
|
|
||
| SymbolTable& symbolTable() override { return symbol_table_; } | ||
| const SymbolTable& symbolTable() const override { return symbol_table_; } | ||
|
|
||
| private: | ||
| SymbolTable& symbol_table_; | ||
| }; | ||
|
|
||
| } // namespace Stats | ||
| } // namespace Envoy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 don't see this variant used, is it used in a follow up?
Also, somewhat nitty, but for clarity I would prefer a single constructor that looks like:
And then personally I would have the following members:
And avoid the manual deletion. WDYT?
Uh oh!
There was an error while loading. Please reload this page.
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.
Yeah I like your pattern better. However I also can't justify the speculative generality here; I needed it in some past iteration and don't see a use-case now. If I have to add it back in the future I'll use your pattern.
update coming.