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