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

EnableHttp2PublicAPI #43123

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public void rntbd() throws Exception {
assertThat(objectNode.get("numberOfClients").asInt()).isEqualTo(2);
assertThat(objectNode.get("consistencyCfg").asText()).isEqualTo("(consistency: null, mm: false, prgns: [null])");
assertThat(objectNode.get("connCfg").get("rntbd").asText()).isEqualTo("(cto:PT5S, nrto:PT5S, icto:PT0S, ieto:PT1H, mcpe:130, mrpc:30, cer:true)");
assertThat(objectNode.get("connCfg").get("gw").asText()).isEqualTo("(cps:1000, nrto:PT1M, icto:PT1M, cto:PT45S, p:false)");
assertThat(objectNode.get("connCfg").get("gw").asText()).isEqualTo("(cps:1000, nrto:PT1M, icto:PT1M, cto:PT45S, p:false, http2:(enabled:false, maxc:1000, minc:1, maxs:30))");
assertThat(objectNode.get("connCfg").get("other").asText()).isEqualTo("(ed: false, cs: false, rv: true)");
}

Expand Down Expand Up @@ -237,7 +237,7 @@ public void gw() throws Exception {
assertThat(objectNode.get("numberOfClients").asInt()).isEqualTo(2);
assertThat(objectNode.get("consistencyCfg").asText()).isEqualTo("(consistency: null, mm: false, prgns: [null])");
assertThat(objectNode.get("connCfg").get("rntbd").asText()).isEqualTo("null");
assertThat(objectNode.get("connCfg").get("gw").asText()).isEqualTo("(cps:500, nrto:PT18S, icto:PT17S, cto:PT45S, p:false)");
assertThat(objectNode.get("connCfg").get("gw").asText()).isEqualTo("(cps:500, nrto:PT18S, icto:PT17S, cto:PT45S, p:false, http2:(enabled:false, maxc:1000, minc:1, maxs:30))");
assertThat(objectNode.get("connCfg").get("other").asText()).isEqualTo("(ed: false, cs: false, rv: true)");
}

