9#include <grpcpp/support/status.h>
11#include <userver/utils/fixed_array.hpp>
12#include <userver/utils/statistics/fwd.hpp>
13#include <userver/utils/statistics/percentile.hpp>
14#include <userver/utils/statistics/rate_counter.hpp>
15#include <userver/utils/statistics/recentperiod.hpp>
17#include <userver/ugrpc/impl/static_metadata.hpp>
19USERVER_NAMESPACE_BEGIN
21namespace ugrpc::impl {
23class MethodStatistics
final {
27 void AccountStarted()
noexcept;
29 void AccountStatus(grpc::StatusCode code)
noexcept;
31 void AccountTiming(std::chrono::milliseconds timing)
noexcept;
35 void AccountNetworkError()
noexcept;
40 void AccountInternalError()
noexcept;
42 void AccountCancelledByDeadlinePropagation()
noexcept;
44 void AccountDeadlinePropagated()
noexcept;
46 void AccountCancelled()
noexcept;
48 friend void DumpMetric(
utils::statistics::Writer& writer,
49 const MethodStatistics& stats);
53 utils::statistics::Percentile<2000, std::uint32_t, 256, 100>;
54 using RateCounter =
utils::statistics::RateCounter;
57 static constexpr std::size_t kCodesCount =
58 static_cast<std::size_t>(grpc::StatusCode::UNAUTHENTICATED) + 1;
60 RateCounter started_{0};
61 std::array<RateCounter, kCodesCount> status_codes_{};
62 utils::statistics::RecentPeriod<Percentile, Percentile> timings_;
63 RateCounter network_errors_{0};
64 RateCounter internal_errors_{0};
65 RateCounter cancelled_{0};
67 RateCounter deadline_updated_{0};
68 RateCounter deadline_cancelled_{0};
71class ServiceStatistics
final {
73 explicit ServiceStatistics(
const StaticServiceMetadata& metadata);
77 MethodStatistics& GetMethodStatistics(std::size_t method_id);
78 const MethodStatistics& GetMethodStatistics(std::size_t method_id)
const;
80 const StaticServiceMetadata& GetMetadata()
const;
82 friend void DumpMetric(
utils::statistics::Writer& writer,
83 const ServiceStatistics& stats);
86 const StaticServiceMetadata metadata_;
87 utils::FixedArray<MethodStatistics> method_statistics_;