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

Add http connections count #528

Merged
merged 3 commits into from
Jul 3, 2019
Merged
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 @@ -13,9 +13,11 @@
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;

import hudson.model.PeriodicWork;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;

Expand Down Expand Up @@ -212,6 +214,17 @@ public static boolean gracefulClose(KubernetesClient client, OkHttpClient httpCl
}
}

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 @@ -243,4 +256,30 @@ 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() {
AtomicInteger runningCallsCount = new AtomicInteger();
AtomicInteger queuedCallsCount = new AtomicInteger();
KubernetesClientProvider.clients.asMap().forEach((s, client) -> {
KubernetesClient kClient = client.getClient();
if (kClient instanceof HttpClientAware) {
OkHttpClient httpClient = ((HttpClientAware) kClient).getHttpClient();
Dispatcher dispatcher = httpClient.dispatcher();
runningCallsCount.addAndGet(dispatcher.runningCallsCount());
queuedCallsCount.addAndGet(dispatcher.queuedCallsCount());
Copy link
Member

Choose a reason for hiding this comment

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

Easier to use a plain old for loop and local int variables.

}
});
KubernetesClientProvider.runningCallsCount = runningCallsCount.get();
KubernetesClientProvider.queuedCallsCount = queuedCallsCount.get();
}
}
}