10#include <userver/utils/statistics/histogram_view.hpp>
11#include <userver/utils/statistics/rate.hpp>
13USERVER_NAMESPACE_BEGIN
15namespace utils::statistics {
20class MetricValue
final {
22 using RawType = std::variant<std::int64_t,
double,
Rate, HistogramView>;
31 constexpr MetricValue(
double value)
noexcept : value_(value) {}
33 constexpr MetricValue(
Rate value)
noexcept : value_(value) {}
35 constexpr MetricValue(HistogramView value)
noexcept : value_(value) {}
39 MetricValue(
const MetricValue&) =
default;
40 MetricValue& operator=(
const MetricValue&) =
default;
42 friend bool operator==(
const MetricValue& lhs,
const MetricValue& rhs)
noexcept {
return lhs.value_ == rhs.value_; }
44 friend bool operator!=(
const MetricValue& lhs,
const MetricValue& rhs)
noexcept {
return lhs.value_ != rhs.value_; }
48 std::int64_t
AsInt()
const {
return std::get<std::int64_t>(value_); }
52 double AsFloat()
const {
return std::get<
double>(value_); }
59 bool IsRate()
const noexcept {
return std::holds_alternative<Rate>(value_); }
63 HistogramView
AsHistogram()
const {
return std::get<HistogramView>(value_); }
66 bool IsHistogram()
const noexcept {
return std::holds_alternative<HistogramView>(value_); }
70 template <
typename VisitorFunc>
71 decltype(
auto)
Visit(VisitorFunc visitor)
const {
72 return std::visit(visitor, value_);
76 explicit MetricValue(RawType value)
noexcept : value_(value) {}