From 2f5115a3ea943ca185b13100045c4b3126197a3f Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Mon, 1 Jul 2019 14:49:06 +0200 Subject: [PATCH 1/3] Add http connections count --- .../kubernetes/KubernetesClientProvider.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesClientProvider.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesClientProvider.java index 07993e1164..14bd2785ef 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesClientProvider.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesClientProvider.java @@ -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; @@ -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); @@ -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()); + } + }); + KubernetesClientProvider.runningCallsCount = runningCallsCount.get(); + KubernetesClientProvider.queuedCallsCount = queuedCallsCount.get(); + } + } } From b7e7531a70def5ad5953ff2acecfe29bf449240d Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Tue, 2 Jul 2019 18:16:41 +0200 Subject: [PATCH 2/3] Simplify --- .../kubernetes/KubernetesClientProvider.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesClientProvider.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesClientProvider.java index 14bd2785ef..bcd3a9b08a 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesClientProvider.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesClientProvider.java @@ -267,19 +267,19 @@ public long getRecurrencePeriod() { @Override protected void doRun() { - AtomicInteger runningCallsCount = new AtomicInteger(); - AtomicInteger queuedCallsCount = new AtomicInteger(); - KubernetesClientProvider.clients.asMap().forEach((s, client) -> { + 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.addAndGet(dispatcher.runningCallsCount()); - queuedCallsCount.addAndGet(dispatcher.queuedCallsCount()); + runningCallsCount += dispatcher.runningCallsCount(); + queuedCallsCount += dispatcher.queuedCallsCount(); } - }); - KubernetesClientProvider.runningCallsCount = runningCallsCount.get(); - KubernetesClientProvider.queuedCallsCount = queuedCallsCount.get(); + } + KubernetesClientProvider.runningCallsCount = runningCallsCount; + KubernetesClientProvider.queuedCallsCount = queuedCallsCount; } } } From 4186fee450a5d3bfddb9c8451bb6344c3edc36fa Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Tue, 2 Jul 2019 18:17:38 +0200 Subject: [PATCH 3/3] Remove unused import --- .../jenkins/plugins/kubernetes/KubernetesClientProvider.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesClientProvider.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesClientProvider.java index bcd3a9b08a..2c4fa802ab 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesClientProvider.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesClientProvider.java @@ -13,7 +13,6 @@ 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;