Search in sources :

Example 1 with SofaTracerStatisticReporterManager

use of com.alipay.common.tracer.core.reporter.stat.manager.SofaTracerStatisticReporterManager in project sofa-rpc by sofastack.

the class AbstractTracerBase method removeRpcDigestStatLogType.

protected void removeRpcDigestStatLogType() throws Exception {
    AsyncCommonDigestAppenderManager asyncDigestManager = SofaTracerDigestReporterAsyncManager.getSofaTracerDigestReporterAsyncManager();
    // stat
    Map<Long, SofaTracerStatisticReporterManager> cycleTimesManager = SofaTracerStatisticReporterCycleTimesManager.getCycleTimesManager();
    for (Map.Entry<Long, SofaTracerStatisticReporterManager> entry : cycleTimesManager.entrySet()) {
        SofaTracerStatisticReporterManager manager = entry.getValue();
        manager.getStatReporters().clear();
    }
}
Also used : SofaTracerStatisticReporterManager(com.alipay.common.tracer.core.reporter.stat.manager.SofaTracerStatisticReporterManager) AsyncCommonDigestAppenderManager(com.alipay.common.tracer.core.appender.manager.AsyncCommonDigestAppenderManager) Map(java.util.Map)

Example 2 with SofaTracerStatisticReporterManager

use of com.alipay.common.tracer.core.reporter.stat.manager.SofaTracerStatisticReporterManager in project sofa-boot by sofastack.

the class AbstractTestBase method reflectSpringMVCClear.

public static void reflectSpringMVCClear() throws NoSuchFieldException, IllegalAccessException {
    Field field = SpringMvcTracer.class.getDeclaredField("springMvcTracer");
    field.setAccessible(true);
    field.set(null, null);
    // clear digest
    Field fieldAsync = SofaTracerDigestReporterAsyncManager.class.getDeclaredField("asyncCommonDigestAppenderManager");
    fieldAsync.setAccessible(true);
    fieldAsync.set(null, null);
    // clear stat
    SofaTracerStatisticReporterManager statReporterManager = SofaTracerStatisticReporterCycleTimesManager.getSofaTracerStatisticReporterManager(1L);
    Field fieldStat = SofaTracerStatisticReporterManager.class.getDeclaredField("statReporters");
    fieldStat.setAccessible(true);
    fieldStat.set(statReporterManager, new ConcurrentHashMap<>());
}
Also used : Field(java.lang.reflect.Field) SofaTracerStatisticReporterManager(com.alipay.common.tracer.core.reporter.stat.manager.SofaTracerStatisticReporterManager)

Example 3 with SofaTracerStatisticReporterManager

use of com.alipay.common.tracer.core.reporter.stat.manager.SofaTracerStatisticReporterManager in project sofa-boot by sofastack.

the class SpringMvcFilterJsonOutputTest method testSofaRestGet.

@Test
@Ignore
public void testSofaRestGet() throws Exception {
    String restUrl = urlHttpPrefix + "/greeting";
    int countTimes = 5;
    for (int i = 0; i < countTimes; i++) {
        ResponseEntity<SampleRestController.Greeting> response = testRestTemplate.getForEntity(restUrl, SampleRestController.Greeting.class);
        SampleRestController.Greeting greetingResponse = response.getBody();
        assertTrue(greetingResponse.isSuccess());
        // http://docs.spring.io/spring-boot/docs/1.4.2.RELEASE/reference/htmlsingle/#boot-features-testing
        assertTrue(greetingResponse.getId() >= 0);
    }
    TestUtil.waitForAsyncLog();
    // wait for async output
    List<String> contents = FileUtils.readLines(customFileLog(SpringMvcLogEnum.SPRING_MVC_DIGEST.getDefaultLogName()));
    assertTrue(contents.size() == countTimes);
    for (int i = 0; i < contents.size(); i++) {
        String logValue = contents.get(i);
        Map<String, String> jsonMap = parseToMap(logValue, String.class, String.class);
        assertTrue(jsonMap.size() > 0);
    }
    // wait another 500ms to reach a cycle of stat_internal_log
    Thread.sleep(500);
    for (int i = 0; i < countTimes; i++) {
        ResponseEntity<SampleRestController.Greeting> response = testRestTemplate.getForEntity(restUrl, SampleRestController.Greeting.class);
        SampleRestController.Greeting greetingResponse = response.getBody();
        assertTrue(greetingResponse.isSuccess());
    }
    SofaTracerStatisticReporterManager s = SofaTracerStatisticReporterCycleTimesManager.getSofaTracerStatisticReporterManager(1L);
    Assert.notNull(s.getStatReporters().get(SpringMvcLogEnum.SPRING_MVC_STAT.getDefaultLogName()));
    // stat log : 设置了周期 1s 输出一次
    Thread.sleep(1000);
    // wait for async output
    List<String> statContents = FileUtils.readLines(customFileLog(SpringMvcLogEnum.SPRING_MVC_STAT.getDefaultLogName()));
    assertEquals(2, statContents.size());
}
Also used : SampleRestController(com.alipay.sofa.tracer.boot.base.controller.SampleRestController) SofaTracerStatisticReporterManager(com.alipay.common.tracer.core.reporter.stat.manager.SofaTracerStatisticReporterManager) Ignore(org.junit.Ignore) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with SofaTracerStatisticReporterManager

