Search in sources :

Example 1 with DiskReporterImpl

use of com.alipay.common.tracer.core.reporter.digest.DiskReporterImpl in project sofa-rpc by sofastack.

the class RestTracerTest method reflectToTracer.

/**
 * reflect to tracer
 *
 * @return
 */
protected Reporter reflectToTracer() {
    try {
        Tracer rpcSofaTracer = Tracers.getTracer();
        tracerField = RpcSofaTracer.class.getDeclaredField("sofaTracer");
        tracerField.setAccessible(true);
        // OpenTracing tracer 标准实现
        tracer = (SofaTracer) tracerField.get(rpcSofaTracer);
        Reporter tempReport = tracer.getClientReporter();
        clientReporterField = SofaTracer.class.getDeclaredField("clientReporter");
        clientReporterField.setAccessible(true);
        serverReporterField = SofaTracer.class.getDeclaredField("serverReporter");
        serverReporterField.setAccessible(true);
        if (tempReport instanceof DiskReporterImpl) {
            diskReporter = (DiskReporterImpl) tempReport;
            assertNotNull(diskReporter);
            memoryReporter = new MemoryReporterImpl(null, null, null, null, diskReporter.getStatReporter());
            clientReporterField.set(tracer, memoryReporter);
            serverReporterField.set(tracer, memoryReporter);
        } else {
            memoryReporter = (MemoryReporterImpl) tempReport;
        }
    // 否则说明已经是 memory 了.主要是本地
    } catch (Exception e) {
        e.printStackTrace();
    }
    return memoryReporter;
}
Also used : MemoryReporterImpl(com.alipay.sofa.rpc.tracer.sofatracer.factory.MemoryReporterImpl) DiskReporterImpl(com.alipay.common.tracer.core.reporter.digest.DiskReporterImpl) RpcSofaTracer(com.alipay.sofa.rpc.tracer.sofatracer.RpcSofaTracer) Tracer(com.alipay.sofa.rpc.tracer.Tracer) SofaTracer(com.alipay.common.tracer.core.SofaTracer) RpcSofaTracer(com.alipay.sofa.rpc.tracer.sofatracer.RpcSofaTracer) Reporter(com.alipay.common.tracer.core.reporter.facade.Reporter) IOException(java.io.IOException) SofaTracer(com.alipay.common.tracer.core.SofaTracer) RpcSofaTracer(com.alipay.sofa.rpc.tracer.sofatracer.RpcSofaTracer)

Example 2 with DiskReporterImpl

use of com.alipay.common.tracer.core.reporter.digest.DiskReporterImpl 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)2 DiskReporterImpl (com.alipay.common.tracer.core.reporter.digest.DiskReporterImpl)2 Reporter (com.alipay.common.tracer.core.reporter.facade.Reporter)2 AsyncCommonDigestAppenderManager (com.alipay.common.tracer.core.appender.manager.AsyncCommonDigestAppenderManager)1 SofaRequest (com.alipay.sofa.rpc.core.request.SofaRequest)1 SofaResponse (com.alipay.sofa.rpc.core.response.SofaResponse)1 Tracer (com.alipay.sofa.rpc.tracer.Tracer)1 RpcSofaTracer (com.alipay.sofa.rpc.tracer.sofatracer.RpcSofaTracer)1 MemoryReporterImpl (com.alipay.sofa.rpc.tracer.sofatracer.factory.MemoryReporterImpl)1 RpcClientStatJsonReporter (com.alipay.sofa.rpc.tracer.sofatracer.log.stat.RpcClientStatJsonReporter)1 RpcServerStatJsonReporter (com.alipay.sofa.rpc.tracer.sofatracer.log.stat.RpcServerStatJsonReporter)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 Test (org.junit.Test)1