Commit 0a2cabc
smorivan
feat core: use separate http client plugins list for dynamic configs
Several changes are made in order to support dynamic config subscription in http client plugins:
1. Plugins are renamed to middlewares
2. Middlewares static configuration for @ref clients::HttpClient is updated to be more like @ref scripts/docs/en/userver/grpc/client\_middlewares.md
3. @ref clients::http::MiddlewarePipelineComponent are introduced to manage common middlewares settings
4. Dynamic configs use separate @ref clients::HttpClient instance named `dynamic-config-http-client`, so that middlewares that use dynamic configs may be disabled just for dynamic configs client and enabled for all other clients in `http-client-middleware-pipeline.middlewares`
Migration guide:
1. Make sure that you use `.AppendComponentList(clients::http::ComponentList())` in your component list instead of `.Append<components::HttpClientCore>().Append<components::HttpClient>()`
2. For classes inherited from @ref tracing::TracingManagerBase:
1. Change @ref clients::http::PluginRequest in @ref tracing::TracingManagerBase::FillRequestWithTracingContext() parameters to @ref clients::http::MiddlewareRequest
3. For classes inherited from @ref clients::http::Plugin:
1. Replace `#include <userver/clients/http/plugin.hpp>` with `#include <userver/clients/http/middlewares/base.hpp>`
2. Change base class to @ref clients::http::MiddlewareBase
3. Change @ref clients::http::PluginRequest in methods parameters to @ref clients::http::MiddlewareRequest
4. Stop passing middleware name to base class constructor
5. Empty methods implementations (or `return true;` for @ref clients::http::MiddlewareBase::HookOnRetry()) may be omitted
For example:
```diff
-#include <userver/clients/http/plugin.hpp>
+#include <userver/clients/http/middlewares/base.hpp>
...
-class MyPlugin : public clients::http::Plugin {
+class MyMiddleware : public clients::http::MiddlewareBase {
public:
...
- MyPlugin() : clients::http::Plugin("my-plugin") {}
+ MyMiddleware() : clients::http::MiddlewareBase() {}
- void HookPerformRequest(clients::http::PluginRequest& request) override { do_something(request); }
+ void HookPerformRequest(clients::http::MiddlewareRequest& request) override { do_something(request); };
- void HookCreateSpan(clients::http::PluginRequest&, tracing::Span&) override {}
- void HookOnCompleted(clients::http::PluginRequest&, clients::http::Response&) override {}
- void HookOnError(clients::http::PluginRequest&, std::error_code) override {}
- bool HookOnRetry(clients::http::PluginRequest&) override { return true; }
...
};
```
4. For plugin components inherited from @ref clients::http::plugin::ComponentBase:
1. Replace `#include <userver/clients/http/plugin_component.hpp>` with `#include <userver/clients/http/middlewares/component.hpp>`
2. Change base class to @ref clients::http::middlewares::ComponentBase
3. Component name is not required to have prefix `http-client-plugin-` anymore, `http-client-` prefix is suggested instead
4. Rename `GetPlugin` method to `GetMiddleware`, change its return type to `clients::http::MiddlewareBase`
5. Use @ref dynamic\_config::Source::UpdateAndListen() to subscribe on dynamic config updates
6. Pass middleware index to base class constructor, instead of setting it in config file
For example:
```diff
-#include <userver/clients/http/plugin_component.hpp>
+#include <userver/clients/http/middlewares/component.hpp>
...
-class SomeComponentName : public clients::http::plugin::ComponentBase {
+class SomeComponentName : public clients::http::middlewares::ComponentBase {
public:
- static constexpr std::string_view kName = "http-client-plugin-my-plugin-name";
+ static constexpr std::string_view kName = "http-client-my-middleware-name";
- SomeComponentName(const components::ComponentConfig& config, const components::ComponentContext& context)
- : ComponentBase(config, context),
- plugin_(std::make_unique<Plugin>()),
+ SomeComponentName(const components::ComponentConfig& config, const components::ComponentContext& context)
+ : ComponentBase(config, context, clients::http::middlewares::MiddlewareIndex{1234}),
+ middleware_(std::make_unique<Middleware>()),
{
auto& config_component = context.FindComponent<components::DynamicConfig>();
subscriber_scope_ =
- components::DynamicConfig::NoblockSubscriber{config_component}
- .GetEventSource()
- .AddListener(this, kName, &Component::OnConfigUpdate);
+ config_component
+ .GetSource()
+ .UpdateAndListen(this, kName, &Component::OnConfigUpdate);
}
...
- clients::http::Plugin& GetPlugin() override { return *plugin_; }
+ clients::http::MiddlewareBase& GetMiddleware() override { return *middleware_; }
private:
- std::unique_ptr<clients::http::Plugin> plugin_;
+ std::unique_ptr<clients::http::MiddlewareBase> middleware_;
};
```
5. Make the following changes in static config:
1. In every @ref components::HttpClient config, rename `plugins` to `middlewares`
2. Update middleware component names to current `Component::kName`
3. Use full middleware components names as keys and `{enabled: true}` as values in `middlewares` for every @ref components::HttpClient config
4. Move middlewares that you want to use for all @ref components::HttpClient instances from `http-client.middlewares` to `http-client-middleware-pipeline.middlewares`
5. Set `dynamic-config-http-client.middlewares.<middleware name>.enabled` to `false` for all middlewares that are subscribed to dynamic configs updates
For example:
```diff
components_manager:
components:
- http-client-plugin-common-plugin-name:
+ http-client-common-middleware-name:
...
- http-client-plugin-plugin-with-dynamic-config:
+ http-client-middleware-with-dynamic-config:
...
- http-client:
- plugins:
- common-plugin-name: 1
- with-dynamic-config: 2
+ http-client-middleware-pipeline:
+ middlewares:
+ http-client-common-middleware-name:
+ enabled: true
+ http-client-middleware-with-dynamic-config:
+ enabled: true
+ dynamic-config-http-client:
+ middlewares:
+ http-client-middleware-with-dynamic-config:
+ enabled: false
```
commit_hash:ab1885792c5fe3e25b3030f6ef998a6098d4849c1 parent 0bee02e commit 0a2cabc
File tree
77 files changed
+910
-748
lines changed- chaotic-openapi/chaotic_openapi/back/cpp_client/templates
- core
- functional_tests
- http_client_middlewares
- src
- tests
- http_client_plugins/src
- include/userver
- clients/http
- middlewares
- headers_propagator
- retry_budget
- yandex_tracing
- plugins
- headers_propagator
- retry_budget
- yandex_tracing
- tracing
- src
- clients/http
- middlewares
- headers_propagator
- retry_budget
- yandex_tracing
- plugins
- headers_propagator
- retry_budget
- yandex_tracing
- components
- dynamic_config
- client
- updater
- tracing
- utest
- include/userver/utest
- src/utest
- grpc/functional_tests/basic_server
- libraries/easy/src
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
77 files changed
+910
-748
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
725 | 725 | | |
726 | 726 | | |
727 | 727 | | |
728 | | - | |
729 | | - | |
730 | | - | |
731 | | - | |
732 | | - | |
733 | | - | |
734 | | - | |
735 | | - | |
736 | | - | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
737 | 737 | | |
738 | 738 | | |
739 | 739 | | |
| |||
835 | 835 | | |
836 | 836 | | |
837 | 837 | | |
838 | | - | |
| 838 | + | |
839 | 839 | | |
840 | 840 | | |
841 | 841 | | |
| |||
845 | 845 | | |
846 | 846 | | |
847 | 847 | | |
848 | | - | |
849 | | - | |
850 | | - | |
851 | | - | |
852 | | - | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
853 | 854 | | |
854 | 855 | | |
855 | 856 | | |
| |||
1249 | 1250 | | |
1250 | 1251 | | |
1251 | 1252 | | |
1252 | | - | |
| 1253 | + | |
1253 | 1254 | | |
1254 | 1255 | | |
1255 | 1256 | | |
| |||
1266 | 1267 | | |
1267 | 1268 | | |
1268 | 1269 | | |
1269 | | - | |
1270 | | - | |
1271 | | - | |
1272 | | - | |
1273 | | - | |
1274 | | - | |
1275 | | - | |
1276 | | - | |
1277 | | - | |
1278 | | - | |
1279 | | - | |
1280 | | - | |
1281 | | - | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
1282 | 1288 | | |
1283 | 1289 | | |
1284 | 1290 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | | - | |
| 25 | + | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
51 | | - | |
| 50 | + | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
| 59 | + | |
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
Lines changed: 8 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
| 5 | + | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
38 | | - | |
| 37 | + | |
| 38 | + | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
44 | | - | |
| 43 | + | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | | - | |
| 125 | + | |
| 126 | + | |
126 | 127 | | |
127 | 128 | | |
128 | 129 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
0 commit comments