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

Thinclient Environment Variables #43188

Merged
merged 16 commits into from
Jan 18, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.netty.handler.ssl.SslContext;
import org.testng.annotations.Test;

import java.net.URI;
import java.util.EnumSet;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -77,71 +78,120 @@ public void httpConnectionWithoutTLSAllowed() {
Configs config = new Configs();
assertThat(config.isHttpConnectionWithoutTLSAllowed()).isFalse();

System.setProperty("COSMOS.HTTP_CONNECTION_WITHOUT_TLS_ALLOWED", "true");
assertThat(config.isHttpConnectionWithoutTLSAllowed()).isTrue();

System.clearProperty("COSMOS.HTTP_CONNECTION_WITHOUT_TLS_ALLOWED");
System.setProperty("COSMOS.HTTP_CONNECTION_WITHOUT_TLS_ALLOWED", "true");
try {
assertThat(config.isHttpConnectionWithoutTLSAllowed()).isTrue();
} finally {
System.clearProperty("COSMOS.HTTP_CONNECTION_WITHOUT_TLS_ALLOWED");
}
}

@Test(groups = { "emulator" })
public void emulatorCertValidationDisabled() {
Configs config = new Configs();
assertThat(config.isEmulatorServerCertValidationDisabled()).isFalse();

System.setProperty("COSMOS.EMULATOR_SERVER_CERTIFICATE_VALIDATION_DISABLED", "true");
assertThat(config.isEmulatorServerCertValidationDisabled()).isTrue();

System.clearProperty("COSMOS.EMULATOR_SERVER_CERTIFICATE_VALIDATION_DISABLED");
System.setProperty("COSMOS.EMULATOR_SERVER_CERTIFICATE_VALIDATION_DISABLED", "true");
try {
assertThat(config.isEmulatorServerCertValidationDisabled()).isTrue();
} finally {
System.clearProperty("COSMOS.EMULATOR_SERVER_CERTIFICATE_VALIDATION_DISABLED");
}
}

@Test(groups = { "emulator" })
public void emulatorHost() {
Configs config = new Configs();
assertThat(config.getEmulatorHost()).isEmpty();

System.setProperty("COSMOS.EMULATOR_HOST", "randomHost");
assertThat(config.getEmulatorHost()).isEqualTo("randomHost");

System.clearProperty("COSMOS.EMULATOR_HOST");
System.setProperty("COSMOS.EMULATOR_HOST", "randomHost");
try {
assertThat(config.getEmulatorHost()).isEqualTo("randomHost");
} finally {
System.clearProperty("COSMOS.EMULATOR_HOST");
}
}

@Test(groups = { "emulator" })
public void http2Enabled() {
assertThat(Configs.isHttp2Enabled()).isFalse();

System.setProperty("COSMOS.HTTP2_ENABLED", "true");
assertThat(Configs.isHttp2Enabled()).isTrue();

System.clearProperty("COSMOS.HTTP2_ENABLED");
System.setProperty("COSMOS.HTTP2_ENABLED", "true");
try {
assertThat(Configs.isHttp2Enabled()).isTrue();
} finally {
System.clearProperty("COSMOS.HTTP2_ENABLED");
}
}

@Test(groups = { "unit" })
public void http2MaxConnectionPoolSize() {
assertThat(Configs.getHttp2MaxConnectionPoolSize()).isEqualTo(1000);

System.setProperty("COSMOS.HTTP2_MAX_CONNECTION_POOL_SIZE", "10");
assertThat(Configs.getHttp2MaxConnectionPoolSize()).isEqualTo(10);

System.clearProperty("COSMOS.HTTP2_MAX_CONNECTION_POOL_SIZE");
System.setProperty("COSMOS.HTTP2_MAX_CONNECTION_POOL_SIZE", "10");
try {
assertThat(Configs.getHttp2MaxConnectionPoolSize()).isEqualTo(10);
} finally {
System.clearProperty("COSMOS.HTTP2_MAX_CONNECTION_POOL_SIZE");
}
}

@Test(groups = { "unit" })
public void http2MinConnectionPoolSize() {
assertThat(Configs.getHttp2MinConnectionPoolSize()).isEqualTo(1);

System.setProperty("COSMOS.HTTP2_MIN_CONNECTION_POOL_SIZE", "10");
assertThat(Configs.getHttp2MinConnectionPoolSize()).isEqualTo(10);

System.clearProperty("COSMOS.HTTP2_MIN_CONNECTION_POOL_SIZE");
System.setProperty("COSMOS.HTTP2_MIN_CONNECTION_POOL_SIZE", "10");
try {
assertThat(Configs.getHttp2MinConnectionPoolSize()).isEqualTo(10);
} finally {
System.clearProperty("COSMOS.HTTP2_MIN_CONNECTION_POOL_SIZE");
}
}

@Test(groups = { "unit" })
public void http2MaxConcurrentStreams() {
assertThat(Configs.getHttp2MaxConcurrentStreams()).isEqualTo(30);

System.clearProperty("COSMOS.HTTP2_MAX_CONCURRENT_STREAMS");
System.setProperty("COSMOS.HTTP2_MAX_CONCURRENT_STREAMS", "10");
assertThat(Configs.getHttp2MaxConcurrentStreams()).isEqualTo(10);
try {
assertThat(Configs.getHttp2MaxConcurrentStreams()).isEqualTo(10);
} finally {
System.clearProperty("COSMOS.HTTP2_MAX_CONCURRENT_STREAMS");
}
}

