9#include <userver/formats/json_fwd.hpp>
10#include <userver/formats/parse/to.hpp>
11#include <userver/utils/statistics/rate_counter.hpp>
13USERVER_NAMESPACE_BEGIN
21struct RetryBudgetSettings
final {
23 float max_tokens{100.0f};
26 float token_ratio{0.1f};
33class RetryBudget
final {
36 explicit RetryBudget(
const RetryBudgetSettings& settings);
53 friend void DumpMetric(statistics::Writer& writer,
const RetryBudget& budget);
55 std::atomic<std::uint32_t> max_tokens_;
56 std::atomic<std::uint32_t> token_ratio_;
57 std::atomic<std::int32_t> token_count_;
58 std::atomic<
bool> enabled_{
false};
61 utils::statistics::RateCounter ok_rate_counter_;
63 utils::statistics::RateCounter fail_rate_counter_;