use of com.alipay.common.tracer.core.reporter.stat.manager.SofaTracerStatisticReporterManager in project sofa-boot by alipay.

the class SpringMvcFilterJsonOutputTest method testSofaRestGet.

@Test
@Ignore
public void testSofaRestGet() throws Exception {
    String restUrl = urlHttpPrefix + "/greeting";
    int countTimes = 5;
    for (int i = 0; i < countTimes; i++) {
        ResponseEntity<SampleRestController.Greeting> response = testRestTemplate.getForEntity(restUrl, SampleRestController.Greeting.class);
        SampleRestController.Greeting greetingResponse = response.getBody();
        assertTrue(greetingResponse.isSuccess());
        // http://docs.spring.io/spring-boot/docs/1.4.2.RELEASE/reference/htmlsingle/#boot-features-testing
        assertTrue(greetingResponse.getId() >= 0);
    }
    TestUtil.waitForAsyncLog();
    // wait for async output
    List<String> contents = FileUtils.readLines(customFileLog(SpringMvcLogEnum.SPRING_MVC_DIGEST.getDefaultLogName()));
    assertTrue(contents.size() == countTimes);
    for (int i = 0; i < contents.size(); i++) {
        String logValue = contents.get(i);
        Map<String, String> jsonMap = parseToMap(logValue, String.class, String.class);
        assertTrue(jsonMap.size() > 0);
    }
    // wait another 500ms to reach a cycle of stat_internal_log
    Thread.sleep(500);
    for (int i = 0; i < countTimes; i++) {
        ResponseEntity<SampleRestController.Greeting> response = testRestTemplate.getForEntity(restUrl, SampleRestController.Greeting.class);
        SampleRestController.Greeting greetingResponse = response.getBody();
        assertTrue(greetingResponse.isSuccess());
    }
    SofaTracerStatisticReporterManager s = SofaTracerStatisticReporterCycleTimesManager.getSofaTracerStatisticReporterManager(1L);
    Assert.notNull(s.getStatReporters().get(SpringMvcLogEnum.SPRING_MVC_STAT.getDefaultLogName()));
    // stat log : 设置了周期 1s 输出一次
    Thread.sleep(1000);
    // wait for async output
    List<String> statContents = FileUtils.readLines(customFileLog(SpringMvcLogEnum.SPRING_MVC_STAT.getDefaultLogName()));
    assertEquals(2, statContents.size());
}
Also used : SampleRestController(com.alipay.sofa.tracer.boot.base.controller.SampleRestController) SofaTracerStatisticReporterManager(com.alipay.common.tracer.core.reporter.stat.manager.SofaTracerStatisticReporterManager) Ignore(org.junit.Ignore) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with SofaTracerStatisticReporterManager

use of com.alipay.common.tracer.core.reporter.stat.manager.SofaTracerStatisticReporterManager in project sofa-boot by alipay.

the class AbstractTestBase method reflectSpringMVCClear.

public static void reflectSpringMVCClear() throws NoSuchFieldException, IllegalAccessException {
    Field field = SpringMvcTracer.class.getDeclaredField("springMvcTracer");
    field.setAccessible(true);
    field.set(null, null);
    // clear digest
    Field fieldAsync = SofaTracerDigestReporterAsyncManager.class.getDeclaredField("asyncCommonDigestAppenderManager");
    fieldAsync.setAccessible(true);
    fieldAsync.set(null, null);
    // clear stat
    SofaTracerStatisticReporterManager statReporterManager = SofaTracerStatisticReporterCycleTimesManager.getSofaTracerStatisticReporterManager(1L);
    Field fieldStat = SofaTracerStatisticReporterManager.class.getDeclaredField("statReporters");
    fieldStat.setAccessible(true);
    fieldStat.set(statReporterManager, new ConcurrentHashMap<>());
}
Also used : Field(java.lang.reflect.Field) SofaTracerStatisticReporterManager(com.alipay.common.tracer.core.reporter.stat.manager.SofaTracerStatisticReporterManager)

Aggregations

SofaTracerStatisticReporterManager (com.alipay.common.tracer.core.reporter.stat.manager.SofaTracerStatisticReporterManager)6 AsyncCommonDigestAppenderManager (com.alipay.common.tracer.core.appender.manager.AsyncCommonDigestAppenderManager)2 SampleRestController (com.alipay.sofa.tracer.boot.base.controller.SampleRestController)2 Field (java.lang.reflect.Field)2 Map (java.util.Map)2 Ignore (org.junit.Ignore)2 Test (org.junit.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2