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

Allow setting of HTTP client timeouts with system properties #24

Merged
merged 1 commit into from
Jun 23, 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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

This is an API plugin for Azure libraries. Users should not install this directly

## Configuration

It is possible to configure some settings with Java System Properties, specified with `-Dproperty=value` in the command line.

### Http Client

* `io.jenkins.plugins.azuresdk.HttpClientRetriever.readTimeoutSeconds` - This sets the read timeout (in seconds) of the HTTP client used for Azure API requests.
* `io.jenkins.plugins.azuresdk.HttpClientRetriever.responseTimeoutSeconds` - This sets the response timeout (in seconds) of the HTTP client used for Azure API requests.
* `io.jenkins.plugins.azuresdk.HttpClientRetriever.writeTimeoutSeconds` - This sets the write timeout (in seconds) of the HTTP client used for Azure API requests.

## Contributing

Refer to our [contribution guidelines](https://github.com/jenkinsci/.github/blob/master/CONTRIBUTING.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import com.azure.core.http.netty.NettyAsyncHttpClientBuilder;
import hudson.ProxyConfiguration;
import hudson.Util;
import java.time.Duration;
import jenkins.model.Jenkins;
import jenkins.util.JenkinsJVM;

import java.net.InetSocketAddress;
import jenkins.util.SystemProperties;

public class HttpClientRetriever {

Expand All @@ -25,7 +27,7 @@ public static HttpClient get() {
return get(proxy);
}
}
return new NettyAsyncHttpClientBuilder().build();
return getBuilder().build();
}

public static HttpClient get(ProxyConfiguration proxy) {
Expand All @@ -42,6 +44,26 @@ public static HttpClient get(ProxyConfiguration proxy) {
}
}

return new NettyAsyncHttpClientBuilder().proxy(proxyOptions).build();
return getBuilder().proxy(proxyOptions).build();
}

private static NettyAsyncHttpClientBuilder getBuilder() {
NettyAsyncHttpClientBuilder builder = new NettyAsyncHttpClientBuilder();

// Apply settings from system properties
Long readTimeoutSeconds = SystemProperties.getLong(HttpClientRetriever.class.getName() + ".readTimeoutSeconds");
if (readTimeoutSeconds != null) {
builder.readTimeout(Duration.ofSeconds(readTimeoutSeconds));
}
Long responseTimeoutSeconds = SystemProperties.getLong(HttpClientRetriever.class.getName() + ".responseTimeoutSeconds");
if (responseTimeoutSeconds != null) {
builder.responseTimeout(Duration.ofSeconds(responseTimeoutSeconds));
}
Long writeTimeoutSeconds = SystemProperties.getLong(HttpClientRetriever.class.getName() + ".writeTimeoutSeconds");
if (writeTimeoutSeconds != null) {
builder.writeTimeout(Duration.ofSeconds(writeTimeoutSeconds));
}

return builder;
}
}