You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ni...@apache.org on 2018/01/02 10:42:30 UTC
[incubator-servicecomb-java-chassis] 01/05: SCB-126 add consumer
event trigger to collect InvocationType.CONSUMER data
This is an automated email from the ASF dual-hosted git repository.
ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git
commit 89a4788136fa06c1a54bf2bf7e77fbdad3cd75ce
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Wed Dec 27 10:04:25 2017 +0800
SCB-126 add consumer event trigger to collect InvocationType.CONSUMER data
Signed-off-by: zhengyangyong <ya...@huawei.com>
---
.../transport/highway/HighwayClient.java | 49 +++++++++++++---------
.../rest/client/http/VertxHttpMethod.java | 10 +++++
2 files changed, 39 insertions(+), 20 deletions(-)
diff --git a/transports/transport-highway/src/main/java/io/servicecomb/transport/highway/HighwayClient.java b/transports/transport-highway/src/main/java/io/servicecomb/transport/highway/HighwayClient.java
index b58e5e6..967fc1f 100644
--- a/transports/transport-highway/src/main/java/io/servicecomb/transport/highway/HighwayClient.java
+++ b/transports/transport-highway/src/main/java/io/servicecomb/transport/highway/HighwayClient.java
@@ -26,7 +26,9 @@ import io.servicecomb.codec.protobuf.definition.OperationProtobuf;
import io.servicecomb.codec.protobuf.definition.ProtobufManager;
import io.servicecomb.core.Invocation;
import io.servicecomb.core.definition.OperationMeta;
+import io.servicecomb.core.metrics.InvocationStartedEvent;
import io.servicecomb.core.transport.AbstractTransport;
+import io.servicecomb.foundation.common.utils.EventUtils;
import io.servicecomb.foundation.ssl.SSLCustom;
import io.servicecomb.foundation.ssl.SSLOption;
import io.servicecomb.foundation.ssl.SSLOptionFactory;
@@ -35,6 +37,7 @@ import io.servicecomb.foundation.vertx.VertxUtils;
import io.servicecomb.foundation.vertx.client.ClientPoolManager;
import io.servicecomb.foundation.vertx.client.tcp.TcpClientConfig;
import io.servicecomb.swagger.invocation.AsyncResponse;
+import io.servicecomb.swagger.invocation.InvocationType;
import io.servicecomb.swagger.invocation.Response;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Vertx;
@@ -66,11 +69,7 @@ public class HighwayClient {
private TcpClientConfig createTcpClientConfig() {
TcpClientConfig tcpClientConfig = new TcpClientConfig();
DynamicLongProperty prop = AbstractTransport.getRequestTimeoutProperty();
- prop.addCallback(new Runnable(){
- public void run(){
- tcpClientConfig.setRequestTimeoutMillis(prop.get());
- }
- });
+ prop.addCallback(() -> tcpClientConfig.setRequestTimeoutMillis(prop.get()));
tcpClientConfig.setRequestTimeoutMillis(prop.get());
if (this.sslEnabled) {
@@ -89,6 +88,12 @@ public class HighwayClient {
}
public void send(Invocation invocation, AsyncResponse asyncResp) throws Exception {
+
+ long startTime = System.nanoTime();
+ EventUtils.triggerEvent(new InvocationStartedEvent(invocation.getMicroserviceQualifiedName(),
+ InvocationType.CONSUMER, startTime));
+ invocation.setStartTime(startTime);
+
HighwayClientConnectionPool tcpClientPool = clientMgr.findThreadBindClientPool();
OperationMeta operationMeta = invocation.getOperationMeta();
@@ -100,22 +105,26 @@ public class HighwayClient {
tcpClientPool.send(tcpClient, clientPackage, ar -> {
// 此时是在网络线程中,转换线程
invocation.getResponseExecutor().execute(() -> {
- if (ar.failed()) {
- // 只会是本地异常
- asyncResp.consumerFail(ar.cause());
- return;
- }
-
- // 处理应答
try {
- Response response =
- HighwayCodec.decodeResponse(invocation,
- operationProtobuf,
- ar.result(),
- tcpClient.getProtobufFeature());
- asyncResp.complete(response);
- } catch (Throwable e) {
- asyncResp.consumerFail(e);
+ if (ar.failed()) {
+ // 只会是本地异常
+ asyncResp.consumerFail(ar.cause());
+ return;
+ }
+
+ // 处理应答
+ try {
+ Response response =
+ HighwayCodec.decodeResponse(invocation,
+ operationProtobuf,
+ ar.result(),
+ tcpClient.getProtobufFeature());
+ asyncResp.complete(response);
+ } catch (Throwable e) {
+ asyncResp.consumerFail(e);
+ }
+ } finally {
+ invocation.triggerFinishedEvent();
}
});
});
diff --git a/transports/transport-rest/transport-rest-client/src/main/java/io/servicecomb/transport/rest/client/http/VertxHttpMethod.java b/transports/transport-rest/transport-rest-client/src/main/java/io/servicecomb/transport/rest/client/http/VertxHttpMethod.java
index b432cc8..c15866e 100644
--- a/transports/transport-rest/transport-rest-client/src/main/java/io/servicecomb/transport/rest/client/http/VertxHttpMethod.java
+++ b/transports/transport-rest/transport-rest-client/src/main/java/io/servicecomb/transport/rest/client/http/VertxHttpMethod.java
@@ -30,9 +30,11 @@ import io.servicecomb.common.rest.definition.RestOperationMeta;
import io.servicecomb.common.rest.filter.HttpClientFilter;
import io.servicecomb.core.Invocation;
import io.servicecomb.core.definition.OperationMeta;
+import io.servicecomb.core.metrics.InvocationStartedEvent;
import io.servicecomb.core.transport.AbstractTransport;
import io.servicecomb.foundation.common.net.IpPort;
import io.servicecomb.foundation.common.net.URIEndpointObject;
+import io.servicecomb.foundation.common.utils.EventUtils;
import io.servicecomb.foundation.common.utils.JsonUtils;
import io.servicecomb.foundation.common.utils.SPIServiceUtils;
import io.servicecomb.foundation.vertx.client.http.HttpClientWithContext;
@@ -42,6 +44,7 @@ import io.servicecomb.foundation.vertx.http.VertxClientRequestToHttpServletReque
import io.servicecomb.foundation.vertx.http.VertxClientResponseToHttpServletResponse;
import io.servicecomb.serviceregistry.api.Const;
import io.servicecomb.swagger.invocation.AsyncResponse;
+import io.servicecomb.swagger.invocation.InvocationType;
import io.servicecomb.swagger.invocation.Response;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.HttpClient;
@@ -67,6 +70,11 @@ public class VertxHttpMethod {
OperationMeta operationMeta = invocation.getOperationMeta();
RestOperationMeta swaggerRestOperation = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
+ long startTime = System.nanoTime();
+ EventUtils.triggerEvent(new InvocationStartedEvent(invocation.getMicroserviceQualifiedName(),
+ InvocationType.CONSUMER, startTime));
+ invocation.setStartTime(startTime);
+
String path = this.createRequestPath(invocation, swaggerRestOperation);
IpPort ipPort = (IpPort) invocation.getEndpoint().getAddress();
@@ -147,6 +155,8 @@ public class VertxHttpMethod {
}
} catch (Throwable e) {
asyncResp.fail(invocation.getInvocationType(), e);
+ } finally {
+ invocation.triggerFinishedEvent();
}
});
});
--
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.