Skip to content

Commit

Permalink
quic: adding upstream config (#15537)
Browse files Browse the repository at this point in the history
Alas I didn't end up moving all of the protocol options over, as the cluster has its own timeout params so most of the QuicProtocolOptions are listener-specific.

Commit Message: adding quic protocol config to quic upstream
Risk Level: n/a (quic only)
Testing: unit tests
Docs Changes: n/a
Release Notes: n/a
part of #14829

Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
  • Loading branch information
alyssawilk authored Mar 18, 2021
1 parent dde4eb6 commit 255f78b
Show file tree
Hide file tree
Showing 24 changed files with 117 additions and 47 deletions.
8 changes: 8 additions & 0 deletions api/envoy/config/core/v3/protocol.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ message TcpProtocolOptions {
"envoy.api.v2.core.TcpProtocolOptions";
}

// QUIC protocol options which apply to both downstream and upstream connections.
message QuicProtocolOptions {
// Maximum number of streams that the client can negotiate per connection. 100
// if not specified.
google.protobuf.UInt32Value max_concurrent_streams = 1;
}

message UpstreamHttpProtocolOptions {
option (udpa.annotations.versioning).previous_message_type =
"envoy.api.v2.core.UpstreamHttpProtocolOptions";
Expand Down Expand Up @@ -406,4 +413,5 @@ message GrpcProtocolOptions {
//
// Eventually this will include configuration for tuning HTTP/3.
message Http3ProtocolOptions {
QuicProtocolOptions quic_protocol_options = 1;
}
12 changes: 12 additions & 0 deletions api/envoy/config/core/v4alpha/protocol.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions api/envoy/config/listener/v3/quic_config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ syntax = "proto3";
package envoy.config.listener.v3;

import "envoy/config/core/v3/base.proto";
import "envoy/config/core/v3/protocol.proto";

import "google/protobuf/duration.proto";
import "google/protobuf/wrappers.proto";
Expand All @@ -24,9 +25,7 @@ message QuicProtocolOptions {
option (udpa.annotations.versioning).previous_message_type =
"envoy.api.v2.listener.QuicProtocolOptions";

// Maximum number of streams that the client can negotiate per connection. 100
// if not specified.
google.protobuf.UInt32Value max_concurrent_streams = 1;
core.v3.QuicProtocolOptions quic_protocol_options = 1;

// Maximum number of milliseconds that connection will be alive when there is
// no network activity. 300000ms if not specified.
Expand Down
5 changes: 2 additions & 3 deletions api/envoy/config/listener/v4alpha/quic_config.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions generated_api_shadow/envoy/config/core/v3/protocol.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions generated_api_shadow/envoy/config/core/v4alpha/protocol.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions include/envoy/upstream/upstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,12 @@ class ClusterInfo {
*/
virtual const envoy::config::core::v3::Http2ProtocolOptions& http2Options() const PURE;

/**
* @return const envoy::config::core::v3::Http3ProtocolOptions& for HTTP/3 connections
* created on behalf of this cluster. @see envoy::config::core::v3::Http3ProtocolOptions.
*/
virtual const envoy::config::core::v3::Http3ProtocolOptions& http3Options() const PURE;

/**
* @return const envoy::config::core::v3::HttpProtocolOptions for all of HTTP versions.
*/
Expand Down
9 changes: 6 additions & 3 deletions source/common/http/conn_pool_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,32 +176,35 @@ uint64_t maxStreamsPerConnection(uint64_t max_streams_config) {
}

MultiplexedActiveClientBase::MultiplexedActiveClientBase(HttpConnPoolImplBase& parent,
uint32_t max_concurrent_streams,
Stats::Counter& cx_total)
: Envoy::Http::ActiveClient(
parent, maxStreamsPerConnection(parent.host()->cluster().maxRequestsPerConnection()),
parent.host()->cluster().http2Options().max_concurrent_streams().value()) {
max_concurrent_streams) {
codec_client_->setCodecClientCallbacks(*this);
codec_client_->setCodecConnectionCallbacks(*this);
cx_total.inc();
}

MultiplexedActiveClientBase::MultiplexedActiveClientBase(HttpConnPoolImplBase& parent,
uint32_t max_concurrent_streams,
Stats::Counter& cx_total,
Upstream::Host::CreateConnectionData& data)
: Envoy::Http::ActiveClient(
parent, maxStreamsPerConnection(parent.host()->cluster().maxRequestsPerConnection()),
parent.host()->cluster().http2Options().max_concurrent_streams().value(), data) {
max_concurrent_streams, data) {
codec_client_->setCodecClientCallbacks(*this);
codec_client_->setCodecConnectionCallbacks(*this);
cx_total.inc();
}

MultiplexedActiveClientBase::MultiplexedActiveClientBase(Envoy::Http::HttpConnPoolImplBase& parent,
Upstream::Host::CreateConnectionData& data,
uint32_t max_concurrent_streams,
Stats::Counter& cx_total)
: Envoy::Http::ActiveClient(
parent, maxStreamsPerConnection(parent.host()->cluster().maxRequestsPerConnection()),
parent.host()->cluster().http2Options().max_concurrent_streams().value(), data) {
max_concurrent_streams, data) {
codec_client_->setCodecClientCallbacks(*this);
codec_client_->setCodecConnectionCallbacks(*this);
cx_total.inc();
Expand Down
10 changes: 6 additions & 4 deletions source/common/http/conn_pool_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,10 @@ class MultiplexedActiveClientBase : public CodecClientCallbacks,
public Http::ConnectionCallbacks,
public Envoy::Http::ActiveClient {
public:
MultiplexedActiveClientBase(HttpConnPoolImplBase& parent, Stats::Counter& cx_total);
MultiplexedActiveClientBase(HttpConnPoolImplBase& parent, Stats::Counter& cx_total,
Upstream::Host::CreateConnectionData& data);
MultiplexedActiveClientBase(HttpConnPoolImplBase& parent, uint32_t max_concurrent_streams,
Stats::Counter& cx_total);
MultiplexedActiveClientBase(HttpConnPoolImplBase& parent, uint32_t max_concurrent_streams,
Stats::Counter& cx_total, Upstream::Host::CreateConnectionData& data);
~MultiplexedActiveClientBase() override = default;

// ConnPoolImpl::ActiveClient
Expand Down Expand Up @@ -205,7 +206,8 @@ class MultiplexedActiveClientBase : public CodecClientCallbacks,

protected:
MultiplexedActiveClientBase(Envoy::Http::HttpConnPoolImplBase& parent,
Upstream::Host::CreateConnectionData& data, Stats::Counter& cx_total);
Upstream::Host::CreateConnectionData& data,
uint32_t max_concurrent_streams, Stats::Counter& cx_total);

private:
bool closed_with_active_rq_{};
Expand Down
10 changes: 6 additions & 4 deletions source/common/http/http2/conn_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ namespace Http {

namespace Http2 {
ActiveClient::ActiveClient(HttpConnPoolImplBase& parent)
: MultiplexedActiveClientBase(parent,
parent.host()->cluster().stats().upstream_cx_http2_total_) {}
: MultiplexedActiveClientBase(
parent, parent.host()->cluster().http2Options().max_concurrent_streams().value(),
parent.host()->cluster().stats().upstream_cx_http2_total_) {}

ActiveClient::ActiveClient(Envoy::Http::HttpConnPoolImplBase& parent,
Upstream::Host::CreateConnectionData& data)
: MultiplexedActiveClientBase(parent, data,
parent.host()->cluster().stats().upstream_cx_http2_total_) {}
: MultiplexedActiveClientBase(
parent, data, parent.host()->cluster().http2Options().max_concurrent_streams().value(),
parent.host()->cluster().stats().upstream_cx_http2_total_) {}

ConnectionPool::InstancePtr
allocateConnPool(Event::Dispatcher& dispatcher, Random::RandomGenerator& random_generator,
Expand Down
2 changes: 1 addition & 1 deletion source/common/http/http3/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ envoy_cc_library(
"//include/envoy/config:typed_config_interface",
"//include/envoy/network:connection_interface",
"//include/envoy/ssl:context_config_interface",
"@envoy_api//envoy/config/listener/v3:pkg_cc_proto",
"@envoy_api//envoy/config/core/v3:pkg_cc_proto",
],
)

Expand Down
13 changes: 9 additions & 4 deletions source/common/http/http3/conn_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@ namespace Envoy {
namespace Http {
namespace Http3 {

// TODO(#14829) the constructor of Http2::ActiveClient sets max requests per
// connection based on HTTP/2 config. Sort out the HTTP/3 config story.
class ActiveClient : public MultiplexedActiveClientBase {
public:
ActiveClient(Envoy::Http::HttpConnPoolImplBase& parent,
Upstream::Host::CreateConnectionData& data)
: MultiplexedActiveClientBase(
parent, parent.host()->cluster().stats().upstream_cx_http3_total_, data) {}
: MultiplexedActiveClientBase(parent,
parent.host()
->cluster()
.http3Options()
.quic_protocol_options()
.max_concurrent_streams()
.value(),
parent.host()->cluster().stats().upstream_cx_http3_total_,
data) {}
};

ConnectionPool::InstancePtr
Expand Down
2 changes: 1 addition & 1 deletion source/common/http/http3/quic_client_connection_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <string>

#include "envoy/config/listener/v3/quic_config.pb.h"
#include "envoy/config/core/v3/protocol.pb.h"
#include "envoy/config/typed_config.h"
#include "envoy/network/connection.h"
#include "envoy/ssl/context_config.h"
Expand Down
3 changes: 3 additions & 0 deletions source/common/upstream/upstream_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,9 @@ class ClusterInfoImpl : public ClusterInfo,
const envoy::config::core::v3::Http2ProtocolOptions& http2Options() const override {
return http_protocol_options_->http2_options_;
}
const envoy::config::core::v3::Http3ProtocolOptions& http3Options() const override {
return http_protocol_options_->http3_options_;
}
const envoy::config::core::v3::HttpProtocolOptions& commonHttpProtocolOptions() const override {
return http_protocol_options_->common_http_protocol_options_;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ ActiveQuicListenerFactory::ActiveQuicListenerFactory(
: 20000;
quic_config_.set_max_time_before_crypto_handshake(
quic::QuicTime::Delta::FromMilliseconds(max_time_before_crypto_handshake_ms));
int32_t max_streams = PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, max_concurrent_streams, 100);
int32_t max_streams =
PROTOBUF_GET_WRAPPED_OR_DEFAULT(config.quic_protocol_options(), max_concurrent_streams, 100);
quic_config_.SetMaxBidirectionalStreamsToSend(max_streams);
quic_config_.SetMaxUnidirectionalStreamsToSend(max_streams);
}
Expand Down
23 changes: 11 additions & 12 deletions source/extensions/upstreams/http/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,13 @@ getHttp2Options(const envoy::extensions::upstreams::http::v3::HttpProtocolOption
return options.explicit_http_config().http2_protocol_options();
}

absl::optional<envoy::config::core::v3::Http3ProtocolOptions>
const envoy::config::core::v3::Http3ProtocolOptions&
getHttp3Options(const envoy::extensions::upstreams::http::v3::HttpProtocolOptions& options) {
if (options.has_use_downstream_protocol_config() &&
options.use_downstream_protocol_config().has_http3_protocol_options()) {
return options.use_downstream_protocol_config().http3_protocol_options();
}
if (options.has_explicit_http_config() &&
options.explicit_http_config().has_http3_protocol_options()) {
return options.explicit_http_config().http3_protocol_options();
}
return {};
return options.explicit_http_config().http3_protocol_options();
}

} // namespace
Expand Down Expand Up @@ -89,14 +85,17 @@ ProtocolOptionsConfigImpl::ProtocolOptionsConfigImpl(
? absl::make_optional<envoy::config::core::v3::UpstreamHttpProtocolOptions>(
options.upstream_http_protocol_options())
: absl::nullopt) {
if (http3_options_.has_value()) {
use_http3_ = true;
}
if (options.has_explicit_http_config() &&
options.explicit_http_config().has_http2_protocol_options()) {
use_http2_ = true;
if (options.has_explicit_http_config()) {
if (options.explicit_http_config().has_http3_protocol_options()) {
use_http3_ = true;
} else if (options.explicit_http_config().has_http2_protocol_options()) {
use_http2_ = true;
}
}
if (options.has_use_downstream_protocol_config()) {
if (options.use_downstream_protocol_config().has_http3_protocol_options()) {
use_http3_ = true;
}
if (options.use_downstream_protocol_config().has_http2_protocol_options()) {
use_http2_ = true;
}
Expand Down
2 changes: 1 addition & 1 deletion source/extensions/upstreams/http/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ProtocolOptionsConfigImpl : public Upstream::ProtocolOptionsConfig {

const Envoy::Http::Http1Settings http1_settings_;
const envoy::config::core::v3::Http2ProtocolOptions http2_options_;
absl::optional<envoy::config::core::v3::Http3ProtocolOptions> http3_options_{};
const envoy::config::core::v3::Http3ProtocolOptions http3_options_{};
const envoy::config::core::v3::HttpProtocolOptions common_http_protocol_options_;
const absl::optional<envoy::config::core::v3::UpstreamHttpProtocolOptions>
upstream_http_protocol_options_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ TEST(ActiveQuicListenerConfigTest, CreateActiveQuicListenerFactory) {
ProtobufTypes::MessagePtr config = config_factory.createEmptyConfigProto();

std::string yaml = R"EOF(
max_concurrent_streams: 10
quic_protocol_options:
max_concurrent_streams: 10
idle_timeout: {
seconds: 2
}
Expand Down Expand Up @@ -63,7 +64,8 @@ TEST(ActiveQuicListenerConfigTest, QuicListenerFlagNotConfigured) {
ProtobufTypes::MessagePtr config = config_factory.createEmptyConfigProto();

std::string yaml = R"EOF(
max_concurrent_streams: 10
quic_protocol_options:
max_concurrent_streams: 10
idle_timeout: {
seconds: 2
}
Expand Down
Loading

0 comments on commit 255f78b

Please sign in to comment.