System.clearProperty("COSMOS.HTTP2_MAX_CONCURRENT_STREAMS");
@Test(groups = { "unit" })
public void thinClientEnabledTest() {
nehrao1 marked this conversation as resolved.
Show resolved Hide resolved
Configs config = new Configs();
assertThat(config.getThinclientEnabled()).isFalse();

System.clearProperty("COSMOS.THINCLIENT_ENABLED");
FabianMeiswinkel marked this conversation as resolved.
Show resolved Hide resolved
System.setProperty("COSMOS.THINCLIENT_ENABLED", "true");
try {
assertThat(config.getThinclientEnabled()).isTrue();
} finally {
System.clearProperty("COSMOS.THINCLIENT_ENABLED");
}
}

@Test(groups = { "unit" })
public void thinClientEndpointTest() {
Configs config = new Configs();
assertThat(config.getThinclientEndpoint()).isEqualTo(URI.create(""));

System.clearProperty("COSMOS.THINCLIENT_ENDPOINT");
System.setProperty("COSMOS.THINCLIENT_ENDPOINT", "testThinClientEndpoint");
try {
assertThat(config.getThinclientEndpoint()).isEqualTo(URI.create("testThinClientEndpoint"));
} finally {
System.clearProperty("COSMOS.THINCLIENT_ENDPOINT");
}
}
}
1 change: 1 addition & 0 deletions sdk/cosmos/azure-cosmos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#### Bugs Fixed

#### Other Changes
* Added temporary internal-only option to enable thin client mode with system property COSMOS.THINCLIENT_ENABLED, setting the thin client endpoint with system property COSMOS.THINCLIENT_ENDPOINT, and default thin client endpoint with system property COSMOS.DEFAULT_THINCLIENT_ENDPOINT while the thin-client transport is still under development. This transport mode is not yet supported or ready to be used by external customers. Please don't use these configs in any production scenario yet. - [PR 43188](https://github.com/Azure/azure-sdk-for-java/pull/43188)

### 4.66.0 (2025-01-14)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
import org.slf4j.LoggerFactory;

import javax.net.ssl.SSLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.time.Duration;
import java.util.Locale;
import java.util.Objects;

import static com.azure.cosmos.implementation.guava25.base.MoreObjects.firstNonNull;
import static com.azure.cosmos.implementation.guava25.base.Strings.emptyToNull;
Expand Down Expand Up @@ -44,6 +47,12 @@ public class Configs {

private static final String UNAVAILABLE_LOCATIONS_EXPIRATION_TIME_IN_SECONDS = "COSMOS.UNAVAILABLE_LOCATIONS_EXPIRATION_TIME_IN_SECONDS";
private static final String GLOBAL_ENDPOINT_MANAGER_INITIALIZATION_TIME_IN_SECONDS = "COSMOS.GLOBAL_ENDPOINT_MANAGER_MAX_INIT_TIME_IN_SECONDS";
private static final String DEFAULT_THINCLIENT_ENDPOINT = "";
private static final String THINCLIENT_ENDPOINT = "COSMOS.THINCLIENT_ENDPOINT";
nehrao1 marked this conversation as resolved.
Show resolved Hide resolved
private static final String THINCLIENT_ENDPOINT_VARIABLE = "COSMOS_THINCLIENT_ENDPOINT";
private static final boolean DEFAULT_THINCLIENT_ENABLED = false;
private static final String THINCLIENT_ENABLED = "COSMOS.THINCLIENT_ENABLED";
private static final String THINCLIENT_ENABLED_VARIABLE = "COSMOS_THINCLIENT_ENABLED";

private static final String MAX_HTTP_BODY_LENGTH_IN_BYTES = "COSMOS.MAX_HTTP_BODY_LENGTH_IN_BYTES";
private static final String MAX_HTTP_INITIAL_LINE_LENGTH_IN_BYTES = "COSMOS.MAX_HTTP_INITIAL_LINE_LENGTH_IN_BYTES";
Expand Down Expand Up @@ -405,6 +414,34 @@ public int getGlobalEndpointManagerMaxInitializationTimeInSeconds() {
return getJVMConfigAsInt(GLOBAL_ENDPOINT_MANAGER_INITIALIZATION_TIME_IN_SECONDS, DEFAULT_GLOBAL_ENDPOINT_MANAGER_INITIALIZATION_TIME_IN_SECONDS);
}

public URI getThinclientEndpoint() {
String valueFromSystemProperty = System.getProperty(THINCLIENT_ENDPOINT);
if (valueFromSystemProperty != null && !valueFromSystemProperty.isEmpty()) {
return URI.create(valueFromSystemProperty);
}

String valueFromEnvVariable = System.getenv(THINCLIENT_ENDPOINT_VARIABLE);
if (valueFromEnvVariable != null && !valueFromEnvVariable.isEmpty()) {
return URI.create(valueFromEnvVariable);
}

return URI.create(DEFAULT_THINCLIENT_ENDPOINT);
}

public static boolean getThinclientEnabled() {
String valueFromSystemProperty = System.getProperty(THINCLIENT_ENABLED);
if (valueFromSystemProperty != null && !valueFromSystemProperty.isEmpty()) {
return Boolean.parseBoolean(valueFromSystemProperty);
}

String valueFromEnvVariable = System.getenv(THINCLIENT_ENABLED_VARIABLE);
if (valueFromEnvVariable != null && !valueFromEnvVariable.isEmpty()) {
return Boolean.parseBoolean(valueFromEnvVariable);
}

return DEFAULT_THINCLIENT_ENABLED;
}

public int getUnavailableLocationsExpirationTimeInSeconds() {
return getJVMConfigAsInt(UNAVAILABLE_LOCATIONS_EXPIRATION_TIME_IN_SECONDS, DEFAULT_UNAVAILABLE_LOCATIONS_EXPIRATION_TIME_IN_SECONDS);
}
Expand Down
Loading