[servicecomb-java-chassis] branch master updated: [SCB-1240] allowed one prometheus cluster support multiple apps
This is an automated email from the ASF dual-hosted git repository. wujimin pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git The following commit(s) were added to refs/heads/master by this push: new 7cd450b [SCB-1240] allowed one prometheus cluster support multiple apps 7cd450b is described below commit 7cd450b87e77d438a23a7c1e603ae660991ad48a Author: wujimin AuthorDate: Thu Apr 4 17:00:39 2019 +0800 [SCB-1240] allowed one prometheus cluster support multiple apps --- .../core/executor/TestThreadPoolExecutorEx.java| 31 +- .../demo/springmvc/client/SpringmvcClient.java | 14 +- .../metrics/prometheus/PrometheusPublisher.java| 4 +++ .../prometheus/TestPrometheusPublisher.java| 11 +++- 4 files changed, 46 insertions(+), 14 deletions(-) diff --git a/core/src/test/java/org/apache/servicecomb/core/executor/TestThreadPoolExecutorEx.java b/core/src/test/java/org/apache/servicecomb/core/executor/TestThreadPoolExecutorEx.java index 163fbb9..14df261 100644 --- a/core/src/test/java/org/apache/servicecomb/core/executor/TestThreadPoolExecutorEx.java +++ b/core/src/test/java/org/apache/servicecomb/core/executor/TestThreadPoolExecutorEx.java @@ -21,11 +21,16 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.TimeUnit; +import java.util.function.IntSupplier; import org.junit.Assert; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class TestThreadPoolExecutorEx { + private static final Logger LOGGER = LoggerFactory.getLogger(TestThreadPoolExecutorEx.class); + static class TestTask implements Runnable { CountDownLatch notify = new CountDownLatch(1); @@ -119,17 +124,15 @@ public class TestThreadPoolExecutorEx { t3.quit(); Assert.assertEquals(4, executorEx.getPoolSize()); Assert.assertEquals(1, executorEx.getRejectedCount()); -Assert.assertEquals(3, executorEx.getNotFinished()); -// multi thread, not sure -// Assert.assertEquals(0, executorEx.getQueue().size()); +waitForResult(3, executorEx::getNotFinished); +waitForResult(0, executorEx.getQueue()::size); // reuse thread t3 = submitTask(); Assert.assertEquals(4, executorEx.getPoolSize()); Assert.assertEquals(1, executorEx.getRejectedCount()); -Assert.assertEquals(4, executorEx.getNotFinished()); -// multi thread, not sure -// Assert.assertEquals(1, executorEx.getQueue().size()); +waitForResult(4, executorEx::getNotFinished); +waitForResult(0, executorEx.getQueue()::size); t3.quit(); t4.quit(); @@ -137,4 +140,20 @@ public class TestThreadPoolExecutorEx { t6.quit(); executorEx.shutdown(); } + + private void waitForResult(int expect, IntSupplier supplier) { +for (; ; ) { + int actual = supplier.getAsInt(); + if (expect == actual) { +return; + } + + LOGGER.info("waiting for thread result, expect:{}, actual: {}.", expect, actual); + try { +TimeUnit.MILLISECONDS.sleep(100); + } catch (InterruptedException e) { +throw new IllegalStateException(e); + } +} + } } diff --git a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java index 411aa11..9b214f7 100644 --- a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java +++ b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java @@ -131,13 +131,13 @@ public class SpringmvcClient { String content = restTemplate .getForObject("cse://springmvc/codeFirstSpringmvc/prometheusForTest", String.class); - TestMgr.check(true, content.contains("servicecomb_invocation{operation=\"springmvc.codeFirst.addDate")); - TestMgr.check(true, content.contains("servicecomb_invocation{operation=\"springmvc.codeFirst.sayHello")); - TestMgr.check(true, content.contains("servicecomb_invocation{operation=\"springmvc.codeFirst.fallbackFromCache")); - TestMgr.check(true, content.contains("servicecomb_invocation{operation=\"springmvc.codeFirst.isTrue")); - TestMgr.check(true, content.contains("servicecomb_invocation{operation=\"springmvc.codeFirst.add")); - TestMgr.check(true, content.contains("servicecomb_invocation{operation=\"springmvc.codeFirst.sayHi2")); - TestMgr.check(true, content.contains("servicecomb_invocation{operation=\"springmvc.codeFirst.saySomething")); + TestMgr.check(true, content.contains("servicecomb_invocation{appId=\"springmvctest\",operation=\"springmvc.codeFirst.addDate")); +
[GitHub] [servicecomb-java-chassis] wujimin merged pull request #1168: [SCB-1240] allowed one prometheus cluster support multiple apps
wujimin merged pull request #1168: [SCB-1240] allowed one prometheus cluster support multiple apps URL: https://github.com/apache/servicecomb-java-chassis/pull/1168 This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[servicecomb-java-chassis] branch release/1.2.0 updated: [SCB-1239] close thread after finish unit test case at once.
This is an automated email from the ASF dual-hosted git repository. ningjiang pushed a commit to branch release/1.2.0 in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git The following commit(s) were added to refs/heads/release/1.2.0 by this push: new 8b1723e [SCB-1239] close thread after finish unit test case at once. 8b1723e is described below commit 8b1723e2fcd2beb86ba05be8d32d3f1b64024eb1 Author: wujimin AuthorDate: Thu Apr 4 10:59:53 2019 +0800 [SCB-1239] close thread after finish unit test case at once. --- .../core/transport/TransportVertxFactory.java | 37 +++--- .../core/executor/TestThreadPoolExecutorEx.java| 19 +-- .../core/transport/TestAbstractTransport.java | 2 +- .../servicecomb/foundation/vertx/VertxUtils.java | 21 +++- .../foundation/vertx/TestVertxUtils.java | 6 ++-- .../servicecomb/faultinjection/AbortFaultTest.java | 2 +- .../servicecomb/faultinjection/DelayFaultTest.java | 2 +- .../faultinjection/TestFaultInjectHandler.java | 2 +- .../transport/highway/TestHighwayTransport.java| 19 +-- 9 files changed, 78 insertions(+), 32 deletions(-) diff --git a/core/src/main/java/org/apache/servicecomb/core/transport/TransportVertxFactory.java b/core/src/main/java/org/apache/servicecomb/core/transport/TransportVertxFactory.java index d4e96d3..c2227fb 100644 --- a/core/src/main/java/org/apache/servicecomb/core/transport/TransportVertxFactory.java +++ b/core/src/main/java/org/apache/servicecomb/core/transport/TransportVertxFactory.java @@ -22,27 +22,42 @@ import org.apache.servicecomb.foundation.vertx.metrics.MetricsOptionsEx; import io.vertx.core.Vertx; import io.vertx.core.VertxOptions; +import io.vertx.core.shareddata.Shareable; public class TransportVertxFactory { - private VertxOptions vertxOptions = new VertxOptions(); + static class TransportVertxInfo implements Shareable { +public VertxOptions vertxOptions = new VertxOptions(); - private DefaultVertxMetricsFactory metricsFactory = new DefaultVertxMetricsFactory(); +public DefaultVertxMetricsFactory metricsFactory = new DefaultVertxMetricsFactory(); - private MetricsOptionsEx metricsOptionsEx = (MetricsOptionsEx) metricsFactory.newOptions(); +public MetricsOptionsEx metricsOptionsEx = (MetricsOptionsEx) metricsFactory.newOptions(); - private Vertx transportVertx; - - public TransportVertxFactory() { -vertxOptions.setMetricsOptions(metricsOptionsEx); -transportVertx = VertxUtils.getOrCreateVertxByName("transport", vertxOptions); -metricsFactory.setVertx(transportVertx, vertxOptions); +public TransportVertxInfo() { + vertxOptions.setMetricsOptions(metricsOptionsEx); +} } + private static final String LOCAL_MAP_NAME = "scb"; + + private static final String INFO = "transport-vertx-info"; + public DefaultVertxMetricsFactory getMetricsFactory() { -return metricsFactory; +TransportVertxInfo info = (TransportVertxInfo) getTransportVertx().sharedData().getLocalMap(LOCAL_MAP_NAME) +.get(INFO); +return info.metricsFactory; } public Vertx getTransportVertx() { -return transportVertx; +return VertxUtils.getVertxMap().computeIfAbsent("transport", this::createTransportVertx); + } + + private Vertx createTransportVertx(String name) { +TransportVertxInfo info = new TransportVertxInfo(); + +Vertx vertx = VertxUtils.init(info.vertxOptions); +info.metricsFactory.setVertx(vertx, info.vertxOptions); +vertx.sharedData().getLocalMap(LOCAL_MAP_NAME).put(INFO, info); + +return vertx; } } diff --git a/core/src/test/java/org/apache/servicecomb/core/executor/TestThreadPoolExecutorEx.java b/core/src/test/java/org/apache/servicecomb/core/executor/TestThreadPoolExecutorEx.java index a2567e4..163fbb9 100644 --- a/core/src/test/java/org/apache/servicecomb/core/executor/TestThreadPoolExecutorEx.java +++ b/core/src/test/java/org/apache/servicecomb/core/executor/TestThreadPoolExecutorEx.java @@ -17,6 +17,8 @@ package org.apache.servicecomb.core.executor; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.TimeUnit; @@ -27,24 +29,19 @@ public class TestThreadPoolExecutorEx { static class TestTask implements Runnable { CountDownLatch notify = new CountDownLatch(1); -CountDownLatch wait = new CountDownLatch(1); +Future future; -public void quit() { +public void quit() throws ExecutionException, InterruptedException { notify.countDown(); - try { -wait.await(); - } catch (InterruptedException e) { -e.printStackTrace(); - } + future.get(); } @Override public void run() { try { notify.await(); -wait.countDown(); } catch