Skip to content

Commit

Permalink
feat clients: enable deadline propagation by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton3 committed Jul 5, 2023
1 parent cf48e5c commit 965b1c6
Show file tree
Hide file tree
Showing 69 changed files with 249 additions and 478 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
"max-size": 100,
"token-update-interval-ms": 0
},
"HTTP_CLIENT_ENFORCE_TASK_DEADLINE": {
"cancel-request": false,
"update-timeout": false
},
"USERVER_BAGGAGE_ENABLED": false,
"USERVER_CACHES": {},
"USERVER_CANCEL_HANDLE_REQUEST_BY_DEADLINE": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
"max-size": 100,
"token-update-interval-ms": 0
},
"HTTP_CLIENT_ENFORCE_TASK_DEADLINE": {
"cancel-request": false,
"update-timeout": false
},
"USERVER_BAGGAGE_ENABLED": false,
"USERVER_CACHES": {},
"USERVER_CANCEL_HANDLE_REQUEST_BY_DEADLINE": false,
Expand Down
4 changes: 0 additions & 4 deletions clickhouse/tests/dynamic_config_fallback.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
"max-size": 100,
"token-update-interval-ms": 0
},
"HTTP_CLIENT_ENFORCE_TASK_DEADLINE": {
"cancel-request": false,
"update-timeout": false
},
"USERVER_BAGGAGE_ENABLED": false,
"USERVER_CACHES": {},
"USERVER_CANCEL_HANDLE_REQUEST_BY_DEADLINE": false,
Expand Down
4 changes: 0 additions & 4 deletions conan/test_package/hello_service/dynamic_config_fallback.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
"max-size": 100,
"token-update-interval-ms": 0
},
"HTTP_CLIENT_ENFORCE_TASK_DEADLINE": {
"cancel-request": false,
"update-timeout": false
},
"USERVER_BAGGAGE_ENABLED": false,
"USERVER_CACHES": {},
"USERVER_CANCEL_HANDLE_REQUEST_BY_DEADLINE": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
"max-size": 100,
"token-update-interval-ms": 0
},
"HTTP_CLIENT_ENFORCE_TASK_DEADLINE": {
"cancel-request": false,
"update-timeout": false
},
"USERVER_BAGGAGE_ENABLED": false,
"USERVER_CACHES": {},
"USERVER_CANCEL_HANDLE_REQUEST_BY_DEADLINE": false,
Expand Down
2 changes: 1 addition & 1 deletion core/functional_tests/basic_chaos/httpserver_handlers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class HttpServerHandler final : public server::handlers::HttpHandlerBase {
}

if (type == "sleep") {
engine::SleepFor(std::chrono::milliseconds{200});
TESTPOINT("testpoint_request", {});
engine::SleepFor(std::chrono::milliseconds{200});
return kDefaultAnswer;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
"max-size": 100,
"token-update-interval-ms": 0
},
"HTTP_CLIENT_ENFORCE_TASK_DEADLINE": {
"cancel-request": false,
"update-timeout": false
},
"USERVER_BAGGAGE_ENABLED": false,
"USERVER_CACHES": {},
"USERVER_CANCEL_HANDLE_REQUEST_BY_DEADLINE": false,
Expand Down
4 changes: 0 additions & 4 deletions core/functional_tests/metrics/dynamic_config_fallback.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
"max-size": 100,
"token-update-interval-ms": 0
},
"HTTP_CLIENT_ENFORCE_TASK_DEADLINE": {
"cancel-request": false,
"update-timeout": false
},
"USERVER_BAGGAGE_ENABLED": false,
"USERVER_CACHES": {},
"USERVER_CANCEL_HANDLE_REQUEST_BY_DEADLINE": false,
Expand Down
4 changes: 0 additions & 4 deletions core/functional_tests/uctl/dynamic_config_fallback.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
"max-size": 100,
"token-update-interval-ms": 0
},
"HTTP_CLIENT_ENFORCE_TASK_DEADLINE": {
"cancel-request": false,
"update-timeout": false
},
"USERVER_BAGGAGE_ENABLED": false,
"USERVER_CACHES": {},
"USERVER_CANCEL_HANDLE_REQUEST_BY_DEADLINE": false,
Expand Down
25 changes: 7 additions & 18 deletions core/include/userver/clients/http/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <userver/moodycamel/concurrentqueue_fwd.h>

