Skip to content

Commit

Permalink
Adapt
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlatombe committed Dec 30, 2021
1 parent 8b51304 commit 6e06139
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 56 deletions.
Expand Up @@ -10,10 +10,6 @@

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import hudson.model.PeriodicWork;
import io.fabric8.kubernetes.client.HttpClientAware;
import okhttp3.Dispatcher;
import okhttp3.OkHttpClient;
import org.jenkinsci.plugins.kubernetes.auth.KubernetesAuthException;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
Expand Down Expand Up @@ -92,17 +88,6 @@ public int getValidity() {
}
}

private static volatile int runningCallsCount;
private static volatile int queuedCallsCount;

public static int getRunningCallsCount() {
return runningCallsCount;
}

public static int getQueuedCallsCount() {
return queuedCallsCount;
}

@Restricted(NoExternalUse.class) // testing only
public static void invalidate(String displayName) {
clients.invalidate(displayName);
Expand Down Expand Up @@ -131,30 +116,4 @@ public void onChange(Saveable o, XmlFile file) {
super.onChange(o, file);
}
}

@Extension
public static class UpdateConnectionCount extends PeriodicWork {

@Override
public long getRecurrencePeriod() {
return TimeUnit.SECONDS.toMillis(5);
}

@Override
protected void doRun() {
int runningCallsCount = 0;
int queuedCallsCount = 0;
for (Client client : KubernetesClientProvider.clients.asMap().values()) {
KubernetesClient kClient = client.getClient();
if (kClient instanceof HttpClientAware) {
OkHttpClient httpClient = ((HttpClientAware) kClient).getHttpClient();
Dispatcher dispatcher = httpClient.dispatcher();
runningCallsCount += dispatcher.runningCallsCount();
queuedCallsCount += dispatcher.queuedCallsCount();
}
}
KubernetesClientProvider.runningCallsCount = runningCallsCount;
KubernetesClientProvider.queuedCallsCount = queuedCallsCount;
}
}
}
Expand Up @@ -389,7 +389,7 @@ private Proc doLaunch(boolean quiet, String[] cmdEnvs, OutputStream outputForCal
.writingOutput(stream).writingError(stream).writingErrorChannel(error)
.usingListener(new ExecListener() {
@Override
public void onOpen(Response response) {
public void onOpen() {
alive.set(true);
started.countDown();
startAlive.set(System.nanoTime());
Expand Down
Expand Up @@ -157,9 +157,6 @@ protected TaskListenerDecorator get(DelegatedContext context) throws IOException
ExecWatch exec = slave.getKubernetesCloud().connect().pods().inNamespace(slave.getNamespace()).withName(slave.getPodName()).inContainer(containerName)
.writingOutput(baos).writingError(errs).writingErrorChannel(errs)
.usingListener(new ExecListener() {
@Override
public void onOpen(Response response) {
}
@Override
public void onFailure(Throwable t, Response response) {
semaphore.release();
Expand Down
Expand Up @@ -50,7 +50,6 @@

import hudson.EnvVars;
import hudson.model.Computer;
import hudson.model.TaskListener;
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.fabric8.kubernetes.client.Watch;
import org.apache.commons.io.output.TeeOutputStream;
Expand Down Expand Up @@ -84,7 +83,6 @@
import io.fabric8.kubernetes.api.model.PodBuilder;
import io.fabric8.kubernetes.client.HttpClientAware;
import io.fabric8.kubernetes.client.KubernetesClient;
import okhttp3.OkHttpClient;
import org.junit.Ignore;
import org.jvnet.hudson.test.JenkinsRule;

Expand Down Expand Up @@ -353,19 +351,12 @@ public void testContainerDoesNotExist() throws Exception {
@Issue("JENKINS-55392")
public void testRejectedExecutionException() throws Exception {
assertTrue(client instanceof HttpClientAware);
OkHttpClient httpClient = ((HttpClientAware) client).getHttpClient();
System.out.println("Max requests: " + httpClient.dispatcher().getMaxRequests() + "/"
+ httpClient.dispatcher().getMaxRequestsPerHost());
System.out.println("Connection count: " + httpClient.connectionPool().connectionCount() + " - "
+ httpClient.connectionPool().idleConnectionCount());
List<Thread> threads = new ArrayList<>();
final AtomicInteger errors = new AtomicInteger(0);
for (int i = 0; i < 10; i++) {
final String name = "Thread " + i;
Thread t = new Thread(() -> {
try {
System.out.println(name + " Connection count: " + httpClient.connectionPool().connectionCount()
+ " - " + httpClient.connectionPool().idleConnectionCount());
ProcReturn r = execCommand(false, false, "echo", "test");
} catch (Exception e) {
errors.incrementAndGet();
Expand All @@ -387,8 +378,6 @@ public void testRejectedExecutionException() throws Exception {
throw new RuntimeException(e);
}
});
System.out.println("Connection count: " + httpClient.connectionPool().connectionCount() + " - "
+ httpClient.connectionPool().idleConnectionCount());
assertEquals("Errors in threads", 0, errors.get());
}

Expand Down

0 comments on commit 6e06139

Please sign in to comment.