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/raw_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 RawComponentBase {
33public:
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, const ComponentContext& context);
39
40 ~StatisticsStorage() override;
41
42 void OnAllComponentsLoaded() override;
43
44 utils::statistics::Storage& GetStorage() { return storage_; }
45
46 const utils::statistics::Storage& GetStorage() const { return storage_; }
47
48 utils::statistics::MetricsStoragePtr GetMetricsStorage() { return metrics_storage_; }
49
50 static yaml_config::Schema GetStaticConfigSchema();
51
52private:
53 utils::statistics::Storage storage_;
54 utils::statistics::MetricsStoragePtr metrics_storage_;
55 std::vector<utils::statistics::Entry> metrics_storage_registration_;
56};
57
58template <>
59inline constexpr bool kHasValidate<StatisticsStorage> = true;
60
61template <>
62inline constexpr auto kConfigFileMode<StatisticsStorage> = ConfigFileMode::kNotRequired;
63
64} // namespace components
65
66USERVER_NAMESPACE_END