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/// @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 of congestion_control::Component :
28/// @include{doc} scripts/docs/en/components_schema/core/src/congestion_control/component.md
29///
30/// Options inherited from @ref components::ComponentBase :
31/// @include{doc} scripts/docs/en/components_schema/core/src/components/impl/component_base.md
32///
33/// ## Static configuration example:
34///
35/// @snippet components/common_server_component_list_test.cpp Sample congestion control component config
36class Component final : public components::ComponentBase {
37public:
38 /// @ingroup userver_component_names
39 /// @brief The default name of @ref congestion_control::Component component
40 static constexpr std::string_view kName = "congestion-control";
41
42 Component(const components::ComponentConfig&, const components::ComponentContext&);
43
44 ~Component() override;
45
46 static yaml_config::Schema GetStaticConfigSchema();
47
48 server::congestion_control::Limiter& GetServerLimiter();
49 server::congestion_control::Sensor& GetServerSensor();
50 const congestion_control::Controller& GetServerController() const;
51
52private:
53 void OnConfigUpdate(const dynamic_config::Snapshot& cfg);
54
55 void OnAllComponentsLoaded() override;
56
57 void OnAllComponentsAreStopping() override;
58
59 void ExtendWriter(utils::statistics::Writer& writer);
60
61 struct Impl;
62 utils::FastPimpl<Impl, 704, 16> pimpl_;
63};
64
65} // namespace congestion_control
66
67template <>
68inline constexpr bool components::kHasValidate<congestion_control::Component> = true;
69
70USERVER_NAMESPACE_END