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 configuring the dispatcher and connection pool of the KubernetesClient shared underlying http client. #8892

Merged
merged 2 commits into from
Feb 26, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,25 @@ che.infra.kubernetes.ingress.annotations_json=NULL
che.infra.kubernetes.pod.security_context.run_as_user=NULL
che.infra.kubernetes.pod.security_context.fs_group=NULL

# Number of maximum concurrent async web requests
# (http requests or ongoing web socket calls)
# supported in the underlying shared http client
# of the `KubernetesClient` instances.
# Default values are 64, and 5 per-host, which
# doesn't seem correct for multi-user scenarios
# knowing that Che keeps a number of connections
# opened (e.g. for command or ws-agent logs)
che.infra.kubernetes.client.http.async_requests.max=1000
che.infra.kubernetes.client.http.async_requests.max_per_host=1000

# Max number of idle connections in the connection pool
# of the Kubernetes-client shared http client
che.infra.kubernetes.client.http.connection_pool.max_idle=5

# Keep-alive timeout of the connection pool
# of the Kubernetes-client shared http client
# in minutes
che.infra.kubernetes.client.http.connection_pool.keep_alive_min=5

### OpenShift Infra parameters
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.fabric8.kubernetes.client.utils.Utils;
import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
import javax.inject.Named;
Expand Down Expand Up @@ -62,10 +63,24 @@ public KubernetesClientFactory(
@Nullable @Named("che.infra.kubernetes.username") String username,
@Nullable @Named("che.infra.kubernetes.password") String password,
@Nullable @Named("che.infra.kubernetes.oauth_token") String oauthToken,
@Nullable @Named("che.infra.kubernetes.trust_certs") Boolean doTrustCerts) {
@Nullable @Named("che.infra.kubernetes.trust_certs") Boolean doTrustCerts,
@Named("che.infra.kubernetes.client.http.async_requests.max") int maxConcurrentRequests,
@Named("che.infra.kubernetes.client.http.async_requests.max_per_host")
int maxConcurrentRequestsPerHost,
@Named("che.infra.kubernetes.client.http.connection_pool.max_idle") int maxIdleConnections,
@Named("che.infra.kubernetes.client.http.connection_pool.keep_alive_min")
int connectionPoolKeepAlive) {
this.defaultConfig =
buildDefaultConfig(masterUrl, username, password, oauthToken, doTrustCerts);
this.httpClient = HttpClientUtils.createHttpClient(defaultConfig);
OkHttpClient temporary = HttpClientUtils.createHttpClient(defaultConfig);
OkHttpClient.Builder builder = temporary.newBuilder();
ConnectionPool oldPool = temporary.connectionPool();
builder.connectionPool(
new ConnectionPool(maxIdleConnections, connectionPoolKeepAlive, TimeUnit.MINUTES));
oldPool.evictAll();
this.httpClient = builder.build();
httpClient.dispatcher().setMaxRequests(maxConcurrentRequests);
httpClient.dispatcher().setMaxRequestsPerHost(maxConcurrentRequestsPerHost);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,23 @@ public OpenShiftClientFactory(
@Nullable @Named("che.infra.kubernetes.username") String username,
@Nullable @Named("che.infra.kubernetes.password") String password,
@Nullable @Named("che.infra.kubernetes.oauth_token") String oauthToken,
@Nullable @Named("che.infra.kubernetes.trust_certs") Boolean doTrustCerts) {
super(masterUrl, username, password, oauthToken, doTrustCerts);
@Nullable @Named("che.infra.kubernetes.trust_certs") Boolean doTrustCerts,
@Named("che.infra.kubernetes.client.http.async_requests.max") int maxConcurrentRequests,
@Named("che.infra.kubernetes.client.http.async_requests.max_per_host")
int maxConcurrentRequestsPerHost,
@Named("che.infra.kubernetes.client.http.connection_pool.max_idle") int maxIdleConnections,
@Named("che.infra.kubernetes.client.http.connection_pool.keep_alive_min")
int connectionPoolKeepAlive) {
super(
masterUrl,
username,
password,
oauthToken,
doTrustCerts,
maxConcurrentRequests,
maxConcurrentRequestsPerHost,
maxIdleConnections,
connectionPoolKeepAlive);
}

protected Config buildDefaultConfig(
Expand Down