Search in sources :

Example 1 with LastJsonReporter

use of com.megaease.easeagent.mock.report.impl.LastJsonReporter in project easeagent by megaease.

the class RabbitMqConsumerMetricTest method metricAfter.

@Test
public void metricAfter() {
    IPluginConfig config = TestUtils.getMqMetricConfig();
    RabbitMqConsumerMetric metric = EaseAgent.getOrCreateServiceMetric(config, RabbitMqConsumerMetric.buildConsumerTags(), RabbitMqConsumerMetric.SERVICE_METRIC_SUPPLIER);
    String key = "testMetricAfter";
    metric.metricAfter(key, System.currentTimeMillis() - 101, true);
    TagVerifier tagVerifier = TagVerifier.build(RabbitMqConsumerMetric.buildConsumerTags(), key);
    LastJsonReporter lastJsonReporter = MockEaseAgent.lastMetricJsonReporter(tagVerifier::verifyAnd);
    Map<String, Object> metrics = lastJsonReporter.flushAndOnlyOne();
    assertTrue((int) (double) metrics.get(MetricField.MIN_EXECUTION_TIME.getField()) > 100);
    Meter meter = metric.meter(key, MetricSubType.CONSUMER);
    Meter meterError = metric.meter(key, MetricSubType.CONSUMER_ERROR);
    assertEquals(1, meter.getCount());
    assertEquals(0, meterError.getCount());
    metric.metricAfter(key, System.currentTimeMillis() - 100, false);
    assertEquals(2, meter.getCount());
    assertEquals(1, meterError.getCount());
}
Also used : TagVerifier(com.megaease.easeagent.mock.plugin.api.utils.TagVerifier) LastJsonReporter(com.megaease.easeagent.mock.report.impl.LastJsonReporter) Meter(com.megaease.easeagent.plugin.api.metric.Meter) IPluginConfig(com.megaease.easeagent.plugin.api.config.IPluginConfig) Test(org.junit.Test)

Example 2 with LastJsonReporter

use of com.megaease.easeagent.mock.report.impl.LastJsonReporter in project easeagent by megaease.

the class MD5SQLCompressionTest method compress.

@Test
public void compress() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    MD5SQLCompression md5SQLCompression = MD5SQLCompression.getInstance();
    Cache<String, String> dictionary = AgentFieldReflectAccessor.getFieldValue(md5SQLCompression, "dictionary");
    Cache<String, String> md5Cache = AgentFieldReflectAccessor.getFieldValue(md5SQLCompression, "md5Cache");
    dictionary.cleanUp();
    md5Cache.cleanUp();
    String sql = "select * from data";
    String md5 = DigestUtils.md5Hex(sql);
    String result = md5SQLCompression.compress(sql);
    assertEquals(md5, result);
    assertEquals(result, md5SQLCompression.compress(sql));
    assertEquals(md5, md5Cache.getIfPresent(sql));
    assertEquals(sql, dictionary.getIfPresent(md5));
    TagVerifier tagVerifier = new TagVerifier().add("category", "application").add("type", "md5-dictionary");
    LastJsonReporter lastJsonReporter = MockEaseAgent.lastMetricJsonReporter(tagVerifier::verifyAnd);
    pushItems();
    Map<String, Object> report = lastJsonReporter.getLastOnlyOne();
    assertEquals(md5, report.get("md5"));
    assertEquals(sql, report.get("sql"));
    dictionary.cleanUp();
    md5Cache.cleanUp();
}
Also used : TagVerifier(com.megaease.easeagent.mock.plugin.api.utils.TagVerifier) LastJsonReporter(com.megaease.easeagent.mock.report.impl.LastJsonReporter) Test(org.junit.Test)

Example 3 with LastJsonReporter

use of com.megaease.easeagent.mock.report.impl.LastJsonReporter in project easeagent by megaease.

the class JdbcDataSourceMetricInterceptorTest method doAfter.

@Test
public void doAfter() throws SQLException {
    JdbcDataSourceMetricInterceptor interceptor = new JdbcDataSourceMetricInterceptor();
    InterceptorTestUtils.init(interceptor, new JdbcConnectionMetricPlugin());
    Context context = EaseAgent.getContext();
    ContextUtils.setBeginTime(context);
    MethodInfo methodInfo = MethodInfo.builder().build();
    interceptor.doAfter(methodInfo, context);
    TagVerifier errorTagVerifier = TagVerifier.build(JdbcMetric.newConnectionTags(), JdbcDataSourceMetricInterceptor.ERR_CON_METRIC_KEY);
    LastJsonReporter lastJsonReporter = MockEaseAgent.lastMetricJsonReporter(errorTagVerifier::verifyAnd);
    Map<String, Object> metrics = lastJsonReporter.flushAndOnlyOne();
    assertEquals(1, metrics.get(MetricField.EXECUTION_COUNT.getField()));
    assertEquals(1, metrics.get(MetricField.EXECUTION_ERROR_COUNT.getField()));
    Connection connection = TestUtils.mockConnection();
    methodInfo = MethodInfo.builder().retValue(connection).throwable(new RuntimeException("test error")).build();
    interceptor.doAfter(methodInfo, context);
    metrics = lastJsonReporter.flushAndOnlyOne();
    assertEquals(2, metrics.get(MetricField.EXECUTION_COUNT.getField()));
    assertEquals(2, metrics.get(MetricField.EXECUTION_ERROR_COUNT.getField()));
    methodInfo = MethodInfo.builder().retValue(connection).build();
    interceptor.doAfter(methodInfo, context);
    metrics = lastJsonReporter.flushAndOnlyOne();
    assertEquals(2, metrics.get(MetricField.EXECUTION_COUNT.getField()));
    assertEquals(2, metrics.get(MetricField.EXECUTION_ERROR_COUNT.getField()));
    TagVerifier urlTagVerifier = TagVerifier.build(JdbcMetric.newConnectionTags(), TestUtils.URI);
    lastJsonReporter = MockEaseAgent.lastMetricJsonReporter(urlTagVerifier::verifyAnd);
    metrics = lastJsonReporter.flushAndOnlyOne();
    assertEquals(1, metrics.get(MetricField.EXECUTION_COUNT.getField()));
    assertNull(metrics.get(MetricField.EXECUTION_ERROR_COUNT.getField()));
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) TagVerifier(com.megaease.easeagent.mock.plugin.api.utils.TagVerifier) LastJsonReporter(com.megaease.easeagent.mock.report.impl.LastJsonReporter) Connection(java.sql.Connection) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) JdbcConnectionMetricPlugin(com.megaease.easeagent.plugin.jdbc.JdbcConnectionMetricPlugin) Test(org.junit.Test)

