Search in sources :

Example 1 with RpcServerStatJsonReporter

use of com.alipay.sofa.rpc.tracer.sofatracer.log.stat.RpcServerStatJsonReporter in project sofa-rpc by sofastack.

the class RpcSofaTracerTest method testTracerInit.

@Test
public void testTracerInit() throws Exception {
    try {
        // 注册 digest
        AsyncCommonDigestAppenderManager asyncDigestManager = SofaTracerDigestReporterAsyncManager.getSofaTracerDigestReporterAsyncManager();
        Field tracerField = RpcSofaTracer.class.getDeclaredField("sofaTracer");
        tracerField.setAccessible(true);
        // OpenTracing tracer 标准实现
        SofaTracer tracer = (SofaTracer) tracerField.get(this.rpcSofaTracer);
        assertTrue(tracer != null);
        Reporter clientReporter = tracer.getClientReporter();
        assertNotNull(clientReporter);
        assertTrue(clientReporter instanceof DiskReporterImpl);
        DiskReporterImpl clientDisk = (DiskReporterImpl) clientReporter;
        assertEquals(clientDisk.getDigestReporterType(), RpcTracerLogEnum.RPC_CLIENT_DIGEST.getDefaultLogName());
        assertTrue(clientDisk.getStatReporter() instanceof RpcClientStatJsonReporter);
        // 修改为 lazy 初始化了
        // assertFalse(asyncDigestManager.isAppenderAndEncoderExist(clientDisk.getDigestReporterType()));
        SofaRequest sofaRequest = new SofaRequest();
        rpcSofaTracer.startRpc(sofaRequest);
        rpcSofaTracer.clientBeforeSend(sofaRequest);
        rpcSofaTracer.clientReceived(sofaRequest, new SofaResponse(), null);
        // lazy 应该注册成功了
        assertTrue(asyncDigestManager.isAppenderAndEncoderExist(clientDisk.getDigestReporterType()));
        // print
        TimeUnit.SECONDS.sleep(1);
        Reporter serverReporter = tracer.getServerReporter();
        assertTrue(serverReporter instanceof DiskReporterImpl);
        assertNotNull(serverReporter);
        DiskReporterImpl serverDisk = (DiskReporterImpl) serverReporter;
        assertEquals(serverDisk.getDigestReporterType(), RpcTracerLogEnum.RPC_SERVER_DIGEST.getDefaultLogName());
        // assertFalse(asyncDigestManager.isAppenderAndEncoderExist(serverDisk.getDigestReporterType()));
        rpcSofaTracer.serverReceived(sofaRequest);
        rpcSofaTracer.serverSend(sofaRequest, new SofaResponse(), null);
        // print
        TimeUnit.SECONDS.sleep(1);
        assertTrue(asyncDigestManager.isAppenderAndEncoderExist(serverDisk.getDigestReporterType()));
        assertTrue(serverDisk.getStatReporter() instanceof RpcServerStatJsonReporter);
    } catch (Throwable e) {
        e.printStackTrace();
        assertTrue(false);
    }
}
Also used : Field(java.lang.reflect.Field) DiskReporterImpl(com.alipay.common.tracer.core.reporter.digest.DiskReporterImpl) SofaRequest(com.alipay.sofa.rpc.core.request.SofaRequest) RpcClientStatJsonReporter(com.alipay.sofa.rpc.tracer.sofatracer.log.stat.RpcClientStatJsonReporter) RpcServerStatJsonReporter(com.alipay.sofa.rpc.tracer.sofatracer.log.stat.RpcServerStatJsonReporter) RpcClientStatJsonReporter(com.alipay.sofa.rpc.tracer.sofatracer.log.stat.RpcClientStatJsonReporter) Reporter(com.alipay.common.tracer.core.reporter.facade.Reporter) RpcServerStatJsonReporter(com.alipay.sofa.rpc.tracer.sofatracer.log.stat.RpcServerStatJsonReporter) SofaResponse(com.alipay.sofa.rpc.core.response.SofaResponse) AsyncCommonDigestAppenderManager(com.alipay.common.tracer.core.appender.manager.AsyncCommonDigestAppenderManager) SofaTracer(com.alipay.common.tracer.core.SofaTracer) Test(org.junit.Test)

Aggregations

SofaTracer (com.alipay.common.tracer.core.SofaTracer)1 AsyncCommonDigestAppenderManager (com.alipay.common.tracer.core.appender.manager.AsyncCommonDigestAppenderManager)1 DiskReporterImpl (com.alipay.common.tracer.core.reporter.digest.DiskReporterImpl)1 Reporter (com.alipay.common.tracer.core.reporter.facade.Reporter)1 SofaRequest (com.alipay.sofa.rpc.core.request.SofaRequest)1 SofaResponse (com.alipay.sofa.rpc.core.response.SofaResponse)1 RpcClientStatJsonReporter (com.alipay.sofa.rpc.tracer.sofatracer.log.stat.RpcClientStatJsonReporter)1 RpcServerStatJsonReporter (com.alipay.sofa.rpc.tracer.sofatracer.log.stat.RpcServerStatJsonReporter)1 Field (java.lang.reflect.Field)1 Test (org.junit.Test)1