Skip to content

Commit

Permalink
Allow setting of HTTP client timeouts with system properties (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
krische authored Jun 23, 2021
1 parent e607086 commit 5682688
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
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
26 changes: 24 additions & 2 deletions src/main/java/io/jenkins/plugins/azuresdk/HttpClientRetriever.java
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;
}
}

0 comments on commit 5682688

Please sign in to comment.