userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
v2.hpp
Go to the documentation of this file.
1
#pragma once
2
5
6
#include <atomic>
7
#include <optional>
8
9
#include <
userver/congestion_control/limiter.hpp
>
10
#include <
userver/congestion_control/sensor.hpp
>
11
#include <
userver/utils/periodic_task.hpp
>
12
#include <
userver/utils/statistics/fwd.hpp
>
13
#include <
userver/utils/statistics/rate_counter.hpp
>
14
15
USERVER_NAMESPACE_BEGIN
16
17
namespace
congestion_control::v2 {
18
19
struct
Stats
{
20
std::atomic<bool> is_enabled{
false
};
21
std::atomic<bool> is_fake_mode{
false
};
22
std::atomic<int64_t> current_limit{0};
23
utils::statistics::RateCounter
enabled_epochs{};
24
};
25
26
void
DumpMetric(
utils::statistics::Writer
& writer,
const
Stats
& stats);
27
28
class
Controller {
29
public
:
30
struct
Config
{
31
bool
fake_mode{
false
};
32
bool
enabled{
true
};
33
};
34
35
Controller(
const
std::string& name,
v2::Sensor
& sensor,
Limiter
& limiter,
Stats
& stats,
const
Config
& config);
36
37
virtual
~Controller() =
default
;
38
39
void
Start();
40
void
Stop();
41
42
void
Step();
43
44
const
std::string& GetName()
const
;
45
46
void
SetEnabled(
bool
enabled);
47
48
protected
:
49
struct
LimitWithDetails
{
50
Limit
limit;
51
std::optional<std::string> sensor_details;
52
};
53
54
virtual
LimitWithDetails
Update(
const
v2::Sensor::Data
& data) = 0;
55
56
// NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
57
std::optional<size_t> current_limit_;
58
59
private
:
60
std::string_view LogFakeMode()
const
;
61
62
const
std::string name_;
63
Sensor
& sensor_;
64
congestion_control::Limiter
& limiter_;
65
Stats
& stats_;
66
const
Config
config_;
67
USERVER_NAMESPACE::utils::PeriodicTask periodic_;
68
std::atomic<bool> enabled_{
true
};
69
};
70
71
}
// namespace congestion_control::v2
72
73
USERVER_NAMESPACE_END
userver
congestion_control
controllers
v2.hpp
Generated on
for userver by
Doxygen
1.17.0