use of com.megaease.easeagent.plugin.kafka.interceptor.redirect.KafkaAbstractConfigConstructInterceptor in project easeagent by megaease.
the class KafkaProducerDoSendInterceptorTest method testRedirectedTag.
@Test
public void testRedirectedTag() {
KafkaAbstractConfigConstructInterceptor kafkaAbstractConfigConstructInterceptor = new KafkaAbstractConfigConstructInterceptor();
KafkaTestUtils.mockRedirect(() -> {
Properties props = new Properties();
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, TestConst.URIS);
props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { props }).build();
kafkaAbstractConfigConstructInterceptor.doBefore(methodInfo, EaseAgent.getContext());
MockKafkaProducer kafkaProducer = new MockKafkaProducer(props);
kafkaProducer.setEaseAgent$$DynamicField$$Data(props.getProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG));
KafkaProducerDoSendInterceptor interceptor = new KafkaProducerDoSendInterceptor();
Context context = EaseAgent.getContext();
ProducerRecord record = new ProducerRecord<>(topic, key, value);
methodInfo = MethodInfo.builder().invoker(kafkaProducer).args(new Object[] { record, null }).build();
interceptor.doBefore(methodInfo, context);
assertTrue(context.currentTracing().hasCurrentSpan());
finishSpan();
assertFalse(context.currentTracing().hasCurrentSpan());
ReportSpan mockSpan = MockEaseAgent.getLastSpan();
assertEquals(TestConst.REDIRECT_URIS, mockSpan.tag("label.remote"));
});
}
use of com.megaease.easeagent.plugin.kafka.interceptor.redirect.KafkaAbstractConfigConstructInterceptor in project easeagent by megaease.
the class KafkaMessageListenerTracingInterceptorTest method doBeforeRedirected.
@Test
public void doBeforeRedirected() {
KafkaAbstractConfigConstructInterceptor kafkaAbstractConfigConstructInterceptor = new KafkaAbstractConfigConstructInterceptor();
Context context = EaseAgent.getContext();
KafkaTestUtils.mockRedirect(() -> {
Properties props = new Properties();
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, TestConst.URIS);
props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
MethodInfo constructMethodInfo = MethodInfo.builder().args(new Object[] { props }).build();
kafkaAbstractConfigConstructInterceptor.doBefore(constructMethodInfo, EaseAgent.getContext());
MockKafkaConsumer kafkaConsumer = new MockKafkaConsumer(props);
kafkaConsumer.setEaseAgent$$DynamicField$$Data(props.getProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG));
KafkaMessageListenerTracingInterceptor interceptor = new KafkaMessageListenerTracingInterceptor();
MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { createConsumerRecord(kafkaConsumer) }).build();
interceptor.doBefore(methodInfo, context);
context.<Span>remove(KafkaMessageListenerTracingInterceptor.SPAN).finish();
check(MockEaseAgent.getLastSpan(), (String) kafkaConsumer.getEaseAgent$$DynamicField$$Data());
assertEquals(TestConst.REDIRECT_URIS, MockEaseAgent.getLastSpan().tag("label.remote"));
});
}
use of com.megaease.easeagent.plugin.kafka.interceptor.redirect.KafkaAbstractConfigConstructInterceptor in project easeagent by megaease.
the class KafkaConsumerTracingInterceptorTest method setConsumerSpan.
@Test
public void setConsumerSpan() {
KafkaConsumerTracingInterceptor interceptor = new KafkaConsumerTracingInterceptor();
Context context = EaseAgent.getContext();
Span span = context.nextSpan().start();
String topic = "testTopic";
String uri = "testUri";
interceptor.setConsumerSpan(topic, uri, span);
span.finish();
ReportSpan mockSpan = MockEaseAgent.getLastSpan();
checkBaseInfo(mockSpan, topic, uri);
KafkaAbstractConfigConstructInterceptor kafkaAbstractConfigConstructInterceptor = new KafkaAbstractConfigConstructInterceptor();
KafkaTestUtils.mockRedirect(() -> {
Properties props = new Properties();
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, TestConst.URIS);
props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { props }).build();
kafkaAbstractConfigConstructInterceptor.doBefore(methodInfo, EaseAgent.getContext());
MockKafkaConsumer kafkaConsumer = new MockKafkaConsumer(props);
kafkaConsumer.setEaseAgent$$DynamicField$$Data(props.getProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG));
Span span1 = context.nextSpan().start();
interceptor.setConsumerSpan(topic, (String) kafkaConsumer.getEaseAgent$$DynamicField$$Data(), span1);
span1.finish();
ReportSpan mockSpan1 = MockEaseAgent.getLastSpan();
assertEquals(TestConst.REDIRECT_URIS, mockSpan1.tag("label.remote"));
});
}
use of com.megaease.easeagent.plugin.kafka.interceptor.redirect.KafkaAbstractConfigConstructInterceptor in project easeagent by megaease.
the class KafkaMetricTest method newTags.
@Test
public void newTags() {
Tags tags = KafkaMetric.newTags();
assertEquals("application", tags.getCategory());
assertEquals("kafka", tags.getType());
assertEquals("resource", tags.getKeyFieldName());
KafkaAbstractConfigConstructInterceptor interceptor = new KafkaAbstractConfigConstructInterceptor();
KafkaTestUtils.mockRedirect(() -> {
Map config = new HashMap();
config.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, TestConst.URIS);
MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { config }).build();
interceptor.doBefore(methodInfo, EaseAgent.getContext());
String testTagKey = "tagKey";
String testTagValue = "tagValue";
Map<String, String> oldTags = RedirectProcessor.INSTANCE.getTags();
Map<String, String> newTagsMap = new HashMap<>();
newTagsMap.put(testTagKey, testTagValue);
AgentFieldReflectAccessor.setFieldValue(RedirectProcessor.INSTANCE, "tags", newTagsMap);
try {
Tags newTags = KafkaMetric.newTags();
assertEquals(testTagValue, newTags.getTags().get(testTagKey));
} finally {
AgentFieldReflectAccessor.setFieldValue(RedirectProcessor.INSTANCE, "tags", oldTags);
}
});
}
Aggregations