You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2018/01/09 08:57:36 UTC
[incubator-servicecomb-java-chassis] 05/09: SCB-118 add integration
test in demo-springmvc
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git
commit 3b86005e1c4744330f4e8b5814d260d0ebf81bc6
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Mon Jan 8 19:46:00 2018 +0800
SCB-118 add integration test in demo-springmvc
Signed-off-by: zhengyangyong <ya...@huawei.com>
---
.../demo/springmvc/client/SpringmvcClient.java | 23 ++++++++++++++++++++++
demo/demo-springmvc/springmvc-server/pom.xml | 2 +-
.../demo/springmvc/server/CodeFirstSpringmvc.java | 8 ++++++++
.../src/main/resources/microservice.yaml | 2 +-
.../metrics/prometheus/MetricsCollector.java | 2 +-
5 files changed, 34 insertions(+), 3 deletions(-)
diff --git a/demo/demo-springmvc/springmvc-client/src/main/java/io/servicecomb/demo/springmvc/client/SpringmvcClient.java b/demo/demo-springmvc/springmvc-client/src/main/java/io/servicecomb/demo/springmvc/client/SpringmvcClient.java
index bd23433..46fc8a6 100644
--- a/demo/demo-springmvc/springmvc-client/src/main/java/io/servicecomb/demo/springmvc/client/SpringmvcClient.java
+++ b/demo/demo-springmvc/springmvc-client/src/main/java/io/servicecomb/demo/springmvc/client/SpringmvcClient.java
@@ -128,6 +128,29 @@ public class SpringmvcClient {
} catch (Exception e) {
TestMgr.check("true", "false");
}
+
+ //prometheus integration test
+ try {
+ String content = restTemplate.getForObject("cse://springmvc/codeFirstSpringmvc/prometheusForTest", String.class);
+ String[] metricLines = content.split("\n");
+ if (metricLines.length > 0) {
+ for (String metricLine : metricLines) {
+ if (!metricLine.startsWith("#")) {
+ String[] metricKeyAndValue = metricLine.split(" ");
+ if (!metricKeyAndValue[0].startsWith("servicecomb_instance_system")) {
+ if (Double.parseDouble(metricKeyAndValue[1]) < 0) {
+ TestMgr.check("true", "false");
+ break;
+ }
+ }
+ }
+ }
+ } else {
+ TestMgr.check("true", "false");
+ }
+ } catch (Exception e) {
+ TestMgr.check("true", "false");
+ }
}
private static void testController(RestTemplate template, String microserviceName) {
diff --git a/demo/demo-springmvc/springmvc-server/pom.xml b/demo/demo-springmvc/springmvc-server/pom.xml
index 772e35f..43a7551 100644
--- a/demo/demo-springmvc/springmvc-server/pom.xml
+++ b/demo/demo-springmvc/springmvc-server/pom.xml
@@ -39,7 +39,7 @@
<dependency>
<groupId>io.servicecomb</groupId>
- <artifactId>metrics-core</artifactId>
+ <artifactId>metrics-prometheus</artifactId>
</dependency>
</dependencies>
diff --git a/demo/demo-springmvc/springmvc-server/src/main/java/io/servicecomb/demo/springmvc/server/CodeFirstSpringmvc.java b/demo/demo-springmvc/springmvc-server/src/main/java/io/servicecomb/demo/springmvc/server/CodeFirstSpringmvc.java
index a244e03..8011dbf 100644
--- a/demo/demo-springmvc/springmvc-server/src/main/java/io/servicecomb/demo/springmvc/server/CodeFirstSpringmvc.java
+++ b/demo/demo-springmvc/springmvc-server/src/main/java/io/servicecomb/demo/springmvc/server/CodeFirstSpringmvc.java
@@ -50,6 +50,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import com.fasterxml.jackson.core.JsonProcessingException;
@@ -352,6 +353,13 @@ public class CodeFirstSpringmvc {
}
}
+ //Only for Prometheus integration test
+ @RequestMapping(path = "/prometheusForTest", method = RequestMethod.GET)
+ public String prometheusForTest() {
+ RestTemplate defaultRestTemplate = new RestTemplate();
+ return defaultRestTemplate.getForObject("http://localhost:9696/metrics", String.class);
+ }
+
@GetMapping(path = "/traceId")
public String getTraceId() {
return ContextUtils.getInvocationContext().getContext(Const.TRACE_ID_NAME);
diff --git a/demo/demo-springmvc/springmvc-server/src/main/resources/microservice.yaml b/demo/demo-springmvc/springmvc-server/src/main/resources/microservice.yaml
index f5d2304..034f0d0 100644
--- a/demo/demo-springmvc/springmvc-server/src/main/resources/microservice.yaml
+++ b/demo/demo-springmvc/springmvc-server/src/main/resources/microservice.yaml
@@ -20,7 +20,7 @@ servicecomb:
APPLICATION_ID: springmvctest
service_description:
name: springmvc
- version: 0.0.2
+ version: 0.0.3
paths:
- path: /test1/testpath
property:
diff --git a/metrics/metrics-integration/metrics-prometheus/src/main/java/io/servicecomb/metrics/prometheus/MetricsCollector.java b/metrics/metrics-integration/metrics-prometheus/src/main/java/io/servicecomb/metrics/prometheus/MetricsCollector.java
index 863736b..c6dd37e 100644
--- a/metrics/metrics-integration/metrics-prometheus/src/main/java/io/servicecomb/metrics/prometheus/MetricsCollector.java
+++ b/metrics/metrics-integration/metrics-prometheus/src/main/java/io/servicecomb/metrics/prometheus/MetricsCollector.java
@@ -54,7 +54,7 @@ public class MetricsCollector extends Collector implements Collector.Describable
}
private List<MetricFamilySamples> load() {
- RegistryMetric registryMetric = dataSource.getRegistryMetric(0);
+ RegistryMetric registryMetric = dataSource.getRegistryMetric();
List<MetricFamilySamples> familySamples = new ArrayList<>();
familySamples.add(getFamilySamples("Instance Level", registryMetric.getInstanceMetric().toMap()));
for (Entry<String, ConsumerInvocationMetric> consumerMetric : registryMetric.getConsumerMetrics().entrySet()) {
--
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.