userver: userver/congestion_control/component.hpp Source File
Loading...
Searching...
No Matches
component.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/congestion_control/component.hpp
4/// @brief @copybrief congestion_control::Component
5
6#include <userver/components/component_base.hpp>
7#include <userver/dynamic_config/snapshot.hpp>
8#include <userver/server/congestion_control/limiter.hpp>
9#include <userver/server/congestion_control/sensor.hpp>
10#include <userver/utils/fast_pimpl.hpp>
11#include <userver/utils/statistics/entry.hpp>
12
13USERVER_NAMESPACE_BEGIN
14
16
17// clang-format off
18
19/// @ingroup userver_components
20///
21/// @brief Component to limit too active requests, also known as CC.
22///
23/// ## congestion_control::Component Dynamic config
24/// * @ref USERVER_RPS_CCONTROL
25/// * @ref USERVER_RPS_CCONTROL_ENABLED
26///
27/// ## Static options:
28/// Name | Description | Default value
29/// ---- | ----------- | -------------
30/// fake-mode | if set, an actual throttling is skipped, but FSM is still working and producing informational logs | false
31/// min-cpu | force fake-mode if the current cpu number is less than the specified value | 1
32/// only-rtc | if set to true and hostinfo::IsInRtc() returns false then forces the fake-mode | true
33/// status-code | HTTP status code for ratelimited responses | 429
34///
35/// ## Static configuration example:
36///
37/// @snippet components/common_server_component_list_test.cpp Sample congestion control component config
38
39// clang-format on
40
41class Component final : public components::ComponentBase {
42public:
43 /// @ingroup userver_component_names
44 /// @brief The default name of congestion_control::Component component
45 static constexpr std::string_view kName = "congestion-control";
46
47 Component(const components::ComponentConfig&, const components::ComponentContext&);
48
49 ~Component() override;
50
51 static yaml_config::Schema GetStaticConfigSchema();
52
53 server::congestion_control::Limiter& GetServerLimiter();
54 server::congestion_control::Sensor& GetServerSensor();
55
56private:
57 void OnConfigUpdate(const dynamic_config::Snapshot& cfg);
58
59 void OnAllComponentsLoaded() override;
60
61 void OnAllComponentsAreStopping() override;
62
63 void ExtendWriter(utils::statistics::Writer& writer);
64
65 struct Impl;
66 utils::FastPimpl<Impl, 704, 16> pimpl_;
67};
68
69} // namespace congestion_control
70
71template <>
72inline constexpr bool components::kHasValidate<congestion_control::Component> = true;
73
74USERVER_NAMESPACE_END