Example 4 with LastJsonReporter

use of com.megaease.easeagent.mock.report.impl.LastJsonReporter in project easeagent by megaease.

the class KafkaMetricTest method consumeError.

@Test
public void consumeError() {
    KafkaMetric kafkaMetric = get();
    kafkaMetric.consumeError(TOPIC);
    LastJsonReporter lastJsonReporter = lastMetricSupplier(TOPIC);
    Map<String, Object> metric = waitOne(lastJsonReporter);
    assertEquals(1, metric.get(MetricField.EXECUTION_CONSUMER_ERROR_COUNT.getField()));
}
Also used : LastJsonReporter(com.megaease.easeagent.mock.report.impl.LastJsonReporter) Test(org.junit.Test)

Example 5 with LastJsonReporter

use of com.megaease.easeagent.mock.report.impl.LastJsonReporter in project easeagent by megaease.

the class KafkaMessageListenerMetricInterceptorTest method doAfter.

@Test
public void doAfter() {
    KafkaMessageListenerMetricInterceptor interceptor = new KafkaMessageListenerMetricInterceptor();
    KafkaMetricTest.init(interceptor);
    Context context = EaseAgent.getContext();
    context.remove(KafkaMessageListenerMetricInterceptor.START);
    interceptor.doBefore(null, context);
    String topic = KafkaMessageListenerMetricInterceptorTest.class.getName() + ".doAfter";
    ConsumerRecord<String, String> record = KafkaConsumerMetricInterceptorTest.record(topic, 0);
    MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { record }).build();
    interceptor.doAfter(methodInfo, EaseAgent.getContext());
    LastJsonReporter lastJsonReporter = KafkaMetricTest.lastMetricSupplier(topic);
    lastJsonReporter.clean();
    Map<String, Object> metric = KafkaMetricTest.waitOne(lastJsonReporter);
    assertEquals(1, metric.get(MetricField.EXECUTION_CONSUMER_COUNT.getField()));
    interceptor.doBefore(null, context);
    methodInfo = MethodInfo.builder().args(new Object[] { record }).throwable(new RuntimeException("error")).build();
    interceptor.doAfter(methodInfo, EaseAgent.getContext());
    lastJsonReporter.clean();
    metric = KafkaMetricTest.waitOne(lastJsonReporter);
    assertEquals(2, metric.get(MetricField.EXECUTION_CONSUMER_COUNT.getField()));
    assertEquals(1, metric.get(MetricField.EXECUTION_CONSUMER_ERROR_COUNT.getField()));
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) LastJsonReporter(com.megaease.easeagent.mock.report.impl.LastJsonReporter) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) Test(org.junit.Test)

Aggregations

LastJsonReporter (com.megaease.easeagent.mock.report.impl.LastJsonReporter)25 Test (org.junit.Test)24 TagVerifier (com.megaease.easeagent.mock.plugin.api.utils.TagVerifier)13 MethodInfo (com.megaease.easeagent.plugin.interceptor.MethodInfo)10 Context (com.megaease.easeagent.plugin.api.Context)8 IPluginConfig (com.megaease.easeagent.plugin.api.config.IPluginConfig)7 Meter (com.megaease.easeagent.plugin.api.metric.Meter)2 ServiceMetric (com.megaease.easeagent.plugin.api.metric.ServiceMetric)2 RequestInfo (com.megaease.easeagent.plugin.tools.metrics.RequestInfo)2 AgentMono (easeagent.plugin.spring.gateway.reactor.AgentMono)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 MockServerWebExchange (org.springframework.mock.web.server.MockServerWebExchange)2 EaseAgentJunit4ClassRunner (com.megaease.easeagent.mock.plugin.api.junit.EaseAgentJunit4ClassRunner)1 ConfigTestUtils (com.megaease.easeagent.mock.plugin.api.utils.ConfigTestUtils)1 RequestContext (com.megaease.easeagent.plugin.api.context.RequestContext)1 MetricRegistry (com.megaease.easeagent.plugin.api.metric.MetricRegistry)1 Timer (com.megaease.easeagent.plugin.api.metric.Timer)1 MetricField (com.megaease.easeagent.plugin.api.metric.name.MetricField)1 AccessPlugin (com.megaease.easeagent.plugin.httpservlet.AccessPlugin)1