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

[plugin] repository-azure: add configuration settings for connect/write/response/read timeouts #1789

Merged
merged 3 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ public List<Setting<?>> getSettings() {
AzureStorageSettings.MAX_RETRIES_SETTING,
AzureStorageSettings.PROXY_TYPE_SETTING,
AzureStorageSettings.PROXY_HOST_SETTING,
AzureStorageSettings.PROXY_PORT_SETTING
AzureStorageSettings.PROXY_PORT_SETTING,
AzureStorageSettings.CONNECTION_TIMEOUT_SETTING,
AzureStorageSettings.WRITE_TIMEOUT_SETTING,
AzureStorageSettings.READ_TIMEOUT_SETTING,
AzureStorageSettings.RESPONSE_TIMEOUT_SETTING
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import org.opensearch.common.settings.SettingsException;
import org.opensearch.common.unit.ByteSizeUnit;
import org.opensearch.common.unit.ByteSizeValue;
import org.opensearch.common.unit.TimeValue;

import java.net.InetSocketAddress;
import java.net.Proxy;
Expand Down Expand Up @@ -178,6 +179,26 @@ private ClientState buildClient(AzureStorageSettings azureStorageSettings, BiCon
clientBuilder.proxy(new ProxyOptions(type, (InetSocketAddress) proxy.address()));
}

final TimeValue connectionTimeout = azureStorageSettings.getConnectionTimeout();
if (connectionTimeout != null) {
clientBuilder.connectTimeout(Duration.ofMillis(connectionTimeout.millis()));
}

final TimeValue writeTimeout = azureStorageSettings.getWriteTimeout();
if (writeTimeout != null) {
clientBuilder.writeTimeout(Duration.ofMillis(writeTimeout.millis()));
}

final TimeValue readTimeout = azureStorageSettings.getReadTimeout();
if (readTimeout != null) {
clientBuilder.readTimeout(Duration.ofMillis(readTimeout.millis()));
}

final TimeValue responseTimeout = azureStorageSettings.getResponseTimeout();
if (responseTimeout != null) {
clientBuilder.responseTimeout(Duration.ofMillis(responseTimeout.millis()));
}

builder.httpClient(clientBuilder.build());

// We define a default exponential retry policy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,42 @@ final class AzureStorageSettings {
() -> KEY_SETTING
);

// See please NettyAsyncHttpClientBuilder#DEFAULT_CONNECT_TIMEOUT
public static final AffixSetting<TimeValue> CONNECTION_TIMEOUT_SETTING = Setting.affixKeySetting(
AZURE_CLIENT_PREFIX_KEY,
"connection.timeout",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, but what do you think about using "connect" instead of "connection" for this setting and the variable names to keep it consistent with the underlying Azure property?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrross thank you, sure, no objections, renaming

(key) -> Setting.timeSetting(key, TimeValue.timeValueSeconds(10), Property.NodeScope),
() -> ACCOUNT_SETTING,
() -> KEY_SETTING
);

// See please NettyAsyncHttpClientBuilder#DEFAULT_WRITE_TIMEOUT
public static final AffixSetting<TimeValue> WRITE_TIMEOUT_SETTING = Setting.affixKeySetting(
AZURE_CLIENT_PREFIX_KEY,
"write.timeout",
(key) -> Setting.timeSetting(key, TimeValue.timeValueSeconds(60), Property.NodeScope),
() -> ACCOUNT_SETTING,
() -> KEY_SETTING
);

// See please NettyAsyncHttpClientBuilder#DEFAULT_READ_TIMEOUT
public static final AffixSetting<TimeValue> READ_TIMEOUT_SETTING = Setting.affixKeySetting(
AZURE_CLIENT_PREFIX_KEY,
"read.timeout",
(key) -> Setting.timeSetting(key, TimeValue.timeValueSeconds(60), Property.NodeScope),
() -> ACCOUNT_SETTING,
() -> KEY_SETTING
);

