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