-
Notifications
You must be signed in to change notification settings - Fork 5.5k
api: expose root Stats::Scope via Api::Api #6712
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
Changes from 7 commits
2728a65
03442f8
4887f8f
76025c1
4c1762d
901c211
75737ec
b869872
f4fd945
48e97ee
1b8d010
22e9269
b95f77e
ee59b8f
bfe397a
e369e30
a145485
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 |
|---|---|---|
|
|
@@ -293,7 +293,6 @@ StatType& ThreadLocalStoreImpl::ScopeImpl::safeMakeStat( | |
| StatMap<std::shared_ptr<StatType>>* tls_cache, StatNameHashSet* tls_rejected_stats, | ||
| StatType& null_stat) { | ||
|
|
||
| // We do name-rejections on the full name, prior to truncation. | ||
| if (tls_rejected_stats != nullptr && | ||
| tls_rejected_stats->find(name) != tls_rejected_stats->end()) { | ||
| return null_stat; | ||
|
|
@@ -329,12 +328,62 @@ StatType& ThreadLocalStoreImpl::ScopeImpl::safeMakeStat( | |
| // If we have a TLS cache, insert the stat. | ||
| if (tls_cache) { | ||
| tls_cache->insert(std::make_pair((*central_ref)->statName(), *central_ref)); | ||
| ENVOY_LOG_MISC(debug, "stat added to central cache map"); | ||
| name.debugPrint(); | ||
| ENVOY_LOG_MISC(debug, "central_cache_map = {}", static_cast<void*>(¢ral_cache_map)); | ||
| ENVOY_LOG_MISC(debug, "this = {}", static_cast<const void*>(this)); | ||
| ENVOY_LOG_MISC(debug, "parent_ = {}", static_cast<void*>(&parent_)); | ||
|
ahedberg marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| // Finally we return the reference. | ||
| return **central_ref; | ||
| } | ||
|
|
||
| // TODO(ahedberg): This is largely duplicated from safeMakeStat and should | ||
| // be cleaned up at some point. | ||
|
ahedberg marked this conversation as resolved.
Outdated
|
||
| template <class StatType> | ||
| const StatType* ThreadLocalStoreImpl::ScopeImpl::safeGetStat( | ||
| StatName name, StatMap<std::shared_ptr<StatType>>& central_cache_map, | ||
| StatMap<std::shared_ptr<StatType>>* tls_cache, StatNameHashSet* tls_rejected_stats) const { | ||
|
|
||
| if (tls_rejected_stats != nullptr && | ||
|
ahedberg marked this conversation as resolved.
Outdated
|
||
| tls_rejected_stats->find(name) != tls_rejected_stats->end()) { | ||
| return nullptr; | ||
| } | ||
|
|
||
| // If we have a valid cache entry, return it. | ||
| if (tls_cache) { | ||
|
ahedberg marked this conversation as resolved.
Outdated
|
||
| auto pos = tls_cache->find(name); | ||
| if (pos != tls_cache->end()) { | ||
| return pos->second.get(); | ||
| } | ||
| } | ||
|
|
||
| // We must now look in the central store so we must be locked. We grab a reference to the | ||
| // central store location. It might contain nothing. In this case, we return | ||
| // nullptr. | ||
| // already holding lock in parent | ||
| auto iter = central_cache_map.find(name); | ||
| if (iter == central_cache_map.end()) { | ||
| // The stat doesn't exist in the central store, so return nullptr. | ||
| ENVOY_LOG_MISC(debug, "stat not in central cache map"); | ||
| name.debugPrint(); | ||
| ENVOY_LOG_MISC(debug, "central_cache_map = {}", static_cast<void*>(¢ral_cache_map)); | ||
| ENVOY_LOG_MISC(debug, "this = {}", static_cast<const void*>(this)); | ||
| ENVOY_LOG_MISC(debug, "parent_ = {}", static_cast<void*>(&parent_)); | ||
| return nullptr; | ||
| } | ||
|
|
||
| std::shared_ptr<StatType>* central_ref = &(iter->second); | ||
| // If we have a TLS cache, insert the stat. | ||
| if (tls_cache) { | ||
|
Contributor
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 think you indicated 'done' in the comment I made earlier suggesting we not bother with the tls cache, since you are holding a lock anyway. I see you are no longer reading from it, but I'm not sure that usage of the 'find' method is a good signal that we should populate the current thread's cache. In particular -- not really fully understanding the application -- I was wondering if this might tend to be run from the main thread, whose tls cache will (I believe) be consulted approximately never. @mattklein123 & @fredlas for opinions on this.
Contributor
Author
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. Ah, I see--I think I misunderstood a previous conversation that we should populate the tls cache upon reading. I don't feel strongly either way. We're planning on calling this from a filter, similar to eds_ready_filter.cc, if that changes anyone else's opinions. |
||
| tls_cache->insert(std::make_pair((*central_ref)->statName(), *central_ref)); | ||
| } | ||
|
|
||
| // Finally we return the pointer to the stat. | ||
| return central_ref->get(); | ||
| } | ||
|
|
||
| Counter& ThreadLocalStoreImpl::ScopeImpl::counterFromStatName(StatName name) { | ||
| if (parent_.rejectsAll()) { | ||
| return parent_.null_counter_; | ||
|
|
@@ -473,6 +522,87 @@ Histogram& ThreadLocalStoreImpl::ScopeImpl::histogramFromStatName(StatName name) | |
| return **central_ref; | ||
| } | ||
|
|
||
| const Counter* ThreadLocalStoreImpl::ScopeImpl::getCounter(StatName name) const { | ||
| if (parent_.rejectsAll()) { | ||
|
ahedberg marked this conversation as resolved.
Outdated
|
||
| return nullptr; | ||
| } | ||
|
|
||
| // See comments in counter(). There is no super clean way (via templates or otherwise) to | ||
| // share this code so I'm leaving it largely duplicated for now. | ||
| Stats::SymbolTable::StoragePtr final_name = symbolTable().join({prefix_.statName(), name}); | ||
| StatName final_stat_name(final_name.get()); | ||
|
|
||
| StatMap<CounterSharedPtr>* tls_cache = nullptr; | ||
| StatNameHashSet* tls_rejected_stats = nullptr; | ||
| if (!parent_.shutting_down_ && parent_.tls_) { | ||
| TlsCacheEntry& entry = parent_.tls_->getTyped<TlsCache>().scope_cache_[this->scope_id_]; | ||
| tls_cache = &entry.counters_; | ||
| tls_rejected_stats = &entry.rejected_stats_; | ||
| } | ||
|
|
||
| return safeGetStat<Counter>(final_stat_name, central_cache_.counters_, tls_cache, | ||
| tls_rejected_stats); | ||
| } | ||
|
|
||
| const Gauge* ThreadLocalStoreImpl::ScopeImpl::getGauge(StatName name) const { | ||
| if (parent_.rejectsAll()) { | ||
| return nullptr; | ||
| } | ||
|
|
||
| // See comments in counter(). There is no super clean way (via templates or otherwise) to | ||
| // share this code so I'm leaving it largely duplicated for now. | ||
| Stats::SymbolTable::StoragePtr final_name = symbolTable().join({prefix_.statName(), name}); | ||
| StatName final_stat_name(final_name.get()); | ||
|
|
||
| StatMap<GaugeSharedPtr>* tls_cache = nullptr; | ||
| StatNameHashSet* tls_rejected_stats = nullptr; | ||
| if (!parent_.shutting_down_ && parent_.tls_) { | ||
| TlsCacheEntry& entry = parent_.tls_->getTyped<TlsCache>().scope_cache_[this->scope_id_]; | ||
| tls_cache = &entry.gauges_; | ||
| tls_rejected_stats = &entry.rejected_stats_; | ||
| } | ||
|
|
||
| return safeGetStat<Gauge>(final_stat_name, central_cache_.gauges_, tls_cache, tls_rejected_stats); | ||
| } | ||
|
|
||
| const Histogram* ThreadLocalStoreImpl::ScopeImpl::getHistogram(StatName name) const { | ||
| if (parent_.rejectsAll()) { | ||
| return nullptr; | ||
| } | ||
|
|
||
| // See comments in counter(). There is no super clean way (via templates or otherwise) to | ||
| // share this code so I'm leaving it largely duplicated for now. | ||
| Stats::SymbolTable::StoragePtr final_name = symbolTable().join({prefix_.statName(), name}); | ||
| StatName final_stat_name(final_name.get()); | ||
|
|
||
| StatMap<ParentHistogramSharedPtr>* tls_cache = nullptr; | ||
| StatNameHashSet* tls_rejected_stats = nullptr; | ||
| if (!parent_.shutting_down_ && parent_.tls_) { | ||
| TlsCacheEntry& entry = parent_.tls_->getTyped<TlsCache>().scope_cache_[this->scope_id_]; | ||
| tls_cache = &entry.parent_histograms_; | ||
| auto iter = tls_cache->find(final_stat_name); | ||
| if (iter != tls_cache->end()) { | ||
| return iter->second.get(); | ||
| } | ||
| tls_rejected_stats = &entry.rejected_stats_; | ||
| if (tls_rejected_stats->find(final_stat_name) != tls_rejected_stats->end()) { | ||
| return nullptr; | ||
| } | ||
| } | ||
|
|
||
| auto iter = central_cache_.histograms_.find(final_stat_name); | ||
| ParentHistogramImplSharedPtr* central_ref = nullptr; | ||
| if (iter == central_cache_.histograms_.end()) { | ||
| return nullptr; | ||
| } | ||
|
|
||
| central_ref = &iter->second; | ||
| if (tls_cache != nullptr) { | ||
| tls_cache->insert(std::make_pair((*central_ref)->statName(), *central_ref)); | ||
| } | ||
| return central_ref->get(); | ||
| } | ||
|
|
||
| Histogram& ThreadLocalStoreImpl::ScopeImpl::tlsHistogram(StatName name, | ||
| ParentHistogramImpl& parent) { | ||
| // tlsHistogram() is generally not called for a histogram that is rejected by | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.