Skip to content

Commit 4102c3a

Browse files
committed
cc core: use scope API for metrics
commit_hash:23fa892e2601460358be4dc5470d51e72ac7b4f9
1 parent 1a03cac commit 4102c3a

File tree

19 files changed

+35
-78
lines changed

19 files changed

+35
-78
lines changed

core/include/userver/cache/lru_cache_component_base.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace cache {
2424

2525
namespace impl {
2626

27-
utils::statistics::Entry RegisterOnStatisticsStorage(
27+
void RegisterOnStatisticsStorage(
2828
const components::ComponentContext& context,
2929
const std::string& name,
3030
std::function<void(utils::statistics::Writer&)> func
@@ -107,7 +107,6 @@ class LruCacheComponent : public components::ComponentBase, private dump::Dumpab
107107

108108
// Subscriptions must be the last fields.
109109
concurrent::AsyncEventSubscriberScope config_subscription_;
110-
utils::statistics::Entry statistics_holder_;
111110
testsuite::CacheResetRegistration reset_registration_;
112111
// See the comment above before adding a new field.
113112
};
@@ -145,17 +144,14 @@ LruCacheComponent<
145144
LOG_INFO() << "Dynamic LRU cache config is disabled, cache=" << name_;
146145
}
147146

148-
statistics_holder_ = impl::RegisterOnStatisticsStorage(context, name_, [this](utils::statistics::Writer& writer) {
149-
writer = *cache_;
150-
});
147+
impl::RegisterOnStatisticsStorage(context, name_, [this](utils::statistics::Writer& writer) { writer = *cache_; });
151148

152149
reset_registration_ = testsuite::RegisterCache(context, this, &LruCacheComponent::DropCache);
153150
}
154151

155152
template <typename Key, typename Value, typename Hash, typename Equal>
156153
LruCacheComponent<Key, Value, Hash, Equal>::~LruCacheComponent() {
157154
reset_registration_.Unregister();
158-
statistics_holder_.Unregister();
159155
config_subscription_.Unsubscribe();
160156

161157
if (dumper_) {

core/include/userver/clients/dns/component.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class Component final : public components::ComponentBase {
3838
void Write(utils::statistics::Writer& writer);
3939

4040
Resolver resolver_;
41-
utils::statistics::Entry statistics_holder_;
4241
};
4342

4443
} // namespace clients::dns

core/include/userver/clients/http/component_core.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ class HttpClientCore final : public ComponentBase {
7171
const bool disable_pool_stats_;
7272
std::shared_ptr<clients::http::ClientCore> http_client_;
7373
concurrent::AsyncEventSubscriberScope subscriber_scope_;
74-
utils::statistics::Entry statistics_holder_;
7574
};
7675

7776
template <>

core/include/userver/components/manager_controller_component.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ class ManagerControllerComponent final : public RawComponentBase {
9292
void OnConfigUpdate(const dynamic_config::Snapshot& cfg);
9393

9494
const components::impl::Manager& components_manager_;
95-
utils::statistics::Entry statistics_holder_;
9695
concurrent::AsyncEventSubscriberScope config_subscription_;
9796
};
9897

core/include/userver/logging/component.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <userver/rcu/rcu_map.hpp>
1515
#include <userver/utils/fast_pimpl.hpp>
1616
#include <userver/utils/periodic_task.hpp>
17-
#include <userver/utils/statistics/entry.hpp>
17+
#include <userver/utils/statistics/metrics_storage.hpp>
1818
#include <userver/utils/statistics/writer.hpp>
1919

2020
#include "logger.hpp"
@@ -139,7 +139,6 @@ class Logging final : public RawComponentBase {
139139

140140
// Subscriptions must be the last fields.
141141
os_signals::Subscriber signal_subscriber_;
142-
utils::statistics::Entry statistics_holder_;
143142
};
144143

145144
template <>

core/include/userver/server/handlers/http_handler_base.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#include <userver/dynamic_config/source.hpp>
1212
#include <userver/logging/level.hpp>
13-
#include <userver/utils/statistics/entry.hpp>
1413
#include <userver/utils/token_bucket.hpp>
1514

1615
#include <userver/server/handlers/exceptions.hpp>
@@ -214,7 +213,6 @@ class HttpHandlerBase : public HandlerBase {
214213
const dynamic_config::Source config_source_;
215214
const std::vector<http::HttpMethod> allowed_methods_;
216215
const std::string handler_name_;
217-
utils::statistics::Entry statistics_holder_;
218216
std::optional<logging::Level> log_level_;
219217
std::unordered_map<int, logging::Level> log_level_for_status_codes_;
220218

core/include/userver/server/websocket/websocket_handler.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ class WebsocketHandlerBase : public server::handlers::HttpHandlerBase {
6868

6969
websocket::Config config_;
7070
mutable Statistics stats_;
71-
utils::statistics::Entry statistics_holder_;
7271
};
7372

7473
} // namespace server::websocket

core/include/userver/utils/statistics/system_statistics_collector.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <userver/concurrent/variable.hpp>
99
#include <userver/engine/task/task_processor_fwd.hpp>
1010
#include <userver/utils/periodic_task.hpp>
11-
#include <userver/utils/statistics/entry.hpp>
1211
#include <utils/statistics/system_statistics.hpp>
1312

1413
USERVER_NAMESPACE_BEGIN
@@ -37,7 +36,6 @@ class SystemStatisticsCollector final : public ComponentBase {
3736
static constexpr std::string_view kName = "system-statistics-collector";
3837

3938
SystemStatisticsCollector(const ComponentConfig&, const ComponentContext&);
40-
~SystemStatisticsCollector() override;
4139

4240
static yaml_config::Schema GetStaticConfigSchema();
4341

@@ -53,7 +51,6 @@ class SystemStatisticsCollector final : public ComponentBase {
5351

5452
const bool with_nginx_;
5553
engine::TaskProcessor& fs_task_processor_;
56-
utils::statistics::Entry statistics_holder_;
5754
concurrent::Variable<Data> data_;
5855
utils::PeriodicTask periodic_;
5956
};

core/src/cache/lru_cache_component_base.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@ USERVER_NAMESPACE_BEGIN
1717

1818
namespace cache::impl {
1919

20-
utils::statistics::Entry RegisterOnStatisticsStorage(
20+
void RegisterOnStatisticsStorage(
2121
const components::ComponentContext& context,
2222
const std::string& name,
2323
std::function<void(utils::statistics::Writer&)> func
2424
) {
25-
return context.FindComponent<components::StatisticsStorage>()
26-
.GetStorage()
27-
.RegisterWriter("cache", std::move(func), {{"cache_name", name}});
25+
utils::statistics::RegisterWriterScope(context, "cache", std::move(func), {{"cache_name", name}});
2826
}
2927

3028
dynamic_config::Source FindDynamicConfigSource(const components::ComponentContext& context) {

core/src/clients/dns/component.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ Component::Component(const components::ComponentConfig& config, const components
1818
: ComponentBase{config, context},
1919
resolver_{GetFsTaskProcessor(config, context), config.As<::userver::static_config::DnsClient>()}
2020
{
21-
auto& storage = context.FindComponent<components::StatisticsStorage>().GetStorage();
22-
statistics_holder_ = storage.RegisterWriter(config.Name() + ".replies", [this](auto& writer) { Write(writer); });
21+
utils::statistics::RegisterWriterScope(context, config.Name() + ".replies", [this](auto& writer) {
22+
Write(writer);
23+
});
2324
}
2425

2526
Resolver& Component::GetResolver() { return resolver_; }

0 commit comments

Comments
 (0)