Expand Down Expand Up @@ -309,7 +309,7 @@ public void full(
assertThat(objectNode.get("numberOfClients").asInt()).isEqualTo(2);
assertThat(objectNode.get("consistencyCfg").asText()).isEqualTo("(consistency: null, mm: false, prgns: [westus1,westus2])");
assertThat(objectNode.get("connCfg").get("rntbd").asText()).isEqualTo("null");
assertThat(objectNode.get("connCfg").get("gw").asText()).isEqualTo("(cps:500, nrto:PT18S, icto:PT17S, cto:PT45S, p:false)");
assertThat(objectNode.get("connCfg").get("gw").asText()).isEqualTo("(cps:500, nrto:PT18S, icto:PT17S, cto:PT45S, p:false, http2:(enabled:false, maxc:1000, minc:1, maxs:30))");
assertThat(objectNode.get("connCfg").get("other").asText()).isEqualTo("(ed: true, cs: true, rv: false)");
assertThat(objectNode.get("excrgns").asText()).isEqualTo("[westus2]");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import com.azure.cosmos.implementation.clienttelemetry.MetricCategory;
import com.azure.cosmos.implementation.clienttelemetry.TagName;
import com.azure.cosmos.implementation.directconnectivity.Protocol;
import com.azure.cosmos.implementation.directconnectivity.ReflectionUtils;
import io.netty.handler.ssl.SslContext;
import org.testng.annotations.Test;

import java.util.EnumSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.azure.cosmos.CosmosResponseValidator;
import com.azure.cosmos.DirectConnectionConfig;
import com.azure.cosmos.GatewayConnectionConfig;
import com.azure.cosmos.Http2ConnectionConfig;
import com.azure.cosmos.TestNGLogListener;
import com.azure.cosmos.ThrottlingRetryOptions;
import com.azure.cosmos.implementation.Configs;
Expand Down Expand Up @@ -1444,6 +1445,15 @@ static protected CosmosClientBuilder createGatewayRxDocumentClient(
boolean retryOnThrottledRequests) {

GatewayConnectionConfig gatewayConnectionConfig = new GatewayConnectionConfig();
if (Configs.isHttp2Enabled()) {
Http2ConnectionConfig http2ConnectionConfig = new Http2ConnectionConfig()
.setEnabled(true)
.setMaxConnectionPoolSize(10)
.setMinConnectionPoolSize(1)
.setMaxConcurrentStreams(30);
gatewayConnectionConfig.setHttp2ConnectionConfig(http2ConnectionConfig);
}

CosmosClientBuilder builder = new CosmosClientBuilder().endpoint(endpoint)
.credential(credential)
.gatewayMode(gatewayConnectionConfig)
Expand Down
3 changes: 2 additions & 1 deletion sdk/cosmos/azure-cosmos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
### 4.66.0-beta.1 (Unreleased)

#### Features Added
* Added Beta public API fto enable http2. - See [PR 43123](https://github.com/Azure/azure-sdk-for-java/pull/43123)

#### Breaking Changes

#### Bugs Fixed

#### Other Changes
* Added support to enable http2 for gateway mode with system property `COSMOS.HTTP2_ENABLED` and system variable `COSMOS_HTTP2_ENABLED`. - [PR 42947](https://github.com/Azure/azure-sdk-for-java/pull/42947)
* Added support to enable http2 for gateway mode with system property `COSMOS.HTTP2_ENABLED` and system variable `COSMOS_HTTP2_ENABLED`. - See [PR 42947](https://github.com/Azure/azure-sdk-for-java/pull/42947)
* Added support to allow changing http2 max connection pool size with system property `COSMOS.HTTP2_MAX_CONNECTION_POOL_SIZE` and system variable `COSMOS_HTTP2_MAX_CONNECTION_POOL_SIZE`. - [PR 42947](https://github.com/Azure/azure-sdk-for-java/pull/42947)
xinlian12 marked this conversation as resolved.
Show resolved Hide resolved
xinlian12 marked this conversation as resolved.
Show resolved Hide resolved
* Added support to allow changing http2 max connection pool size with system property `COSMOS.HTTP2_MIN_CONNECTION_POOL_SIZE` and system variable `COSMOS_HTTP2_MIN_CONNECTION_POOL_SIZE`. - [PR 42947](https://github.com/Azure/azure-sdk-for-java/pull/42947)
xinlian12 marked this conversation as resolved.
Show resolved Hide resolved
* Added support to allow changing http2 max connection pool size with system property `COSMOS.HTTP2_MAX_CONCURRENT_STREAMS` and system variable `COSMOS_HTTP2_MAX_CONCURRENT_STREAMS`. - [PR 42947](https://github.com/Azure/azure-sdk-for-java/pull/42947)
xinlian12 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.azure.core.http.ProxyOptions;
import com.azure.cosmos.implementation.Configs;
import com.azure.cosmos.util.Beta;

import java.time.Duration;

Expand All @@ -24,6 +25,7 @@ public final class GatewayConnectionConfig {
private int maxConnectionPoolSize;
private Duration idleConnectionTimeout;
private ProxyOptions proxy;
private Http2ConnectionConfig http2ConnectionConfig;

/**
* Constructor.
Expand All @@ -32,6 +34,7 @@ public GatewayConnectionConfig() {
this.idleConnectionTimeout = DEFAULT_IDLE_CONNECTION_TIMEOUT;
this.maxConnectionPoolSize = Configs.getDefaultHttpPoolSize();
this.networkRequestTimeout = DEFAULT_NETWORK_REQUEST_TIMEOUT;
this.http2ConnectionConfig = new Http2ConnectionConfig();
}

/**
Expand Down Expand Up @@ -136,6 +139,27 @@ public GatewayConnectionConfig setProxy(ProxyOptions proxy) {
return this;
}

/***
* Get the http2 connection config.
* @return the {@link Http2ConnectionConfig}.
*/
@Beta(value = Beta.SinceVersion.V4_66_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public Http2ConnectionConfig getHttp2ConnectionConfig() {
return http2ConnectionConfig;
}

/***
* Set the http2 connection config.
* @param http2ConnectionConfig the {@link Http2ConnectionConfig}.
*/
@Beta(value = Beta.SinceVersion.V4_66_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public GatewayConnectionConfig setHttp2ConnectionConfig(Http2ConnectionConfig http2ConnectionConfig) {
checkNotNull(http2ConnectionConfig, "Argument 'http2ConnectionConfig' can not be null");

this.http2ConnectionConfig = http2ConnectionConfig;
return this;
}

@Override
public String toString() {
String proxyType = proxy != null ? proxy.getType().toString() : null;
Expand All @@ -147,6 +171,7 @@ public String toString() {
", networkRequestTimeout=" + networkRequestTimeout +
", proxyType=" + proxyType +
", inetSocketProxyAddress=" + proxyAddress +
", http2ConnectionConfig=" + http2ConnectionConfig.toDiagnosticsString() +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.cosmos;

import com.azure.cosmos.implementation.Configs;
import com.azure.cosmos.util.Beta;

@Beta(value = Beta.SinceVersion.V4_66_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public class Http2ConnectionConfig {
private static final int DEFAULT_MAX_CONCURRENT_STREAMS = 30;
private static final int DEFAULT_MIN_CONNECTION_POOL_SIZE = 1;

private int maxConnectionPoolSize;
private int minConnectionPoolSize;
private int maxConcurrentStreams;
private boolean enabled;

@Beta(value = Beta.SinceVersion.V4_66_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public Http2ConnectionConfig() {
this.maxConnectionPoolSize = Configs.getDefaultHttpPoolSize(); // overlapping with the maxConnectionPoolSize in gateway connection config
this.minConnectionPoolSize = DEFAULT_MIN_CONNECTION_POOL_SIZE;
xinlian12 marked this conversation as resolved.
Show resolved Hide resolved
this.maxConcurrentStreams = DEFAULT_MAX_CONCURRENT_STREAMS;
this.enabled = Configs.isHttp2Enabled();
}

/***
* Get the maximum number of live connections to keep in the pool.
*
* @return the configured max number of live connections to keep in the pool.
*/
@Beta(value = Beta.SinceVersion.V4_66_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public int getMaxConnectionPoolSize() {
return maxConnectionPoolSize;
}

/***
* Configures the maximum number of live connections to keep in the pool.
* If not configured, will be default to 1000.
*
* @param maxConnectionPoolSize the maximum number of live connections to keep in the pool.
* @return the current {@link Http2ConnectionConfig}.
*/
@Beta(value = Beta.SinceVersion.V4_66_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public Http2ConnectionConfig setMaxConnectionPoolSize(int maxConnectionPoolSize) {
this.maxConnectionPoolSize = maxConnectionPoolSize;
return this;
}

/***
* Get the maximum number of the concurrent streams that can be opened to the remote peer.
* @return the maximum number of the concurrent streams that can be opened to the remote peer.
*/
@Beta(value = Beta.SinceVersion.V4_66_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public int getMaxConcurrentStreams() {
return maxConcurrentStreams;
}

/***
* Configures the maximum number of the concurrent streams that can be opened to the remote peer.
* When evaluating how many streams can be opened to the remote peer, the minimum of this configuration and the remote peer configuration is taken (unless -1 is used).
* Default to 30.
*
* @param maxConcurrentStreams the maximum number of the concurrent streams that can be opened to the remote peer.
* @return the current {@link Http2ConnectionConfig}.
*/
@Beta(value = Beta.SinceVersion.V4_66_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public Http2ConnectionConfig setMaxConcurrentStreams(int maxConcurrentStreams) {
this.maxConcurrentStreams = maxConcurrentStreams;
return this;
}

/***
* Get the minimum number of live connections to keep in the pool (can be the best effort).
* @return the minimum number of live connections to keep in the pool (can be the best effort).
*/
@Beta(value = Beta.SinceVersion.V4_66_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public int getMinConnectionPoolSize() {
return minConnectionPoolSize;
}

/***
* Configures the minimum number of live connections to keep in the pool (can be the best effort). Default to 1.
* @param minConnectionPoolSize the minimum number of live connections to keep in the pool (can be the best effort).
* @return the current {@link Http2ConnectionConfig}.
*/
@Beta(value = Beta.SinceVersion.V4_66_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public Http2ConnectionConfig setMinConnectionPoolSize(int minConnectionPoolSize) {
this.minConnectionPoolSize = minConnectionPoolSize;
return this;
}

/***
* return the flag to indicate whether http2 is enabled.
* @return the flag to indicate whether http2 is enabled.
*/
@Beta(value = Beta.SinceVersion.V4_66_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public boolean isEnabled() {
return enabled;
}

/***
* Configure the flag to indicate whether http2 is enabled.
* @param enabled the flag to indicate whether http2 is enabled.
* @return the current {@link Http2ConnectionConfig}.
*/
@Beta(value = Beta.SinceVersion.V4_66_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public Http2ConnectionConfig setEnabled(boolean enabled) {
this.enabled = enabled;
return this;
}

@Beta(value = Beta.SinceVersion.V4_66_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public String toDiagnosticsString() {
return String.format("(enabled:%s, maxc:%s, minc:%s, maxs:%s)",
isEnabled(),
maxConnectionPoolSize,
minConnectionPoolSize,
maxConcurrentStreams);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
import com.azure.cosmos.CosmosExcludedRegions;
import com.azure.cosmos.DirectConnectionConfig;
import com.azure.cosmos.GatewayConnectionConfig;
import com.azure.cosmos.Http2ConnectionConfig;
import com.azure.cosmos.ThrottlingRetryOptions;

import java.time.Duration;
import java.util.Collections;
import java.util.List;
import java.util.function.Supplier;

import static com.azure.cosmos.implementation.guava25.base.Preconditions.checkNotNull;

/**
* Represents the Connection policy associated with a Cosmos client in the Azure Cosmos DB service.
*/
Expand All @@ -38,6 +41,7 @@ public final class ConnectionPolicy {
private Duration httpNetworkRequestTimeout;
private ProxyOptions proxy;
private Duration idleHttpConnectionTimeout;
private Http2ConnectionConfig http2ConnectionConfig;

// Direct connection config properties
private Duration connectTimeout;
Expand Down Expand Up @@ -100,6 +104,7 @@ private ConnectionPolicy(
.DirectConnectionConfigHelper
.getDirectConnectionConfigAccessor()
.isHealthCheckTimeoutDetectionEnabled(directConnectionConfig);
this.http2ConnectionConfig = gatewayConnectionConfig.getHttp2ConnectionConfig();

// NOTE: should be compared with COSMOS.MIN_CONNECTION_POOL_SIZE_PER_ENDPOINT
// read during client initialization before connections are created for the container
Expand Down Expand Up @@ -635,6 +640,27 @@ public boolean isServerCertValidationDisabled() {
return this.serverCertValidationDisabled;
}

/***
* Get the Http2ConnectionConfig for gateway request.
* @return the configured {@link Http2ConnectionConfig}.
*/
public Http2ConnectionConfig getHttp2ConnectionConfig() {
return http2ConnectionConfig;
}

/***
* Set the Http2ConnectionConfig for gateway request.
*
* @param http2ConnectionConfig the configured http2ConnectionConfig.
* @return the current {@link ConnectionPolicy}.
*/
public ConnectionPolicy setHttp2ConnectionConfig(Http2ConnectionConfig http2ConnectionConfig) {
checkNotNull(http2ConnectionConfig, "Argument 'http2ConnectionConfig' can not be null");

this.http2ConnectionConfig = http2ConnectionConfig;
return this;
}

@Override
public String toString() {
return "ConnectionPolicy{" +
Expand Down Expand Up @@ -663,6 +689,7 @@ public String toString() {
", minConnectionPoolSizePerEndpoint=" + minConnectionPoolSizePerEndpoint +
", openConnectionsConcurrency=" + openConnectionsConcurrency +
", aggressiveWarmupConcurrency=" + aggressiveWarmupConcurrency +
", http2ConnectionConfig=" + this.http2ConnectionConfig.toDiagnosticsString() +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import com.azure.cosmos.implementation.directconnectivity.StoreClientFactory;
import com.azure.cosmos.implementation.faultinjection.IFaultInjectorProvider;
import com.azure.cosmos.implementation.feedranges.FeedRangeEpkImpl;
import com.azure.cosmos.implementation.http.Http2ConnectionConfig;
import com.azure.cosmos.implementation.http.HttpClient;
import com.azure.cosmos.implementation.http.HttpClientConfig;
import com.azure.cosmos.implementation.http.HttpHeaders;
Expand Down Expand Up @@ -833,7 +832,7 @@ private HttpClient httpClient() {
.withProxy(this.connectionPolicy.getProxy())
.withNetworkRequestTimeout(this.connectionPolicy.getHttpNetworkRequestTimeout())
.withServerCertValidationDisabled(this.connectionPolicy.isServerCertValidationDisabled())
.withHttp2Config(new Http2ConnectionConfig());
.withHttp2ConnectionConfig(this.connectionPolicy.getHttp2ConnectionConfig());

if (connectionSharingAcrossClientsEnabled) {
return SharedGatewayHttpClient.getOrCreateInstance(httpClientConfig, diagnosticsClientConfig);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ static HttpClient createFixed(HttpClientConfig httpClientConfig) {
fixedConnectionProviderBuilder.pendingAcquireTimeout(httpClientConfig.getConnectionAcquireTimeout());
fixedConnectionProviderBuilder.maxIdleTime(httpClientConfig.getMaxIdleConnectionTimeout());

if (httpClientConfig.getHttp2Config().isEnabled()) {
if (httpClientConfig.getHttp2ConnectionConfig().isEnabled()) {
fixedConnectionProviderBuilder.allocationStrategy(
Http2AllocationStrategy.builder()
.maxConnections(httpClientConfig.getHttp2Config().getMaxConnectionPoolSize())
.minConnections(httpClientConfig.getHttp2Config().getMinConnectionPoolSize())
.maxConcurrentStreams(httpClientConfig.getHttp2Config().getMaxConcurrentStreams())
.minConnections(httpClientConfig.getHttp2ConnectionConfig().getMinConnectionPoolSize())
.maxConnections(httpClientConfig.getHttp2ConnectionConfig().getMaxConnectionPoolSize())
.maxConcurrentStreams(httpClientConfig.getHttp2ConnectionConfig().getMaxConcurrentStreams())
.build()
);
}
Expand Down
Loading
Loading