Search in sources :

Example 6 with InvocationStageTrace

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);
}
Also used : InvocationFinishEvent(org.apache.servicecomb.core.event.InvocationFinishEvent) Invocation(org.apache.servicecomb.core.Invocation) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) InvocationStageTrace(org.apache.servicecomb.core.invocation.InvocationStageTrace) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 7 with InvocationStageTrace

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());
}
Also used : InvocationStageTrace(org.apache.servicecomb.core.invocation.InvocationStageTrace)

Example 8 with InvocationStageTrace

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();
}
Also used : InvocationStageTrace(org.apache.servicecomb.core.invocation.InvocationStageTrace)

Example 9 with InvocationStageTrace

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));
    }
}
Also used : InvocationException(org.apache.servicecomb.swagger.invocation.exception.InvocationException) CommonExceptionData(org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData) InvocationStageTrace(org.apache.servicecomb.core.invocation.InvocationStageTrace) TimeoutException(java.util.concurrent.TimeoutException)

Example 10 with InvocationStageTrace

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();
}
Also used : InvocationFinishEvent(org.apache.servicecomb.core.event.InvocationFinishEvent) ServerAccessLogEvent(org.apache.servicecomb.core.event.ServerAccessLogEvent) Invocation(org.apache.servicecomb.core.Invocation) InvocationStageTrace(org.apache.servicecomb.core.invocation.InvocationStageTrace) Before(org.junit.Before)

Aggregations

InvocationStageTrace (org.apache.servicecomb.core.invocation.InvocationStageTrace)15 Invocation (org.apache.servicecomb.core.Invocation)4 InvocationFinishEvent (org.apache.servicecomb.core.event.InvocationFinishEvent)4 RestOperationMeta (org.apache.servicecomb.common.rest.definition.RestOperationMeta)3 ServerAccessLogEvent (org.apache.servicecomb.core.event.ServerAccessLogEvent)3 Before (org.junit.Before)3 Test (org.junit.Test)2 SimpleDateFormat (java.text.SimpleDateFormat)1 TimeoutException (java.util.concurrent.TimeoutException)1 Expectations (mockit.Expectations)1 MockUp (mockit.MockUp)1 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)1 CommonExceptionData (org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData)1 InvocationException (org.apache.servicecomb.swagger.invocation.exception.InvocationException)1