13#include <fmt/format.h>
15#include <userver/utils/fmt_compat.hpp>
16#include <userver/utils/overloaded.hpp>
17#include <userver/utils/statistics/labels.hpp>
18#include <userver/utils/statistics/metric_value.hpp>
19#include <userver/utils/statistics/rate.hpp>
22struct fmt::formatter<USERVER_NAMESPACE::utils::statistics::LabelView> {
23 constexpr static auto parse(format_parse_context& ctx) {
return ctx.begin(); }
25 template <
typename FormatContext>
26 auto format(USERVER_NAMESPACE::utils::statistics::LabelView value,
28 return fmt::format_to(ctx.out(),
"{}={}", value.Name(), value.Value());
33struct fmt::formatter<USERVER_NAMESPACE::utils::statistics::Label>
34 :
public fmt::formatter<USERVER_NAMESPACE::utils::statistics::LabelView> {
35 template <
typename FormatContext>
36 auto format(
const USERVER_NAMESPACE::utils::statistics::Label& value,
38 return formatter<USERVER_NAMESPACE::utils::statistics::LabelView>::format(
39 USERVER_NAMESPACE::utils::statistics::LabelView{value}, ctx);
44struct fmt::formatter<USERVER_NAMESPACE::utils::statistics::LabelsSpan> {
45 constexpr static auto parse(format_parse_context& ctx) {
return ctx.begin(); }
47 template <
typename FormatContext>
48 auto format(USERVER_NAMESPACE::utils::statistics::LabelsSpan value,
50 return fmt::format_to(ctx.out(),
"{}", fmt::join(value,
";"));
55class fmt::formatter<USERVER_NAMESPACE::utils::statistics::Rate> {
57 constexpr auto parse(format_parse_context& ctx) {
58 return rate_format_.parse(ctx);
61 template <
typename FormatCtx>
62 auto format(
const USERVER_NAMESPACE::utils::statistics::Rate& rate,
64 return rate_format_.format(rate.value, ctx);
68 fmt::formatter<USERVER_NAMESPACE::utils::statistics::Rate::ValueType>
73class fmt::formatter<USERVER_NAMESPACE::utils::statistics::MetricValue> {
75 constexpr auto parse(format_parse_context& ctx) {
77 const auto max = [](
auto a,
auto b) {
return a > b ? a : b; };
78 return max(int_format_.parse(ctx),
79 max(float_format_.parse(ctx), rate_format_.parse(ctx)));
82 template <
typename FormatContext>
83 auto format(USERVER_NAMESPACE::utils::statistics::MetricValue value,
85 return value.Visit(USERVER_NAMESPACE::utils::Overloaded{
86 [&](std::int64_t x) {
return int_format_.format(x, ctx); },
87 [&](USERVER_NAMESPACE::utils::statistics::Rate x) {
88 return rate_format_.format(x.value, ctx);
90 [&](
double x) {
return float_format_.format(x, ctx); }});
94 fmt::formatter<std::int64_t> int_format_;
95 fmt::formatter<USERVER_NAMESPACE::utils::statistics::Rate::ValueType>
97 fmt::formatter<
double> float_format_;