#include <userver/clients/dns/resolver_fwd.hpp>
#include <userver/clients/http/impl/config.hpp>
#include <userver/clients/http/plugin.hpp>
#include <userver/clients/http/request.hpp>
#include <userver/engine/task/task_processor_fwd.hpp>
Expand Down Expand Up @@ -47,25 +48,12 @@ namespace impl {
class EasyWrapper;
} // namespace impl

struct Config;
struct TestsuiteConfig;
struct EnforceTaskDeadlineConfig;
class Statistics;
struct PoolStatistics;
struct InstanceStatistics;
class DestinationStatistics;

struct ClientSettings final {
std::string thread_name_prefix;
size_t io_threads = 8;
bool defer_events = false;
const tracing::TracingManagerBase* tracing_manager_{nullptr};
const server::http::HeadersPropagator* headers_propagator_{nullptr};
};

ClientSettings Parse(const yaml_config::YamlConfig& value,
formats::parse::To<ClientSettings>);

/// @ingroup userver_clients
///
/// @brief HTTP client that returns a HTTP request builder from
Expand All @@ -78,8 +66,10 @@ ClientSettings Parse(const yaml_config::YamlConfig& value,
/// @snippet clients/http/client_test.cpp Sample HTTP Client usage
class Client final {
public:
Client(ClientSettings settings, engine::TaskProcessor& fs_task_processor,
Client(impl::ClientSettings settings,
engine::TaskProcessor& fs_task_processor,
impl::PluginPipeline&& plugin_pipeline);

~Client();

/// @brief Returns a HTTP request builder type with preset values of
Expand Down Expand Up @@ -117,7 +107,7 @@ class Client final {
void SetAllowedUrlsExtra(std::vector<std::string>&& urls);

// For internal use only.
void SetConfig(const Config&);
void SetConfig(const impl::Config&);
/// @endcond

/// @brief Sets User-Agent headers for all the requests or removes that
Expand All @@ -140,8 +130,6 @@ class Client final {
/// (most likely getaddrinfo).
void SetDnsResolver(clients::dns::Resolver* resolver);

void SetTracingManager(const tracing::TracingManagerBase&);

private:
void ReinitEasy();

Expand All @@ -159,7 +147,8 @@ class Client final {
std::shared_ptr<curl::easy> TryDequeueIdle() noexcept;

std::atomic<std::size_t> pending_tasks_{0};
rcu::Variable<EnforceTaskDeadlineConfig> enforce_task_deadline_;

const impl::DeadlinePropagationConfig deadline_propagation_config_;

std::shared_ptr<DestinationStatistics> destination_statistics_;
std::unique_ptr<engine::ev::ThreadPool> thread_pool_;
Expand Down
2 changes: 1 addition & 1 deletion core/include/userver/clients/http/component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ namespace components {
/// ## Dynamic options:
/// * @ref HTTP_CLIENT_CONNECT_THROTTLE
/// * @ref HTTP_CLIENT_CONNECTION_POOL_SIZE
/// * @ref HTTP_CLIENT_ENFORCE_TASK_DEADLINE
/// * @ref USERVER_HTTP_PROXY
///
/// ## Static options:
Expand All @@ -47,6 +46,7 @@ namespace components {
/// testsuite-timeout | if set, force the request timeout regardless of the value passed in code | -
/// testsuite-allowed-url-prefixes | if set, checks that all URLs start with any of the passed prefixes, asserts if not. Set for testing purposes only. | ''
/// dns_resolver | server hostname resolver type (getaddrinfo or async) | 'async'
/// set-deadline-propagation-header | whether to set http::common::kXYaTaxiClientTimeoutMs request header | true
/// plugins | Plugin names to apply. A plugin component is called "http-client-plugin-" plus the plugin name.
///
/// ## Static configuration example:
Expand Down
66 changes: 66 additions & 0 deletions core/include/userver/clients/http/impl/config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#pragma once

#include <chrono>
#include <string>

#include <userver/dynamic_config/fwd.hpp>
#include <userver/formats/json_fwd.hpp>
#include <userver/yaml_config/fwd.hpp>

USERVER_NAMESPACE_BEGIN

namespace tracing {
class TracingManagerBase;
} // namespace tracing

namespace server::http {
class HeadersPropagator;
} // namespace server::http

namespace clients::http::impl {

struct DeadlinePropagationConfig {
bool update_header{true};
};

// Static config
struct ClientSettings final {
std::string thread_name_prefix{};
size_t io_threads{8};
bool defer_events{false};
DeadlinePropagationConfig deadline_propagation{};
const tracing::TracingManagerBase* tracing_manager{nullptr};
const server::http::HeadersPropagator* headers_propagator{nullptr};
};

ClientSettings Parse(const yaml_config::YamlConfig& value,
formats::parse::To<ClientSettings>);

struct ThrottleConfig final {
static constexpr size_t kNoLimit = -1;

std::size_t http_connect_limit{kNoLimit};
std::chrono::microseconds http_connect_rate{0};
std::size_t https_connect_limit{kNoLimit};
std::chrono::microseconds https_connect_rate{0};
std::size_t per_host_connect_limit{kNoLimit};
std::chrono::microseconds per_host_connect_rate{0};
};

ThrottleConfig Parse(const formats::json::Value& value,
formats::parse::To<ThrottleConfig>);

// Dynamic config
struct Config final {
static constexpr std::size_t kDefaultConnectionPoolSize = 10000;

std::size_t connection_pool_size{kDefaultConnectionPoolSize};
std::string proxy;
ThrottleConfig throttle;
};

Config ParseConfig(const dynamic_config::DocsMap& docs_map);

} // namespace clients::http::impl

USERVER_NAMESPACE_END
21 changes: 10 additions & 11 deletions core/include/userver/clients/http/request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ namespace clients::http {
class RequestState;
class StreamedResponse;
class ConnectTo;
class Form;
class RequestStats;
class DestinationStatistics;
struct TestsuiteConfig;

namespace impl {
class EasyWrapper;
struct DeadlinePropagationConfig;
} // namespace impl

/// HTTP request method
Expand Down Expand Up @@ -67,12 +72,6 @@ enum class ProxyAuthType {

ProxyAuthType ProxyAuthTypeFromString(const std::string& auth_name);

class Form;
class RequestStats;
class DestinationStatistics;
struct TestsuiteConfig;
struct EnforceTaskDeadlineConfig;

/// Class for creating and performing new http requests
class Request final {
public:
Expand Down Expand Up @@ -261,16 +260,16 @@ class Request final {

/// @cond
// Set testsuite related settings. For internal use only.
Request& SetTestsuiteConfig(
void SetTestsuiteConfig(
const std::shared_ptr<const TestsuiteConfig>& config) &;

Request& SetAllowedUrlsExtra(const std::vector<std::string>& urls) &;
void SetAllowedUrlsExtra(const std::vector<std::string>& urls) &;

// Set deadline propagation settings. For internal use only.
Request& SetEnforceTaskDeadline(
EnforceTaskDeadlineConfig enforce_task_deadline) &;
void SetDeadlinePropagationConfig(
const impl::DeadlinePropagationConfig& deadline_propagation_config) &;

Request& SetHeadersPropagator(const server::http::HeadersPropagator*) &;
void SetHeadersPropagator(const server::http::HeadersPropagator*) &;
/// @endcond

/// Disable auto-decoding of received replies.
Expand Down
1 change: 0 additions & 1 deletion core/library.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ configs:
- BAGGAGE_SETTINGS
- HTTP_CLIENT_CONNECTION_POOL_SIZE
- HTTP_CLIENT_CONNECT_THROTTLE
- HTTP_CLIENT_ENFORCE_TASK_DEADLINE
- USERVER_BAGGAGE_ENABLED
- USERVER_CACHES
- USERVER_CANCEL_HANDLE_REQUEST_BY_DEADLINE
Expand Down
Loading

0 comments on commit 965b1c6

Please sign in to comment.