Search in sources :

Example 1 with TagVerifier

use of com.megaease.easeagent.mock.plugin.api.utils.TagVerifier 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 TagVerifier

use of com.megaease.easeagent.mock.plugin.api.utils.TagVerifier 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 TagVerifier

use of com.megaease.easeagent.mock.plugin.api.utils.TagVerifier 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 TagVerifier

use of com.megaease.easeagent.mock.plugin.api.utils.TagVerifier in project easeagent by megaease.

the class JdbcMetricTest method onRemoval.

@Test
public void onRemoval() {
    JdbcMetric jdbcMetric = get();
    Context context = EaseAgent.getContext();
    ContextUtils.setBeginTime(context);
    jdbcMetric.collectMetric(TestUtils.URI, true, context);
    TagVerifier tagVerifier = TagVerifier.build(JdbcMetric.newConnectionTags(), TestUtils.URI);
    LastJsonReporter lastJsonReporter = MockEaseAgent.lastMetricJsonReporter(tagVerifier::verifyAnd);
    Map<String, Object> metrics = lastJsonReporter.flushAndOnlyOne();
    assertNotNull(metrics);
    jdbcMetric.collectMetric(TestUtils.URI, false, context);
    metrics = lastJsonReporter.flushAndOnlyOne();
    assertNotNull(metrics);
    RemovalNotification<String, String> removalNotification = RemovalNotification.create(TestUtils.URI, "", RemovalCause.SIZE);
    jdbcMetric.onRemoval(removalNotification);
    try {
        lastJsonReporter.flushAndOnlyOne();
        fail("must be throw error");
    } catch (Exception e) {
    // must be error
    }
}
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) Test(org.junit.Test)

Example 5 with TagVerifier

use of com.megaease.easeagent.mock.plugin.api.utils.TagVerifier in project easeagent by megaease.

the class GatewayAccessLogInterceptorTest method after.

@Test
public void after() throws InterruptedException {
    GatewayAccessLogInterceptor interceptor = new GatewayAccessLogInterceptor();
    InterceptorTestUtils.init(interceptor, new AccessPlugin());
    Context context = EaseAgent.getContext();
    MockServerWebExchange mockServerWebExchange = TestServerWebExchangeUtils.mockServerWebExchange();
    MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { mockServerWebExchange }).build();
    interceptor.before(methodInfo, context);
    Long start = context.get(startTime);
    assertNotNull(start);
    interceptor.after(methodInfo, context);
    assertNull(context.get(startTime));
    assertTrue(methodInfo.getRetValue() instanceof AgentMono);
    AgentMono agentMono = (AgentMono) methodInfo.getRetValue();
    TagVerifier tagVerifier = new TagVerifier().add("type", "access-log").add("system", "test-gateway-system");
    LastJsonReporter lastJsonReporter = MockEaseAgent.lastMetricJsonReporter(tagVerifier::verifyAnd);
    Thread thread = new Thread(() -> agentMono.getFinish().accept(agentMono.getMethodInfo(), agentMono.getAsyncContext()));
    thread.start();
    thread.join();
    RequestInfo requestInfo = getRequestInfo(lastJsonReporter);
    verify(requestInfo, start);
}
Also used : RequestContext(com.megaease.easeagent.plugin.api.context.RequestContext) Context(com.megaease.easeagent.plugin.api.Context) AgentMono(easeagent.plugin.spring.gateway.reactor.AgentMono) AccessPlugin(easeagent.plugin.spring.gateway.AccessPlugin) MockServerWebExchange(org.springframework.mock.web.server.MockServerWebExchange) RequestInfo(com.megaease.easeagent.plugin.tools.metrics.RequestInfo) TagVerifier(com.megaease.easeagent.mock.plugin.api.utils.TagVerifier) LastJsonReporter(com.megaease.easeagent.mock.report.impl.LastJsonReporter) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) GatewayServerTracingInterceptorTest(easeagent.plugin.spring.gateway.interceptor.tracing.GatewayServerTracingInterceptorTest) Test(org.junit.Test)

Aggregations

TagVerifier (com.megaease.easeagent.mock.plugin.api.utils.TagVerifier)13 LastJsonReporter (com.megaease.easeagent.mock.report.impl.LastJsonReporter)13 Test (org.junit.Test)13 Context (com.megaease.easeagent.plugin.api.Context)7 MethodInfo (com.megaease.easeagent.plugin.interceptor.MethodInfo)6 IPluginConfig (com.megaease.easeagent.plugin.api.config.IPluginConfig)5 Meter (com.megaease.easeagent.plugin.api.metric.Meter)2 AgentMono (easeagent.plugin.spring.gateway.reactor.AgentMono)2 MockServerWebExchange (org.springframework.mock.web.server.MockServerWebExchange)2 ConfigTestUtils (com.megaease.easeagent.mock.plugin.api.utils.ConfigTestUtils)1 RequestContext (com.megaease.easeagent.plugin.api.context.RequestContext)1 ServiceMetric (com.megaease.easeagent.plugin.api.metric.ServiceMetric)1 HttpServletPlugin (com.megaease.easeagent.plugin.httpservlet.HttpServletPlugin)1 JdbcConnectionMetricPlugin (com.megaease.easeagent.plugin.jdbc.JdbcConnectionMetricPlugin)1 JdbcDataSourceMetricPlugin (com.megaease.easeagent.plugin.jdbc.JdbcDataSourceMetricPlugin)1 SqlInfo (com.megaease.easeagent.plugin.jdbc.common.SqlInfo)1 RedisPlugin (com.megaease.easeagent.plugin.redis.RedisPlugin)1 RequestInfo (com.megaease.easeagent.plugin.tools.metrics.RequestInfo)1 AccessPlugin (easeagent.plugin.spring.gateway.AccessPlugin)1 SpringGatewayPlugin (easeagent.plugin.spring.gateway.SpringGatewayPlugin)1