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);
51 std::uint64_t GetStarted()
const noexcept;
55 utils::statistics::Percentile<2000, std::uint32_t, 256, 100>;
56 using RateCounter = utils::statistics::RateCounter;
59 static constexpr std::size_t kCodesCount =
60 static_cast<std::size_t>(grpc::StatusCode::UNAUTHENTICATED) + 1;
62 RateCounter started_{0};
63 std::array<RateCounter, kCodesCount> status_codes_{};
64 utils::statistics::RecentPeriod<Percentile, Percentile> timings_;
65 RateCounter network_errors_{0};
66 RateCounter internal_errors_{0};
67 RateCounter cancelled_{0};
69 RateCounter deadline_updated_{0};
70 RateCounter deadline_cancelled_{0};
73class ServiceStatistics
final {
75 explicit ServiceStatistics(
const StaticServiceMetadata& metadata);
79 MethodStatistics& GetMethodStatistics(std::size_t method_id);
80 const MethodStatistics& GetMethodStatistics(std::size_t method_id)
const;
82 const StaticServiceMetadata& GetMetadata()
const;
84 std::uint64_t GetStartedRequests()
const;
86 friend void DumpMetric(utils::statistics::Writer& writer,
87 const ServiceStatistics& stats);
90 const StaticServiceMetadata metadata_;
91 utils::FixedArray<MethodStatistics> method_statistics_;