use of org.apache.servicecomb.core.invocation.InvocationStageTrace in project java-chassis by ServiceComb.
the class AccessLogGeneratorTest method testClientLog.
@Test
public void testClientLog() {
Invocation invocation = Mockito.mock(Invocation.class);
InvocationStageTrace stageTrace = Mockito.mock(InvocationStageTrace.class);
OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
long startMillisecond = 1416863450581L;
when(stageTrace.getStartSend()).thenReturn(0L);
when(stageTrace.getStart()).thenReturn(0L);
when(stageTrace.getFinish()).thenReturn(0L);
when(stageTrace.getStartTimeMillis()).thenReturn(startMillisecond);
when(invocation.getOperationMeta()).thenReturn(operationMeta);
when(invocation.getInvocationStageTrace()).thenReturn(stageTrace);
InvocationFinishEvent finishEvent = new InvocationFinishEvent(invocation, null);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(ConfigurableDatetimeAccessItem.DEFAULT_DATETIME_PATTERN, ConfigurableDatetimeAccessItem.DEFAULT_LOCALE);
simpleDateFormat.setTimeZone(TimeZone.getDefault());
when(operationMeta.getHttpMethod()).thenReturn(HttpMethod.DELETE.toString());
String log = LOG_GENERATOR.generateClientLog(finishEvent);
Assert.assertEquals("DELETE" + " - " + simpleDateFormat.format(startMillisecond), log);
}
use of org.apache.servicecomb.core.invocation.InvocationStageTrace in project java-chassis by ServiceComb.
the class EdgeInvocationMeter method onInvocationFinish.
@Override
public void onInvocationFinish(InvocationFinishEvent event) {
super.onInvocationFinish(event);
InvocationStageTrace invocationStageTrace = event.getInvocation().getInvocationStageTrace();
executorQueueTimer.record((long) invocationStageTrace.calcThreadPoolQueueTime());
serverFiltersRequestTimer.record((long) invocationStageTrace.calcServerFiltersRequestTime());
serverFiltersResponseTimer.record((long) invocationStageTrace.calcServerFiltersResponseTime());
sendResponseTimer.record((long) invocationStageTrace.calcSendResponseTime());
}
use of org.apache.servicecomb.core.invocation.InvocationStageTrace in project java-chassis by ServiceComb.
the class RestClientSender method processMetrics.
protected void processMetrics() {
InvocationStageTrace stageTrace = invocation.getInvocationStageTrace();
stageTrace.finishWriteToBuffer(System.nanoTime());
// even failed and did not received response, still set time for it
// that will help to know the real timeout time
stageTrace.finishReceiveResponse();
stageTrace.startClientFiltersResponse();
}
use of org.apache.servicecomb.core.invocation.InvocationStageTrace in project java-chassis by ServiceComb.
the class RestClientInvocation method fail.
protected void fail(Throwable e) {
if (alreadyFailed) {
return;
}
alreadyFailed = true;
InvocationStageTrace stageTrace = invocation.getInvocationStageTrace();
if (stageTrace.getFinishWriteToBuffer() == 0) {
stageTrace.finishWriteToBuffer(System.nanoTime());
}
// that will help to know the real timeout time
if (stageTrace.getFinishReceiveResponse() == 0) {
stageTrace.finishReceiveResponse();
}
if (stageTrace.getStartClientFiltersResponse() == 0) {
stageTrace.startClientFiltersResponse();
}
stageTrace.finishClientFiltersResponse();
try {
if (e instanceof TimeoutException) {
// give an accurate cause for timeout exception
// The timeout period of 30000ms has been exceeded while executing GET /xxx for server 1.1.1.1:8080
// should not copy the message to invocationException to avoid leak server ip address
LOGGER.info("Request timeout, Details: {}.", e.getMessage());
asyncResp.consumerFail(new InvocationException(Status.REQUEST_TIMEOUT, new CommonExceptionData("Request Timeout.")));
return;
}
asyncResp.fail(invocation.getInvocationType(), e);
} catch (Throwable e1) {
invocation.getTraceIdLogger().error(LOGGER, "failed to invoke asyncResp, message={}", ExceptionUtils.getExceptionMessageWithoutTrace(e));
}
}
use of org.apache.servicecomb.core.invocation.InvocationStageTrace in project java-chassis by ServiceComb.
the class DatetimeConfigurableItemTest method initStrBuilder.
@Before
public void initStrBuilder() {
finishEvent = Mockito.mock(InvocationFinishEvent.class);
invocation = Mockito.mock(Invocation.class);
invocationStageTrace = Mockito.mock(InvocationStageTrace.class);
when(finishEvent.getInvocation()).thenReturn(invocation);
when(invocation.getInvocationStageTrace()).thenReturn(invocationStageTrace);
when(invocationStageTrace.getStartSend()).thenReturn(0L);
when(invocationStageTrace.getStart()).thenReturn(0L);
when(invocationStageTrace.getStartTimeMillis()).thenReturn(START_MILLISECOND);
accessLogEvent = new ServerAccessLogEvent();
accessLogEvent.setMilliStartTime(START_MILLISECOND);
strBuilder = new StringBuilder();
}
Aggregations