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