8#include <initializer_list>
11#include <unordered_map>
15#include <userver/engine/shared_mutex.hpp>
16#include <userver/formats/json/value_builder.hpp>
17#include <userver/utils/assert.hpp>
18#include <userver/utils/statistics/entry.hpp>
19#include <userver/utils/statistics/metric_value.hpp>
20#include <userver/utils/statistics/writer.hpp>
22USERVER_NAMESPACE_BEGIN
24namespace utils::statistics {
27struct StatisticsRequest
final {};
44 using AddLabels = std::unordered_map<std::string, std::string>;
52 AddLabels add_labels = {},
53 std::vector<Label> require_labels = {});
57 AddLabels add_labels = {},
58 std::vector<Label> require_labels = {});
80 Request(std::string prefix_in,
PrefixMatch path_match_type_in,
81 std::vector<Label> require_labels_in, AddLabels add_labels_in);
85 std::function<formats::
json::ValueBuilder(
const StatisticsRequest&)>;
87using WriterFunc = std::function<
void(Writer&)>;
91struct MetricsSource
final {
92 std::string prefix_path;
93 std::vector<std::string> path_segments;
94 ExtenderFunc extender;
97 std::vector<Label> writer_labels;
100using StorageData = std::list<MetricsSource>;
101using StorageIterator = StorageData::iterator;
103inline constexpr bool kCheckSubscriptionUB = utils::impl::kEnableAssert;
109 virtual ~BaseFormatBuilder();
111 virtual void HandleMetric(std::string_view path, LabelsSpan labels,
112 const MetricValue& value) = 0;
124 Storage(
const Storage&) =
delete;
138 void StopRegisteringExtenders();
144 std::vector<Label> add_labels = {});
149 void UnregisterExtender(impl::StorageIterator iterator,
150 impl::UnregisteringKind kind)
noexcept;
153 Entry DoRegisterExtender(impl::MetricsSource&& source);
155 std::atomic<
bool> may_register_extenders_;
156 impl::StorageData metrics_sources_;
157 mutable engine::SharedMutex mutex_;