Skip to content

Commit

Permalink
Merge 592285a into b15551c
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengyangyong committed Dec 27, 2017
2 parents b15551c + 592285a commit 7a50f9e
Show file tree
Hide file tree
Showing 34 changed files with 386 additions and 89 deletions.
6 changes: 6 additions & 0 deletions demo/demo-springmvc/springmvc-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
<groupId>io.servicecomb</groupId>
<artifactId>provider-pojo</artifactId>
</dependency>

<dependency>
<groupId>io.servicecomb</groupId>
<artifactId>metrics-common</artifactId>
</dependency>

</dependencies>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
import io.servicecomb.demo.controller.Controller;
import io.servicecomb.demo.controller.Person;
import io.servicecomb.foundation.common.utils.BeanUtils;
import io.servicecomb.foundation.common.utils.JsonUtils;
import io.servicecomb.foundation.common.utils.Log4jUtils;
import io.servicecomb.metrics.common.RegistryMetric;
import io.servicecomb.provider.springmvc.reference.CseRestTemplate;
import io.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
import io.servicecomb.provider.springmvc.reference.UrlWithServiceNameClientHttpRequestFactory;
Expand Down Expand Up @@ -81,6 +83,51 @@ public static void run() throws Exception {

testController();
}

//0.5.0 version metrics integration test
try {
// this test class is intended for retry hanging issue JAV-127
String content = restTemplate.getForObject("cse://springmvc/codeFirstSpringmvc/metricsForTest", String.class);
Map<String, String> resultMap = JsonUtils.OBJ_MAPPER.readValue(content, HashMap.class);

TestMgr.check(String.valueOf(true), String.valueOf(resultMap.get("CPU and Memory").contains("heapUsed=")));

TestMgr.check(resultMap.get("totalRequestProvider OPERATIONAL_LEVEL"),
"{springmvc.codeFirst.saySomething=3, springmvc.codeFirst.testRawJsonAnnotation=3, " +
"springmvc.codeFirst.sayHi2=3, springmvc.codeFirst.responseEntity=6, springmvc.codeFirst.fileUpload=3, " +
"springmvc.codeFirst.responseEntityPATCH=3, springmvc.codeFirst.textPlain=3, " +
"springmvc.codeFirst.metricsForTest=1, springmvc.codeFirst.testform=6, " +
"springmvc.controller.saySomething=6, springmvc.codeFirst.fallbackReturnNull=6, " +
"springmvc.codeFirst.addString=3, springmvc.codeFirst.reduce=3, springmvc.codeFirst.sayHi=3, " +
"springmvc.codeFirst.cseResponse=6, springmvc.codeFirst.bytes=3, springmvc.controller.sayHei=3, " +
"springmvc.codeFirst.fallbackThrowException=9, springmvc.codeFirst.testModelWithIgnoreField=1, " +
"springmvc.codeFirst.testUserMap=3, springmvc.codeFirst.isTrue=3, springmvc.codeFirst.add=3, " +
"springmvc.codeFirst.fallbackFromCache=6, springmvc.controller.sayHi=17, springmvc.codeFirst.sayHello=6,"
+
" springmvc.controller.sayHello=6, springmvc.codeFirst.addDate=3}");

TestMgr.check(String.valueOf(resultMap.get("RequestQueueRelated").contains("springmvc.codeFirst.saySomething")),
String.valueOf(true));
TestMgr.check(String.valueOf(resultMap.get("RequestQueueRelated").contains("springmvc.controller.sayHi")),
String.valueOf(true));
} catch (Exception e) {
TestMgr.check("true", "false");
}

//0.5.0 later version metrics integration test
try {
Object obj = restTemplate.getForObject("cse://springmvc/metrics", Object.class);
String content = JsonUtils.writeValueAsString(obj);
RegistryMetric metric = JsonUtils.OBJ_MAPPER.readValue(content, RegistryMetric.class);

TestMgr.check(String.valueOf(metric.getInstanceMetric().getSystemMetric().getHeapUsed() != 0), "true");
TestMgr.check(String.valueOf(metric.getProducerMetrics().size() == 28), "true");
TestMgr.check(String.valueOf(
metric.getProducerMetrics().get("springmvc.codeFirst.saySomething").getProducerCall().getTotal() == 3),
"true");
} catch (Exception e) {
TestMgr.check("true", "false");
}
}

