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/loggable_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/// ## 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::LoggableComponentBase {
42 public:
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&,
48 const components::ComponentContext&);
49
50 ~Component() override;
51
52 static yaml_config::Schema GetStaticConfigSchema();
53
54 server::congestion_control::Limiter& GetServerLimiter();
55 server::congestion_control::Sensor& GetServerSensor();
56
57 private:
58 void OnConfigUpdate(const dynamic_config::Snapshot& cfg);
59
60 void OnAllComponentsLoaded() override;
61
62 void OnAllComponentsAreStopping() override;
63
64 void ExtendWriter(utils::statistics::Writer& writer);
65
66 struct Impl;
67 utils::FastPimpl<Impl, 664, 8> pimpl_;
68};
69
70} // namespace congestion_control
71
72template <>
73inline constexpr bool components::kHasValidate<congestion_control::Component> =
74 true;
75
76USERVER_NAMESPACE_END