Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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 @@ -189,7 +189,7 @@ protected void doInvoke() throws Throwable {
invocation.next(resp -> {
sendResponseQuietly(resp);

invocation.triggerFinishedEvent(resp.getStatusCode(), resp.isSuccessed());
invocation.triggerFinishedEvent(resp.getStatusCode());
});
}

Expand Down
11 changes: 6 additions & 5 deletions core/src/main/java/org/apache/servicecomb/core/Invocation.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,16 @@ public String getMicroserviceQualifiedName() {
public void triggerStartProcessingEvent() {
this.startProcessingTime = System.nanoTime();
EventUtils.triggerEvent(new InvocationStartProcessingEvent(
operationMeta.getMicroserviceQualifiedName(), this.invocationType, startProcessingTime - startTime));
operationMeta.getMicroserviceQualifiedName(), this.invocationType));
}

public void triggerFinishedEvent(int statusCode, boolean success) {
public void triggerFinishedEvent(int statusCode) {
long finishedTime = System.nanoTime();
EventUtils
.triggerEvent(new InvocationFinishedEvent(operationMeta.getMicroserviceQualifiedName(),
this.invocationType, finishedTime - startProcessingTime,
finishedTime - startTime, statusCode, success));
.triggerEvent(new InvocationFinishedEvent(operationMeta.getMicroserviceQualifiedName(), this.invocationType,
startProcessingTime - startTime,
finishedTime - startProcessingTime,
finishedTime - startTime, statusCode));
}

public boolean isSync() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public class InvocationFinishedEvent implements Event {

private final InvocationType invocationType;

private final long inQueueNanoTime;

private final long processElapsedNanoTime;

private final long totalElapsedNanoTime;

private final int statusCode;

private final boolean success;

public String getOperationName() {
return operationName;
}
Expand All @@ -41,6 +41,10 @@ public InvocationType getInvocationType() {
return invocationType;
}

public long getInQueueNanoTime() {
return inQueueNanoTime;
}

public long getProcessElapsedNanoTime() {
return processElapsedNanoTime;
}
Expand All @@ -53,17 +57,13 @@ public int getStatusCode() {
return statusCode;
}

public boolean isSuccess() {
return success;
}

public InvocationFinishedEvent(String operationName, InvocationType invocationType,
long processElapsedNanoTime, long totalElapsedNanoTime, int statusCode, boolean success) {
long inQueueNanoTime, long processElapsedNanoTime, long totalElapsedNanoTime, int statusCode) {
this.operationName = operationName;
this.invocationType = invocationType;
this.inQueueNanoTime = inQueueNanoTime;
this.processElapsedNanoTime = processElapsedNanoTime;
this.totalElapsedNanoTime = totalElapsedNanoTime;
this.statusCode = statusCode;
this.success = success;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public class InvocationStartProcessingEvent implements Event {

private final InvocationType invocationType;

private final long inQueueNanoTime;

public String getOperationName() {
return operationName;
}
Expand All @@ -35,14 +33,9 @@ public InvocationType getInvocationType() {
return invocationType;
}

public long getInQueueNanoTime() {
return inQueueNanoTime;
}

public InvocationStartProcessingEvent(String operationName, InvocationType invocationType,
long inQueueNanoTime) {
public InvocationStartProcessingEvent(String operationName, InvocationType invocationType) {
this.operationName = operationName;
this.invocationType = invocationType;
this.inQueueNanoTime = inQueueNanoTime;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
public final class InvokerUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(InvokerUtils.class);

private InvokerUtils() {
}

public static Object syncInvoke(String microserviceName, String schemaId, String operationName, Object[] args) {
ReferenceConfig referenceConfig = ReferenceConfigUtils.getForInvoke(microserviceName);
SchemaMeta schemaMeta = referenceConfig.getMicroserviceMeta().ensureFindSchemaMeta(schemaId);
Expand All @@ -59,7 +56,7 @@ public static Object syncInvoke(Invocation invocation) throws InvocationExceptio
return response.getResult();
}

throw ExceptionFactory.convertConsumerException((Throwable) response.getResult());
throw ExceptionFactory.convertConsumerException(response.getResult());
}

public static Response innerSyncInvoke(Invocation invocation) {
Expand All @@ -73,7 +70,6 @@ public static Response innerSyncInvoke(Invocation invocation) {
invocation.next(respExecutor::setResponse);

Response response = respExecutor.waitResponse();
success = response.isSuccessed();
statusCode = response.getStatusCode();
return response;
} catch (Throwable e) {
Expand All @@ -82,7 +78,7 @@ public static Response innerSyncInvoke(Invocation invocation) {
LOGGER.debug(msg, e);
return Response.createConsumerFail(e);
} finally {
invocation.triggerFinishedEvent(statusCode, success);
invocation.triggerFinishedEvent(statusCode);
}
}

Expand All @@ -97,15 +93,15 @@ public static void reactiveInvoke(Invocation invocation, AsyncResponse asyncResp
invocation.next(ar -> {
ContextUtils.setInvocationContext(invocation.getParentContext());
try {
invocation.triggerFinishedEvent(ar.getStatusCode(), ar.isSuccessed());
invocation.triggerFinishedEvent(ar.getStatusCode());
asyncResp.handle(ar);
} finally {
ContextUtils.removeInvocationContext();
}
});
} catch (Throwable e) {
//if throw exception,we can use 500 for status code ?
invocation.triggerFinishedEvent(500, false);
invocation.triggerFinishedEvent(500);
LOGGER.error("invoke failed, {}", invocation.getOperationMeta().getMicroserviceQualifiedName());
asyncResp.consumerFail(e);
}
Expand Down
6 changes: 0 additions & 6 deletions demo/demo-springmvc/springmvc-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@
<groupId>org.apache.servicecomb</groupId>
<artifactId>provider-pojo</artifactId>
</dependency>

<dependency>
<groupId>org.apache.servicecomb</groupId>
<artifactId>metrics-common</artifactId>
</dependency>

</dependencies>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@

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

import org.apache.servicecomb.core.CseContext;
import org.apache.servicecomb.demo.DemoConst;
import org.apache.servicecomb.demo.TestMgr;
import org.apache.servicecomb.demo.controller.Controller;
import org.apache.servicecomb.demo.controller.Person;
import org.apache.servicecomb.foundation.common.utils.BeanUtils;
import org.apache.servicecomb.foundation.common.utils.Log4jUtils;
import org.apache.servicecomb.metrics.common.MetricsDimension;
import org.apache.servicecomb.metrics.common.MetricsPublisher;
import org.apache.servicecomb.metrics.common.RegistryMetric;
import org.apache.servicecomb.provider.springmvc.reference.CseRestTemplate;
import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
import org.apache.servicecomb.provider.springmvc.reference.UrlWithServiceNameClientHttpRequestFactory;
Expand All @@ -45,8 +43,6 @@ public class SpringmvcClient {

private static Controller controller;

private static MetricsPublisher metricsPublisher;

public static void main(String[] args) throws Exception {
Log4jUtils.init();
BeanUtils.init();
Expand All @@ -60,7 +56,6 @@ public static void run() {
templateUrlWithServiceName.setRequestFactory(new UrlWithServiceNameClientHttpRequestFactory());
restTemplate = RestTemplateBuilder.create();
controller = BeanUtils.getBean("controller");
metricsPublisher = BeanUtils.getBean("metricsPublisher");

String prefix = "cse://springmvc";

Expand Down Expand Up @@ -88,14 +83,15 @@ public static void run() {

//0.5.0 later version metrics integration test
try {
RegistryMetric metric = metricsPublisher.metrics();
Thread.sleep(1000);
Map<String, Double> metrics = restTemplate.getForObject(prefix + "/metrics", Map.class);

TestMgr
.check(true, metric.getInstanceMetric().getSystemMetric().getHeapUsed() != 0);
TestMgr.check(true, metric.getProducerMetrics().size() > 0);
TestMgr.check(true,
metric.getProducerMetrics().get("springmvc.codeFirst.saySomething").getProducerCall()
.getTotalValue(MetricsDimension.DIMENSION_STATUS, MetricsDimension.DIMENSION_STATUS_ALL).getValue() > 0);
.check(true, metrics.get("jvm(statistic=gauge,name=heapUsed)") != 0);
TestMgr.check(true, metrics.size() > 0);
TestMgr.check(true, metrics.get(
"servicecomb.invocation(operation=springmvc.codeFirst.saySomething,role=producer,stage=whole,statistic=count,status=200)")
>= 0);
} catch (Exception e) {
TestMgr.check("true", "false");
}
Expand All @@ -104,20 +100,20 @@ public static void run() {
try {
String content = restTemplate.getForObject("cse://springmvc/codeFirstSpringmvc/prometheusForTest", String.class);

TestMgr.check(true, content.contains("servicecomb_springmvc_codeFirst_addDate"));
TestMgr.check(true, content.contains("servicecomb_springmvc_codeFirst_sayHello"));
TestMgr.check(true, content.contains("servicecomb_springmvc_codeFirst_fallbackFromCache"));
TestMgr.check(true, content.contains("servicecomb_springmvc_codeFirst_isTrue_producer"));
TestMgr.check(true, content.contains("servicecomb_springmvc_codeFirst_add"));
TestMgr.check(true, content.contains("servicecomb_springmvc_codeFirst_sayHi2"));
TestMgr.check(true, content.contains("servicecomb_springmvc_codeFirst_saySomething"));
TestMgr.check(true, content.contains("servicecomb_invocation_springmvc_codeFirst_addDate"));
TestMgr.check(true, content.contains("servicecomb_invocation_springmvc_codeFirst_sayHello"));
TestMgr.check(true, content.contains("servicecomb_invocation_springmvc_codeFirst_fallbackFromCache"));
TestMgr.check(true, content.contains("servicecomb_invocation_springmvc_codeFirst_isTrue"));
TestMgr.check(true, content.contains("servicecomb_invocation_springmvc_codeFirst_add"));
TestMgr.check(true, content.contains("servicecomb_invocation_springmvc_codeFirst_sayHi2"));
TestMgr.check(true, content.contains("servicecomb_invocation_springmvc_codeFirst_saySomething"));

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 (!metricKeyAndValue[0].startsWith("jvm")) {
if (Double.parseDouble(metricKeyAndValue[1]) < 0) {
TestMgr.check("true", "false");
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,14 @@
-->

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util" xmlns:cse="http://www.huawei.com/schema/paas/cse/rpc"
xsi:schemaLocation="
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util" xmlns:cse="http://www.huawei.com/schema/paas/cse/rpc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans classpath:org/springframework/beans/factory/xml/spring-beans-3.0.xsd
http://www.huawei.com/schema/paas/cse/rpc classpath:META-INF/spring/spring-paas-cse-rpc.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<context:component-scan base-package="org.apache.servicecomb.demo.springmvc.client" />
<cse:rpc-reference id="controller" microservice-name="springmvc"
schema-id="controller" interface="org.apache.servicecomb.demo.controller.Controller"></cse:rpc-reference>

<cse:rpc-reference id="metricsPublisher" microservice-name="springmvc"
schema-id="metricsEndpoint" interface="org.apache.servicecomb.metrics.common.MetricsPublisher"></cse:rpc-reference>

<context:component-scan base-package="org.apache.servicecomb.demo.springmvc.client"/>
<cse:rpc-reference id="controller" microservice-name="springmvc"
schema-id="controller" interface="org.apache.servicecomb.demo.controller.Controller"></cse:rpc-reference>
</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,7 @@ ssl.keyStoreType: PKCS12
ssl.keyStoreValue: Changeme_123
ssl.crl: revoke.crl
ssl.sslCustomClass: org.apache.servicecomb.demo.DemoSSLCustom

servicecomb:
metrics:
window_time: 1000
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import org.apache.servicecomb.foundation.common.utils.BeanUtils;
import org.apache.servicecomb.foundation.vertx.VertxUtils;
import org.apache.servicecomb.metrics.core.publish.DataSource;
import org.apache.servicecomb.metrics.core.MetricsDataSource;

public class PerfMain {

Expand All @@ -35,8 +35,8 @@ public static void main(String[] args) throws Exception {
RedisClientUtils.init(VertxUtils.getOrCreateVertxByName("transport", null));

// metrics
DataSource dataSource = BeanUtils.getContext().getBean(DataSource.class);
PerfMetricsFilePublisher metricsLog = new PerfMetricsFilePublisher(dataSource);
//DataSource dataSource = BeanUtils.getContext().getBean(Def.class);
PerfMetricsFilePublisher metricsLog = new PerfMetricsFilePublisher(MetricsDataSource.getInstance());
Executors.newScheduledThreadPool(1).scheduleWithFixedDelay(metricsLog::onCycle, 0, 1, TimeUnit.SECONDS);

List<String> argList = Arrays.asList(args);
Expand All @@ -45,5 +45,4 @@ public static void main(String[] args) throws Exception {
consumer.runConsumer();
}
}

}
Loading