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());
}
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();
}
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()));
}
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()));
}
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()));
}
Aggregations