Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

engine: add H2 ping config API #1770

Merged
merged 10 commits into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions library/cc/engine_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ EngineBuilder::addDnsPreresolveHostnames(const std::string& dns_preresolve_hostn
return *this;
}

EngineBuilder& EngineBuilder::addH2ConnectionKeepaliveIdleIntervalMilliseconds(
int h2_connection_keepalive_idle_interval_milliseconds) {
this->h2_connection_keepalive_idle_interval_milliseconds_ =
h2_connection_keepalive_idle_interval_milliseconds;
return *this;
}

EngineBuilder&
EngineBuilder::addH2ConnectionKeepaliveTimeoutSeconds(int h2_connection_keepalive_timeout_seconds) {
this->h2_connection_keepalive_timeout_seconds_ = h2_connection_keepalive_timeout_seconds;
return *this;
}
junr03 marked this conversation as resolved.
Show resolved Hide resolved

EngineBuilder& EngineBuilder::addStatsFlushSeconds(int stats_flush_seconds) {
this->stats_flush_seconds_ = stats_flush_seconds;
return *this;
Expand Down Expand Up @@ -87,6 +100,10 @@ std::string EngineBuilder::generateConfigStr() {
{"dns_preresolve_hostnames", this->dns_preresolve_hostnames_},
{"dns_refresh_rate", fmt::format("{}s", this->dns_refresh_seconds_)},
{"dns_query_timeout", fmt::format("{}s", this->dns_query_timeout_seconds_)},
{"h2_connection_keepalive_idle_interval",
fmt::format("{}s", this->h2_connection_keepalive_idle_interval_milliseconds_ / 1000.0)},
{"h2_connection_keepalive_timeout",
fmt::format("{}s", this->h2_connection_keepalive_timeout_seconds_)},
{
"metadata",
fmt::format("{{ device_os: {}, app_version: {}, app_id: {} }}", this->device_os_,
Expand Down
6 changes: 6 additions & 0 deletions library/cc/engine_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class EngineBuilder {
EngineBuilder& addDnsFailureRefreshSeconds(int base, int max);
EngineBuilder& addDnsQueryTimeoutSeconds(int dns_query_timeout_seconds);
EngineBuilder& addDnsPreresolveHostnames(const std::string& dns_preresolve_hostnames);
EngineBuilder& addH2ConnectionKeepaliveIdleIntervalMilliseconds(
int h2_connection_keepalive_idle_interval_milliseconds);
EngineBuilder&
addH2ConnectionKeepaliveTimeoutSeconds(int h2_connection_keepalive_timeout_seconds);
EngineBuilder& addStatsFlushSeconds(int stats_flush_seconds);
EngineBuilder& addVirtualClusters(const std::string& virtual_clusters);
EngineBuilder& setAppVersion(const std::string& app_version);
Expand Down Expand Up @@ -53,6 +57,8 @@ class EngineBuilder {
int dns_failure_refresh_seconds_max_ = 10;
int dns_query_timeout_seconds_ = 25;
std::string dns_preresolve_hostnames_ = "[]";
int h2_connection_keepalive_idle_interval_milliseconds_ = 100000000;
int h2_connection_keepalive_timeout_seconds_ = 10;
int stats_flush_seconds_ = 60;
std::string app_version_ = "unspecified";
std::string app_id_ = "unspecified";
Expand Down
7 changes: 6 additions & 1 deletion library/common/config/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const std::string config_header = R"(
- &dns_fail_max_interval 10s
- &dns_query_timeout 25s
- &dns_preresolve_hostnames []
- &h2_connection_keepalive_idle_interval 100000s
goaway marked this conversation as resolved.
Show resolved Hide resolved
- &h2_connection_keepalive_timeout 10s
- &metadata {}
- &stats_domain 127.0.0.1
- &stats_flush_interval 60s
Expand Down Expand Up @@ -70,7 +72,10 @@ const std::string config_header = R"(
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
"@type": type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions
auto_config:
http2_protocol_options: {}
http2_protocol_options:
connection_keepalive:
connection_idle_interval: *h2_connection_keepalive_idle_interval
timeout: *h2_connection_keepalive_timeout
http_protocol_options:
header_key_format:
stateful_formatter:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class EnvoyConfiguration {
public final Integer dnsFailureRefreshSecondsMax;
public final Integer dnsQueryTimeoutSeconds;
public final String dnsPreresolveHostnames;
public final Integer h2ConnectionKeepaliveIdleIntervalMilliseconds;
public final Integer h2ConnectionKeepaliveTimeoutSeconds;
public final List<EnvoyHTTPFilterFactory> httpPlatformFilterFactories;
public final Integer statsFlushSeconds;
public final Integer streamIdleTimeoutSeconds;
Expand All @@ -43,6 +45,9 @@ public class EnvoyConfiguration {
* @param dnsFailureRefreshSecondsMax max rate in seconds to refresh DNS on failure.
* @param dnsQueryTimeoutSeconds rate in seconds to timeout DNS queries.
* @param dnsPreresolveHostnames hostnames to preresolve on Envoy Client construction.
* @param h2ConnectionKeepaliveIdleIntervalMilliseconds rate in milliseconds seconds to send h2
* pings on stream creation.
* @param h2ConnectionKeepaliveTimeoutSeconds rate in seconds to timeout h2 pings.
* @param statsFlushSeconds interval at which to flush Envoy stats.
* @param streamIdleTimeoutSeconds idle timeout for HTTP streams.
* @param appVersion the App Version of the App using this Envoy Client.
Expand All @@ -56,7 +61,9 @@ public EnvoyConfiguration(Boolean adminInterfaceEnabled, String grpcStatsDomain,
@Nullable Integer statsdPort, int connectTimeoutSeconds,
int dnsRefreshSeconds, int dnsFailureRefreshSecondsBase,
int dnsFailureRefreshSecondsMax, int dnsQueryTimeoutSeconds,
String dnsPreresolveHostnames, int statsFlushSeconds,
String dnsPreresolveHostnames,
int h2ConnectionKeepaliveIdleIntervalMilliseconds,
int h2ConnectionKeepaliveTimeoutSeconds, int statsFlushSeconds,
int streamIdleTimeoutSeconds, String appVersion, String appId,
String virtualClusters, List<EnvoyNativeFilterConfig> nativeFilterChain,
List<EnvoyHTTPFilterFactory> httpPlatformFilterFactories,
Expand All @@ -70,6 +77,9 @@ public EnvoyConfiguration(Boolean adminInterfaceEnabled, String grpcStatsDomain,
this.dnsFailureRefreshSecondsMax = dnsFailureRefreshSecondsMax;
this.dnsQueryTimeoutSeconds = dnsQueryTimeoutSeconds;
this.dnsPreresolveHostnames = dnsPreresolveHostnames;
this.h2ConnectionKeepaliveIdleIntervalMilliseconds =
h2ConnectionKeepaliveIdleIntervalMilliseconds;
this.h2ConnectionKeepaliveTimeoutSeconds = h2ConnectionKeepaliveTimeoutSeconds;
this.statsFlushSeconds = statsFlushSeconds;
this.streamIdleTimeoutSeconds = streamIdleTimeoutSeconds;
this.appVersion = appVersion;
Expand Down Expand Up @@ -118,6 +128,10 @@ String resolveTemplate(final String templateYAML, final String platformFilterTem
.append(String.format("- &dns_fail_max_interval %ss\n", dnsFailureRefreshSecondsMax))
.append(String.format("- &dns_query_timeout %ss\n", dnsQueryTimeoutSeconds))
.append(String.format("- &dns_preresolve_hostnames %s\n", dnsPreresolveHostnames))
.append(String.format("- &h2_connection_keepalive_idle_interval %ss\n",
h2ConnectionKeepaliveIdleIntervalMilliseconds / 1000.0))
.append(String.format("- &h2_connection_keepalive_timeout %ss\n",
h2ConnectionKeepaliveTimeoutSeconds))
.append(String.format("- &stream_idle_timeout %ss\n", streamIdleTimeoutSeconds))
.append(String.format("- &metadata { device_os: %s, app_version: %s, app_id: %s }\n",
"Android", appVersion, appId))
Expand Down
37 changes: 33 additions & 4 deletions library/kotlin/io/envoyproxy/envoymobile/EngineBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ open class EngineBuilder(
private var dnsFailureRefreshSecondsMax = 10
private var dnsQueryTimeoutSeconds = 25
private var dnsPreresolveHostnames = "[]"
private var h2ConnectionKeepaliveIdleIntervalMilliseconds = 100000000
private var h2ConnectionKeepaliveTimeoutSeconds = 10
private var statsFlushSeconds = 60
private var streamIdleTimeoutSeconds = 15
private var appVersion = "unspecified"
Expand Down Expand Up @@ -148,6 +150,31 @@ open class EngineBuilder(
return this
}

/**
* Add a rate at which to ping h2 connections on new stream creation if the connection has
* sat idle.
*
* @param h2ConnectionKeepaliveIdleIntervalMilliseconds rate in milliseconds.
*
* @return this builder.
*/
fun addH2ConnectionKeepaliveIdleIntervalMilliseconds(idleIntervalMs: Int): EngineBuilder {
this.h2ConnectionKeepaliveIdleIntervalMilliseconds = idleIntervalMs
return this
}

/**
* Add a rate at which to timeout h2 pings.
*
* @param h2ConnectionKeepaliveTimeoutSeconds rate in seconds to timeout h2 pings.
*
* @return this builder.
*/
fun addH2ConnectionKeepaliveTimeoutSeconds(timeoutSeconds: Int): EngineBuilder {
this.h2ConnectionKeepaliveTimeoutSeconds = timeoutSeconds
return this
}

/**
* Add an interval at which to flush Envoy stats.
*
Expand Down Expand Up @@ -321,8 +348,9 @@ open class EngineBuilder(
EnvoyConfiguration(
adminInterfaceEnabled, grpcStatsDomain, statsDPort, connectTimeoutSeconds,
dnsRefreshSeconds, dnsFailureRefreshSecondsBase, dnsFailureRefreshSecondsMax,
dnsQueryTimeoutSeconds,
dnsPreresolveHostnames, statsFlushSeconds, streamIdleTimeoutSeconds, appVersion, appId,
dnsQueryTimeoutSeconds, dnsPreresolveHostnames,
h2ConnectionKeepaliveIdleIntervalMilliseconds, h2ConnectionKeepaliveTimeoutSeconds,
statsFlushSeconds, streamIdleTimeoutSeconds, appVersion, appId,
virtualClusters, nativeFilterChain, platformFilterChain, stringAccessors
),
configuration.yaml,
Expand All @@ -335,8 +363,9 @@ open class EngineBuilder(
EnvoyConfiguration(
adminInterfaceEnabled, grpcStatsDomain, statsDPort, connectTimeoutSeconds,
dnsRefreshSeconds, dnsFailureRefreshSecondsBase, dnsFailureRefreshSecondsMax,
dnsQueryTimeoutSeconds,
dnsPreresolveHostnames, statsFlushSeconds, streamIdleTimeoutSeconds, appVersion, appId,
dnsQueryTimeoutSeconds, dnsPreresolveHostnames,
h2ConnectionKeepaliveIdleIntervalMilliseconds, h2ConnectionKeepaliveTimeoutSeconds,
statsFlushSeconds, streamIdleTimeoutSeconds, appVersion, appId,
virtualClusters, nativeFilterChain, platformFilterChain, stringAccessors
),
logLevel
Expand Down
52 changes: 32 additions & 20 deletions library/objective-c/EnvoyConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,31 @@

@implementation EnvoyConfiguration

- (instancetype)
initWithAdminInterfaceEnabled:(BOOL)adminInterfaceEnabled
GrpcStatsDomain:(nullable NSString *)grpcStatsDomain
connectTimeoutSeconds:(UInt32)connectTimeoutSeconds
dnsRefreshSeconds:(UInt32)dnsRefreshSeconds
dnsFailureRefreshSecondsBase:(UInt32)dnsFailureRefreshSecondsBase
dnsFailureRefreshSecondsMax:(UInt32)dnsFailureRefreshSecondsMax
dnsQueryTimeoutSeconds:(UInt32)dnsQueryTimeoutSeconds
dnsPreresolveHostnames:(NSString *)dnsPreresolveHostnames
statsFlushSeconds:(UInt32)statsFlushSeconds
streamIdleTimeoutSeconds:(UInt32)streamIdleTimeoutSeconds
appVersion:(NSString *)appVersion
appId:(NSString *)appId
virtualClusters:(NSString *)virtualClusters
directResponseMatchers:(NSString *)directResponseMatchers
directResponses:(NSString *)directResponses
nativeFilterChain:(NSArray<EnvoyNativeFilterConfig *> *)nativeFilterChain
platformFilterChain:(NSArray<EnvoyHTTPFilterFactory *> *)httpPlatformFilterFactories
stringAccessors:
(NSDictionary<NSString *, EnvoyStringAccessor *> *)stringAccessors {
- (instancetype)initWithAdminInterfaceEnabled:(BOOL)adminInterfaceEnabled
GrpcStatsDomain:(nullable NSString *)grpcStatsDomain
connectTimeoutSeconds:(UInt32)connectTimeoutSeconds
dnsRefreshSeconds:(UInt32)dnsRefreshSeconds
dnsFailureRefreshSecondsBase:(UInt32)dnsFailureRefreshSecondsBase
dnsFailureRefreshSecondsMax:(UInt32)dnsFailureRefreshSecondsMax
dnsQueryTimeoutSeconds:(UInt32)dnsQueryTimeoutSeconds
dnsPreresolveHostnames:(NSString *)dnsPreresolveHostnames
h2ConnectionKeepaliveIdleIntervalMilliseconds:
(UInt32)h2ConnectionKeepaliveIdleIntervalMilliseconds
h2ConnectionKeepaliveTimeoutSeconds:(UInt32)h2ConnectionKeepaliveTimeoutSeconds
statsFlushSeconds:(UInt32)statsFlushSeconds
streamIdleTimeoutSeconds:(UInt32)streamIdleTimeoutSeconds
appVersion:(NSString *)appVersion
appId:(NSString *)appId
virtualClusters:(NSString *)virtualClusters
directResponseMatchers:(NSString *)directResponseMatchers
directResponses:(NSString *)directResponses
nativeFilterChain:
(NSArray<EnvoyNativeFilterConfig *> *)nativeFilterChain
platformFilterChain:
(NSArray<EnvoyHTTPFilterFactory *> *)httpPlatformFilterFactories
stringAccessors:
(NSDictionary<NSString *, EnvoyStringAccessor *> *)
stringAccessors {
self = [super init];
if (!self) {
return nil;
Expand All @@ -37,6 +42,9 @@ @implementation EnvoyConfiguration
self.dnsFailureRefreshSecondsMax = dnsFailureRefreshSecondsMax;
self.dnsQueryTimeoutSeconds = dnsQueryTimeoutSeconds;
self.dnsPreresolveHostnames = dnsPreresolveHostnames;
self.h2ConnectionKeepaliveIdleIntervalMilliseconds =
h2ConnectionKeepaliveIdleIntervalMilliseconds;
self.h2ConnectionKeepaliveTimeoutSeconds = h2ConnectionKeepaliveTimeoutSeconds;
self.statsFlushSeconds = statsFlushSeconds;
self.streamIdleTimeoutSeconds = streamIdleTimeoutSeconds;
self.appVersion = appVersion;
Expand Down Expand Up @@ -108,6 +116,10 @@ - (nullable NSString *)resolveTemplate:(NSString *)templateYAML {
[definitions
appendFormat:@"- &dns_query_timeout %lus\n", (unsigned long)self.dnsQueryTimeoutSeconds];
[definitions appendFormat:@"- &dns_preresolve_hostnames %@\n", self.dnsPreresolveHostnames];
[definitions appendFormat:@"- &h2_connection_keepalive_idle_interval %.*fs\n", 3,
(double)self.h2ConnectionKeepaliveIdleIntervalMilliseconds / 1000.0];
[definitions appendFormat:@"- &h2_connection_keepalive_timeout %lus\n",
(unsigned long)self.h2ConnectionKeepaliveTimeoutSeconds];
[definitions
appendFormat:@"- &stream_idle_timeout %lus\n", (unsigned long)self.streamIdleTimeoutSeconds];
[definitions appendFormat:@"- &metadata { device_os: %@, app_version: %@, app_id: %@ }\n", @"iOS",
Expand Down
47 changes: 27 additions & 20 deletions library/objective-c/EnvoyEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ extern const int kEnvoyFilterResumeStatusResumeIteration;
@property (nonatomic, assign) UInt32 dnsFailureRefreshSecondsMax;
@property (nonatomic, assign) UInt32 dnsQueryTimeoutSeconds;
@property (nonatomic, strong) NSString *dnsPreresolveHostnames;
@property (nonatomic, assign) UInt32 h2ConnectionKeepaliveIdleIntervalMilliseconds;
@property (nonatomic, assign) UInt32 h2ConnectionKeepaliveTimeoutSeconds;
@property (nonatomic, assign) UInt32 statsFlushSeconds;
@property (nonatomic, assign) UInt32 streamIdleTimeoutSeconds;
@property (nonatomic, strong) NSString *appVersion;
Expand All @@ -315,26 +317,31 @@ extern const int kEnvoyFilterResumeStatusResumeIteration;
/**
Create a new instance of the configuration.
*/
- (instancetype)
initWithAdminInterfaceEnabled:(BOOL)adminInterfaceEnabled
GrpcStatsDomain:(nullable NSString *)grpcStatsDomain
connectTimeoutSeconds:(UInt32)connectTimeoutSeconds
dnsRefreshSeconds:(UInt32)dnsRefreshSeconds
dnsFailureRefreshSecondsBase:(UInt32)dnsFailureRefreshSecondsBase
dnsFailureRefreshSecondsMax:(UInt32)dnsFailureRefreshSecondsMax
dnsQueryTimeoutSeconds:(UInt32)dnsQueryTimeoutSeconds
dnsPreresolveHostnames:(NSString *)dnsPreresolveHostnames
statsFlushSeconds:(UInt32)statsFlushSeconds
streamIdleTimeoutSeconds:(UInt32)streamIdleTimeoutSeconds
appVersion:(NSString *)appVersion
appId:(NSString *)appId
virtualClusters:(NSString *)virtualClusters
directResponseMatchers:(NSString *)directResponseMatchers
directResponses:(NSString *)directResponses
nativeFilterChain:(NSArray<EnvoyNativeFilterConfig *> *)nativeFilterChain
platformFilterChain:(NSArray<EnvoyHTTPFilterFactory *> *)httpPlatformFilterFactories
stringAccessors:
(NSDictionary<NSString *, EnvoyStringAccessor *> *)stringAccessors;
- (instancetype)initWithAdminInterfaceEnabled:(BOOL)adminInterfaceEnabled
GrpcStatsDomain:(nullable NSString *)grpcStatsDomain
connectTimeoutSeconds:(UInt32)connectTimeoutSeconds
dnsRefreshSeconds:(UInt32)dnsRefreshSeconds
dnsFailureRefreshSecondsBase:(UInt32)dnsFailureRefreshSecondsBase
dnsFailureRefreshSecondsMax:(UInt32)dnsFailureRefreshSecondsMax
dnsQueryTimeoutSeconds:(UInt32)dnsQueryTimeoutSeconds
dnsPreresolveHostnames:(NSString *)dnsPreresolveHostnames
h2ConnectionKeepaliveIdleIntervalMilliseconds:
(UInt32)h2ConnectionKeepaliveIdleIntervalMilliseconds
h2ConnectionKeepaliveTimeoutSeconds:(UInt32)h2ConnectionKeepaliveTimeoutSeconds
statsFlushSeconds:(UInt32)statsFlushSeconds
streamIdleTimeoutSeconds:(UInt32)streamIdleTimeoutSeconds
appVersion:(NSString *)appVersion
appId:(NSString *)appId
virtualClusters:(NSString *)virtualClusters
directResponseMatchers:(NSString *)directResponseMatchers
directResponses:(NSString *)directResponses
nativeFilterChain:
(NSArray<EnvoyNativeFilterConfig *> *)nativeFilterChain
platformFilterChain:
(NSArray<EnvoyHTTPFilterFactory *> *)httpPlatformFilterFactories
stringAccessors:
(NSDictionary<NSString *, EnvoyStringAccessor *> *)
stringAccessors;

/**
Resolves the provided configuration template using properties on this configuration.
Expand Down
Loading