private static void testController(RestTemplate template, String microserviceName) {
Expand Down
6 changes: 6 additions & 0 deletions demo/demo-springmvc/springmvc-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
<groupId>io.servicecomb</groupId>
<artifactId>provider-springmvc</artifactId>
</dependency>

<dependency>
<groupId>io.servicecomb</groupId>
<artifactId>metrics-core</artifactId>
</dependency>

</dependencies>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -29,6 +30,7 @@
import javax.ws.rs.core.Response.Status;

import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand All @@ -50,11 +52,16 @@
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.netflix.servo.monitor.Monitor;

import io.servicecomb.common.rest.codec.RestObjectMapper;
import io.servicecomb.demo.compute.Person;
import io.servicecomb.demo.ignore.InputModelForTestIgnore;
import io.servicecomb.demo.ignore.OutputModelForTestIgnore;
import io.servicecomb.demo.server.User;
import io.servicecomb.foundation.common.utils.JsonUtils;
import io.servicecomb.foundation.metrics.MetricsServoRegistry;
import io.servicecomb.provider.rest.common.RestSchema;
import io.servicecomb.swagger.extend.annotations.RawJsonRequestBody;
import io.servicecomb.swagger.extend.annotations.ResponseHeaders;
Expand All @@ -74,6 +81,15 @@
@RestSchema(schemaId = "codeFirst")
@RequestMapping(path = "/codeFirstSpringmvc", produces = MediaType.APPLICATION_JSON_VALUE)
public class CodeFirstSpringmvc {

private MetricsServoRegistry registry;

@Autowired
public CodeFirstSpringmvc(MetricsServoRegistry registry) {
this.registry = registry;
}


private String _fileUpload(MultipartFile file1, Part file2) {
try (InputStream is1 = file1.getInputStream(); InputStream is2 = file2.getInputStream()) {
String content1 = IOUtils.toString(is1);
Expand Down Expand Up @@ -283,7 +299,7 @@ public OutputModelForTestIgnore testModelWithIgnoreField(@RequestBody InputModel
return new OutputModelForTestIgnore("output_id", input.getInputId(), input.getContent(), input.getInputObject(),
input.getInputJsonObject(), input.getInputIgnoreInterface(),
new Person("outputSomeone"), new JsonObject("{\"OutputJsonKey\" : \"OutputJsonValue\"}"), () -> {
});
});
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -312,4 +328,19 @@ public String testform(HttpServletRequest request) {
Assert.notNull(form1);
return form1 + form2;
}


@RequestMapping(path = "/metricsForTest", method = RequestMethod.GET)
public String metricsForTest() {
List<Monitor<?>> monitors = registry.getMetricsMonitors();
Map<String, String> values = new HashMap<>();
for (Monitor<?> monitor : monitors) {
values.put(monitor.getConfig().getName(), monitor.getValue().toString());
}
try {
return JsonUtils.writeValueAsString(values);
} catch (JsonProcessingException e) {
return "{}";
}
}
}
10 changes: 10 additions & 0 deletions java-chassis-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,16 @@
<artifactId>edge-core</artifactId>
<version>0.6.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.servicecomb</groupId>
<artifactId>metrics-core</artifactId>
<version>0.6.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.servicecomb</groupId>
<artifactId>metrics-common</artifactId>
<version>0.6.0-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
38 changes: 38 additions & 0 deletions metrics/metrics-common/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>metrics</artifactId>
<groupId>io.servicecomb</groupId>
<version>0.6.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>metrics-common</artifactId>

<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
* limitations under the License.
*/

package io.servicecomb.metrics.core.metric;
package io.servicecomb.metrics.common;

import java.util.HashMap;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonProperty;

public class CallMetric {
private final String prefix;

Expand All @@ -39,7 +41,8 @@ public CallMetric(String prefix) {
this(prefix, 0, 0);
}

public CallMetric(String prefix, long total, double tps) {
public CallMetric(@JsonProperty("prefix") String prefix, @JsonProperty("total") long total,
@JsonProperty("tps") double tps) {
this.prefix = prefix;
this.total = total;
this.tps = tps;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
* limitations under the License.
*/

package io.servicecomb.metrics.core.metric;
package io.servicecomb.metrics.common;

import java.util.HashMap;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonProperty;

public class ConsumerInvocationMetric extends InvocationMetric {
private final TimerMetric consumerLatency;

Expand All @@ -33,8 +35,10 @@ public CallMetric getConsumerCall() {
return consumerCall;
}

public ConsumerInvocationMetric(String operationName, String prefix,
TimerMetric consumerLatency, CallMetric consumerCall) {
public ConsumerInvocationMetric(@JsonProperty("operationName") String operationName,
@JsonProperty("prefix") String prefix,
@JsonProperty("consumerLatency") TimerMetric consumerLatency,
@JsonProperty("consumerCall") CallMetric consumerCall) {
super(operationName, prefix);
this.consumerLatency = consumerLatency;
this.consumerCall = consumerCall;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
* limitations under the License.
*/

package io.servicecomb.metrics.core.metric;
package io.servicecomb.metrics.common;

import com.fasterxml.jackson.annotation.JsonProperty;

public class InstanceMetric {
private final SystemMetric systemMetric;
Expand All @@ -36,9 +38,9 @@ public ProducerInvocationMetric getProducerMetric() {
return producerMetric;
}

public InstanceMetric(SystemMetric systemMetric,
ConsumerInvocationMetric consumerMetric,
ProducerInvocationMetric producerMetric) {
public InstanceMetric(@JsonProperty("systemMetric") SystemMetric systemMetric,
@JsonProperty("consumerMetric") ConsumerInvocationMetric consumerMetric,
@JsonProperty("producerMetric") ProducerInvocationMetric producerMetric) {
this.systemMetric = systemMetric;
this.consumerMetric = consumerMetric;
this.producerMetric = producerMetric;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package io.servicecomb.metrics.core.metric;
package io.servicecomb.metrics.common;

public class InvocationMetric {
private final String operationName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package io.servicecomb.metrics.core;
package io.servicecomb.metrics.common;

public class MetricsConst {
public static final String CONSUMER_PREFIX_TEMPLATE = "servicecomb.%s.consumer";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.servicecomb.metrics.common;

public interface MetricsPublisher {
RegistryMetric metrics();

RegistryMetric metricsWithWindowTimeIndex(int windowTimeIndex);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
* limitations under the License.
*/

package io.servicecomb.metrics.core.metric;
package io.servicecomb.metrics.common;

import java.util.HashMap;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonProperty;

public class ProducerInvocationMetric extends InvocationMetric {
private final long waitInQueue;

Expand Down Expand Up @@ -51,8 +53,13 @@ public CallMetric getProducerCall() {
return producerCall;
}

public ProducerInvocationMetric(String operationName, String prefix, long waitInQueue,
TimerMetric lifeTimeInQueue, TimerMetric executionTime, TimerMetric producerLatency, CallMetric producerCall) {
public ProducerInvocationMetric(@JsonProperty("operationName") String operationName,
@JsonProperty("prefix") String prefix,
@JsonProperty("waitInQueue") long waitInQueue,
@JsonProperty("lifeTimeInQueue") TimerMetric lifeTimeInQueue,
@JsonProperty("executionTime") TimerMetric executionTime,
@JsonProperty("producerLatency") TimerMetric producerLatency,
@JsonProperty("producerCall") CallMetric producerCall) {
super(operationName, prefix);
this.waitInQueue = waitInQueue;
this.lifeTimeInQueue = lifeTimeInQueue;
Expand Down

0 comments on commit 7a50f9e

Please sign in to comment.