userver: userver/components/statistics_storage.hpp Source File
Loading...
Searching...
No Matches
statistics_storage.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/components/statistics_storage.hpp
4/// @brief @copybrief components::StatisticsStorage
5
6#include <userver/components/component_fwd.hpp>
7#include <userver/components/impl/component_base.hpp>
8#include <userver/utils/statistics/metrics_storage.hpp>
9#include <userver/utils/statistics/storage.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace components {
14
15// clang-format off
16
17/// @ingroup userver_components
18///
19/// @brief Component that keeps a utils::statistics::Storage storage for
20/// metrics.
21///
22/// Returned references to utils::statistics::Storage live for a lifetime
23/// of the component and are safe for concurrent use.
24///
25/// The component does **not** have any options for service config.
26///
27/// ## Static configuration example:
28///
29/// @snippet components/common_component_list_test.cpp Sample statistics storage component config
30
31// clang-format on
32class StatisticsStorage final : public impl::ComponentBase {
33 public:
34 /// @ingroup userver_component_names
35 /// @brief The default name of components::StatisticsStorage component
36 static constexpr std::string_view kName = "statistics-storage";
37
38 StatisticsStorage(const ComponentConfig& config,
39 const ComponentContext& context);
40
41 ~StatisticsStorage() override;
42
43 void OnAllComponentsLoaded() override;
44
45 utils::statistics::Storage& GetStorage() { return storage_; }
46
47 const utils::statistics::Storage& GetStorage() const { return storage_; }
48
49 utils::statistics::MetricsStoragePtr GetMetricsStorage() {
50 return metrics_storage_;
51 }
52
53 static yaml_config::Schema GetStaticConfigSchema();
54
55 private:
56 utils::statistics::Storage storage_;
57 utils::statistics::MetricsStoragePtr metrics_storage_;
58 std::vector<utils::statistics::Entry> metrics_storage_registration_;
59};
60
61template <>
62inline constexpr bool kHasValidate<StatisticsStorage> = true;
63
64template <>
65inline constexpr auto kConfigFileMode<StatisticsStorage> =
67
68} // namespace components
69
70USERVER_NAMESPACE_END