// See please NettyAsyncHttpClientBuilder#DEFAULT_RESPONSE_TIMEOUT
public static final AffixSetting<TimeValue> RESPONSE_TIMEOUT_SETTING = Setting.affixKeySetting(
AZURE_CLIENT_PREFIX_KEY,
"response.timeout",
(key) -> Setting.timeSetting(key, TimeValue.timeValueSeconds(60), Property.NodeScope),
() -> ACCOUNT_SETTING,
() -> KEY_SETTING
);

/** The type of the proxy to connect to azure through. Can be direct (no proxy, default), http or socks */
public static final AffixSetting<Proxy.Type> PROXY_TYPE_SETTING = Setting.affixKeySetting(
AZURE_CLIENT_PREFIX_KEY,
Expand Down Expand Up @@ -142,6 +178,10 @@ final class AzureStorageSettings {
private final int maxRetries;
private final Proxy proxy;
private final LocationMode locationMode;
private final TimeValue connectionTimeout;
private final TimeValue writeTimeout;
private final TimeValue readTimeout;
private final TimeValue responseTimeout;

// copy-constructor
private AzureStorageSettings(
Expand All @@ -151,7 +191,11 @@ private AzureStorageSettings(
TimeValue timeout,
int maxRetries,
Proxy proxy,
LocationMode locationMode
LocationMode locationMode,
TimeValue connectionTimeout,
TimeValue writeTimeout,
TimeValue readTimeout,
TimeValue responseTimeout
) {
this.account = account;
this.connectString = connectString;
Expand All @@ -160,6 +204,10 @@ private AzureStorageSettings(
this.maxRetries = maxRetries;
this.proxy = proxy;
this.locationMode = locationMode;
this.connectionTimeout = connectionTimeout;
this.writeTimeout = writeTimeout;
this.readTimeout = readTimeout;
this.responseTimeout = responseTimeout;
}

private AzureStorageSettings(
Expand All @@ -171,7 +219,11 @@ private AzureStorageSettings(
int maxRetries,
Proxy.Type proxyType,
String proxyHost,
Integer proxyPort
Integer proxyPort,
TimeValue connectionTimeout,
TimeValue writeTimeout,
TimeValue readTimeout,
TimeValue responseTimeout
) {
this.account = account;
this.connectString = buildConnectString(account, key, sasToken, endpointSuffix);
Expand All @@ -197,6 +249,10 @@ private AzureStorageSettings(
}
}
this.locationMode = LocationMode.PRIMARY_ONLY;
this.connectionTimeout = connectionTimeout;
this.writeTimeout = writeTimeout;
this.readTimeout = readTimeout;
this.responseTimeout = responseTimeout;
}

public String getEndpointSuffix() {
Expand Down Expand Up @@ -245,6 +301,22 @@ public LocationMode getLocationMode() {
return locationMode;
}

public TimeValue getConnectionTimeout() {
return connectionTimeout;
}

public TimeValue getWriteTimeout() {
return writeTimeout;
}

public TimeValue getReadTimeout() {
return readTimeout;
}

public TimeValue getResponseTimeout() {
return responseTimeout;
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("AzureStorageSettings{");
Expand All @@ -254,6 +326,10 @@ public String toString() {
sb.append(", maxRetries=").append(maxRetries);
sb.append(", proxy=").append(proxy);
sb.append(", locationMode='").append(locationMode).append('\'');
sb.append(", connectionTimeout='").append(connectionTimeout).append('\'');
sb.append(", writeTimeout='").append(writeTimeout).append('\'');
sb.append(", readTimeout='").append(readTimeout).append('\'');
sb.append(", responseTimeout='").append(responseTimeout).append('\'');
sb.append('}');
return sb.toString();
}
Expand Down Expand Up @@ -296,7 +372,11 @@ private static AzureStorageSettings getClientSettings(Settings settings, String
getValue(settings, clientName, MAX_RETRIES_SETTING),
getValue(settings, clientName, PROXY_TYPE_SETTING),
getValue(settings, clientName, PROXY_HOST_SETTING),
getValue(settings, clientName, PROXY_PORT_SETTING)
getValue(settings, clientName, PROXY_PORT_SETTING),
getValue(settings, clientName, CONNECTION_TIMEOUT_SETTING),
getValue(settings, clientName, WRITE_TIMEOUT_SETTING),
getValue(settings, clientName, READ_TIMEOUT_SETTING),
getValue(settings, clientName, RESPONSE_TIMEOUT_SETTING)
);
}
}
Expand Down Expand Up @@ -327,7 +407,11 @@ static Map<String, AzureStorageSettings> overrideLocationMode(
entry.getValue().timeout,
entry.getValue().maxRetries,
entry.getValue().proxy,
locationMode
locationMode,
entry.getValue().connectionTimeout,
entry.getValue().writeTimeout,
entry.getValue().readTimeout,
entry.getValue().responseTimeout
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.opensearch.common.settings.Settings;
import org.opensearch.common.settings.SettingsException;
import org.opensearch.common.settings.SettingsModule;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.test.OpenSearchTestCase;

import java.io.IOException;
Expand Down Expand Up @@ -217,6 +218,62 @@ public void testGetSelectedClientDefaultTimeout() {
assertThat(azureStorageService.getBlobRequestTimeout("azure3"), is(Duration.ofSeconds(30)));
}

public void testClientDefaultConnectionTimeout() {
final Settings settings = Settings.builder()
.setSecureSettings(buildSecureSettings())
.put("azure.client.azure3.connection.timeout", "25s")
.build();
final AzureStorageService mock = storageServiceWithSettingsValidation(settings);
final TimeValue timeout = mock.storageSettings.get("azure3").getConnectionTimeout();

assertThat(timeout, notNullValue());
assertThat(timeout, equalTo(TimeValue.timeValueSeconds(25)));
assertThat(mock.storageSettings.get("azure2").getConnectionTimeout(), notNullValue());
assertThat(mock.storageSettings.get("azure2").getConnectionTimeout(), equalTo(TimeValue.timeValueSeconds(10)));
}

public void testClientDefaultWriteTimeout() {
final Settings settings = Settings.builder()
.setSecureSettings(buildSecureSettings())
.put("azure.client.azure3.write.timeout", "85s")
.build();
final AzureStorageService mock = storageServiceWithSettingsValidation(settings);
final TimeValue timeout = mock.storageSettings.get("azure3").getWriteTimeout();

assertThat(timeout, notNullValue());
assertThat(timeout, equalTo(TimeValue.timeValueSeconds(85)));
assertThat(mock.storageSettings.get("azure2").getWriteTimeout(), notNullValue());
assertThat(mock.storageSettings.get("azure2").getWriteTimeout(), equalTo(TimeValue.timeValueSeconds(60)));
}

public void testClientDefaultReadTimeout() {
final Settings settings = Settings.builder()
.setSecureSettings(buildSecureSettings())
.put("azure.client.azure3.read.timeout", "120s")
.build();
final AzureStorageService mock = storageServiceWithSettingsValidation(settings);
final TimeValue timeout = mock.storageSettings.get("azure3").getReadTimeout();

assertThat(timeout, notNullValue());
assertThat(timeout, equalTo(TimeValue.timeValueSeconds(120)));
assertThat(mock.storageSettings.get("azure2").getReadTimeout(), notNullValue());
assertThat(mock.storageSettings.get("azure2").getReadTimeout(), equalTo(TimeValue.timeValueSeconds(60)));
}

public void testClientDefaultResponseTimeout() {
final Settings settings = Settings.builder()
.setSecureSettings(buildSecureSettings())
.put("azure.client.azure3.response.timeout", "1ms")
.build();
final AzureStorageService mock = storageServiceWithSettingsValidation(settings);
final TimeValue timeout = mock.storageSettings.get("azure3").getResponseTimeout();

assertThat(timeout, notNullValue());
assertThat(timeout, equalTo(TimeValue.timeValueMillis(1)));
assertThat(mock.storageSettings.get("azure2").getResponseTimeout(), notNullValue());
assertThat(mock.storageSettings.get("azure2").getResponseTimeout(), equalTo(TimeValue.timeValueSeconds(60)));
}

public void testGetSelectedClientNoTimeout() {
final AzureStorageService azureStorageService = storageServiceWithSettingsValidation(buildSettings());
assertThat(azureStorageService.getBlobRequestTimeout("azure1"), nullValue());
Expand Down