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/servicecomb-java-chassis.git
The following commit(s) were added to refs/heads/master by this push:
new 50b8b08 [SCB-1154]invocation related log must invoke with marker
50b8b08 is described below
commit 50b8b08508b44d8bad81aecbae2efd5561fb205d
Author: liubao <[email protected]>
AuthorDate: Tue Mar 31 11:58:44 2020 +0800
[SCB-1154]invocation related log must invoke with marker
---
.../org/apache/servicecomb/core/Invocation.java | 4 ++--
.../handler/impl/ProducerOperationHandler.java | 8 +++----
.../loadbalance/LoadbalanceHandler.java | 27 ++++++++++++----------
.../rest/client/http/RestClientInvocation.java | 6 ++---
4 files changed, 24 insertions(+), 21 deletions(-)
diff --git a/core/src/main/java/org/apache/servicecomb/core/Invocation.java
b/core/src/main/java/org/apache/servicecomb/core/Invocation.java
index 4150b1d..049316c 100644
--- a/core/src/main/java/org/apache/servicecomb/core/Invocation.java
+++ b/core/src/main/java/org/apache/servicecomb/core/Invocation.java
@@ -144,6 +144,7 @@ public class Invocation extends SwaggerInvocation {
public Invocation() {
// An empty invocation, used to mock or some other scenario do not need
operation information.
+ traceIdLogger = new TraceIdLogger(this);
}
public Invocation(ReferenceConfig referenceConfig, OperationMeta
operationMeta,
@@ -167,6 +168,7 @@ public class Invocation extends SwaggerInvocation {
this.setSwaggerArguments(swaggerArguments);
this.handlerList = getHandlerChain();
handlerIndex = 0;
+ traceIdLogger = new TraceIdLogger(this);
}
public Transport getTransport() {
@@ -346,8 +348,6 @@ public class Invocation extends SwaggerInvocation {
for (TraceIdGenerator traceIdGenerator : TRACE_ID_GENERATORS) {
initTraceId(traceIdGenerator);
}
-
- traceIdLogger = new TraceIdLogger(this);
}
protected void initTraceId(TraceIdGenerator traceIdGenerator) {
diff --git
a/core/src/main/java/org/apache/servicecomb/core/handler/impl/ProducerOperationHandler.java
b/core/src/main/java/org/apache/servicecomb/core/handler/impl/ProducerOperationHandler.java
index 75e7492..22df2f9 100644
---
a/core/src/main/java/org/apache/servicecomb/core/handler/impl/ProducerOperationHandler.java
+++
b/core/src/main/java/org/apache/servicecomb/core/handler/impl/ProducerOperationHandler.java
@@ -94,7 +94,7 @@ public class ProducerOperationHandler implements Handler {
asyncResp.handle(processException(invocation, ex));
});
} catch (IllegalArgumentException ae) {
- LOGGER.error("Parameters not valid or types not match {},",
+ invocation.getTraceIdLogger().error(LOGGER, "Parameters not valid or
types not match {},",
invocation.getInvocationQualifiedName(), ae);
invocation.onBusinessMethodFinish();
invocation.onBusinessFinish();
@@ -102,7 +102,7 @@ public class ProducerOperationHandler implements Handler {
new InvocationException(Status.BAD_REQUEST.getStatusCode(), "",
new CommonExceptionData("Parameters not valid or types not
match."), ae)));
} catch (Throwable e) {
- LOGGER.error("unexpected error {},",
+ invocation.getTraceIdLogger().error(LOGGER, "unexpected error {},",
invocation.getInvocationQualifiedName(), e);
invocation.onBusinessMethodFinish();
invocation.onBusinessFinish();
@@ -133,7 +133,7 @@ public class ProducerOperationHandler implements Handler {
invocation.onBusinessMethodFinish();
invocation.onBusinessFinish();
} catch (IllegalArgumentException ae) {
- LOGGER.error("Parameters not valid or types not match {},",
+ invocation.getTraceIdLogger().error(LOGGER, "Parameters not valid or
types not match {},",
invocation.getInvocationQualifiedName(), ae);
invocation.onBusinessMethodFinish();
invocation.onBusinessFinish();
@@ -143,7 +143,7 @@ public class ProducerOperationHandler implements Handler {
new CommonExceptionData("Parameters not valid or types not
match."), ae));
} catch (Throwable e) {
if (shouldPrintErrorLog(e)) {
- LOGGER.error("unexpected error {},",
+ invocation.getTraceIdLogger().error(LOGGER, "unexpected error {},",
invocation.getInvocationQualifiedName(), e);
}
invocation.onBusinessMethodFinish();
diff --git
a/handlers/handler-loadbalance/src/main/java/org/apache/servicecomb/loadbalance/LoadbalanceHandler.java
b/handlers/handler-loadbalance/src/main/java/org/apache/servicecomb/loadbalance/LoadbalanceHandler.java
index a1eea05..61c33f7 100644
---
a/handlers/handler-loadbalance/src/main/java/org/apache/servicecomb/loadbalance/LoadbalanceHandler.java
+++
b/handlers/handler-loadbalance/src/main/java/org/apache/servicecomb/loadbalance/LoadbalanceHandler.java
@@ -97,9 +97,10 @@ public class LoadbalanceHandler implements Handler {
@Override
public Server chooseServer(Object key) {
+ Invocation invocation = (Invocation) key;
boolean isRetry = null != lastServer;
for (int i = 0; i < COUNT; i++) {
- Server s = delegate.chooseServer((Invocation) key);
+ Server s = delegate.chooseServer(invocation);
if (s == null) {
break;
}
@@ -109,7 +110,7 @@ public class LoadbalanceHandler implements Handler {
}
}
if (isRetry) {
- LOGGER.info("retry to instance [{}]", lastServer.getHostPort());
+ invocation.getTraceIdLogger().info(LOGGER, "retry to instance [{}]",
lastServer.getHostPort());
}
return lastServer;
@@ -316,19 +317,20 @@ public class LoadbalanceHandler implements Handler {
@Override
public void onExceptionWithServer(ExecutionContext<Invocation> context,
Throwable exception,
ExecutionInfo info) {
- LOGGER.error("Invoke server failed. Operation {}; server {}; {}-{} msg
{}",
- context.getRequest().getInvocationQualifiedName(),
- context.getRequest().getEndpoint(),
- info.getNumberOfPastServersAttempted(),
- info.getNumberOfPastAttemptsOnServer(),
- ExceptionUtils.getExceptionMessageWithoutTrace(exception));
+ context.getRequest().getTraceIdLogger()
+ .error(LOGGER, "Invoke server failed. Operation {}; server {};
{}-{} msg {}",
+ context.getRequest().getInvocationQualifiedName(),
+ context.getRequest().getEndpoint(),
+ info.getNumberOfPastServersAttempted(),
+ info.getNumberOfPastAttemptsOnServer(),
+ ExceptionUtils.getExceptionMessageWithoutTrace(exception));
}
@Override
public void onExecutionSuccess(ExecutionContext<Invocation> context,
Response response,
ExecutionInfo info) {
if (info.getNumberOfPastServersAttempted() > 0 ||
info.getNumberOfPastAttemptsOnServer() > 0) {
- LOGGER.error("Invoke server success. Operation {}; server {}",
+ context.getRequest().getTraceIdLogger().error(LOGGER, "Invoke server
success. Operation {}; server {}",
context.getRequest().getInvocationQualifiedName(),
context.getRequest().getEndpoint());
}
@@ -344,7 +346,7 @@ public class LoadbalanceHandler implements Handler {
@Override
public void onExecutionFailed(ExecutionContext<Invocation> context,
Throwable finalException,
ExecutionInfo info) {
- LOGGER.error("Invoke all server failed. Operation {}, e={}",
+ context.getRequest().getTraceIdLogger().error(LOGGER, "Invoke all
server failed. Operation {}, e={}",
context.getRequest().getInvocationQualifiedName(),
ExceptionUtils.getExceptionMessageWithoutTrace(finalException));
if (orginExecutor != null) {
@@ -391,7 +393,7 @@ public class LoadbalanceHandler implements Handler {
invocation.setEndpoint(server.getEndpoint());
invocation.next(resp -> {
if (isFailedResponse(resp)) {
- LOGGER.error("service {}, call error, msg is {}, server is {}
",
+ invocation.getTraceIdLogger().error(LOGGER, "service {}, call
error, msg is {}, server is {} ",
invocation.getInvocationQualifiedName(),
ExceptionUtils.getExceptionMessageWithoutTrace((Throwable)
resp.getResult()),
s);
@@ -408,7 +410,8 @@ public class LoadbalanceHandler implements Handler {
}
});
} catch (Exception e) {
- LOGGER.error("execution error, msg is {}",
ExceptionUtils.getExceptionMessageWithoutTrace(e));
+ invocation.getTraceIdLogger()
+ .error(LOGGER, "execution error, msg is {}",
ExceptionUtils.getExceptionMessageWithoutTrace(e));
f.onError(e);
}
});
diff --git
a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/http/RestClientInvocation.java
b/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/http/RestClientInvocation.java
index 2ffe2bc..97bdd55 100644
---
a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/http/RestClientInvocation.java
+++
b/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/http/RestClientInvocation.java
@@ -119,14 +119,14 @@ public class RestClientInvocation {
throwableHandler.handle(e);
});
clientRequest.connectionHandler(connection -> {
- LOGGER.debug("http connection connected, local:{}, remote:{}.",
+ invocation.getTraceIdLogger().debug(LOGGER, "http connection connected,
local:{}, remote:{}.",
connection.localAddress(), connection.remoteAddress());
connection.closeHandler(v ->
- LOGGER.debug("http connection closed, local:{}, remote:{}.",
+ invocation.getTraceIdLogger().debug(LOGGER, "http connection closed,
local:{}, remote:{}.",
connection.localAddress(), connection.remoteAddress())
);
connection.exceptionHandler(e ->
- LOGGER.info("http connection exception, local:{}, remote:{}.",
+ invocation.getTraceIdLogger().info(LOGGER, "http connection
exception, local:{}, remote:{}.",
connection.localAddress(), connection.remoteAddress(), e)
);
});