use of com.megaease.easeagent.plugin.api.Context in project easeagent by megaease.
the class TraceHelperTest method performSuccess.
@Test
public void performSuccess() {
BsonDocument bsonDocument = new BsonDocument();
bsonDocument.put("collection", new BsonString(collection));
CommandSucceededEvent succeededEvent = new CommandSucceededEvent(this.requestId, this.connectionDescription, this.cmdName, bsonDocument, 10);
Context context = EaseAgent.getContext();
TraceHelper.commandStarted(context, this.config, this.startedEvent);
TraceHelper.commandSucceeded(context, succeededEvent);
this.assertTrace(true, null);
}
use of com.megaease.easeagent.plugin.api.Context in project easeagent by megaease.
the class MongoBaseTest method before.
@Before
public void before() {
EaseAgent.initializeContextSupplier.get().clear();
config = new AutoRefreshPluginConfigImpl();
IPluginConfig iPluginConfig = mock(IPluginConfig.class);
when(iPluginConfig.enabled()).thenReturn(true);
when(iPluginConfig.namespace()).thenReturn("mongodb");
when(iPluginConfig.domain()).thenReturn("observability");
config.onChange(null, iPluginConfig);
Context context = EaseAgent.getContext();
ContextUtils.setBeginTime(context);
MockEaseAgent.cleanLastSpan();
clusterId = new ClusterId("local-cluster");
serverAddress = new ServerAddress("127.0.0.1", 2020);
serverId = new ServerId(clusterId, serverAddress);
this.connectionDescription = new ConnectionDescription(serverId);
Map<String, Object> map = new HashMap<>();
map.put("collection", collection);
BsonDocument bsonDocument = BsonDocument.parse(JsonUtil.toJson(map));
this.startedEvent = new CommandStartedEvent(this.requestId, this.connectionDescription, this.dbName, this.cmdName, bsonDocument);
}
use of com.megaease.easeagent.plugin.api.Context in project easeagent by megaease.
the class MongoReactiveMetricTest method performSuccess.
@Test
public void performSuccess() {
Context context = EaseAgent.getContext();
MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { null, null, null, mock(SingleResultCallback.class) }).build();
interceptor.before(methodInfo, context);
BsonDocument bsonDocument = new BsonDocument();
bsonDocument.put("collection", new BsonString(collection));
CommandSucceededEvent succeededEvent = new CommandSucceededEvent(this.requestId, this.connectionDescription, this.cmdName, bsonDocument, 10);
this.listener.commandStarted(startedEvent);
this.listener.commandSucceeded(succeededEvent);
MongoInternalConnectionSendAndReceiveAsync4MetricInterceptor.SingleResultCallbackProxy<?> proxy = (MongoInternalConnectionSendAndReceiveAsync4MetricInterceptor.SingleResultCallbackProxy<?>) methodInfo.getArgs()[3];
proxy.onResult(null, null);
this.assertMetric(initMetricInterceptor.getMongoMetric().getNameFactory(), initMetricInterceptor.getMongoMetric().getMetricRegistry(), true);
context.exit(interceptor.getEnterKey(methodInfo, context));
}
use of com.megaease.easeagent.plugin.api.Context 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.api.Context in project easeagent by megaease.
the class KafkaProducerDoSendInterceptorTest method doBefore.
@Test
public void doBefore() {
KafkaProducerDoSendInterceptor interceptor = new KafkaProducerDoSendInterceptor();
MockKafkaProducer kafkaProducer = MockKafkaProducer.buildOne();
Context context = EaseAgent.getContext();
ProducerRecord record = new ProducerRecord<>(topic, key, value);
MethodInfo methodInfo = MethodInfo.builder().invoker(kafkaProducer).args(new Object[] { record, null }).build();
interceptor.doBefore(methodInfo, context);
assertTrue(context.currentTracing().hasCurrentSpan());
Span span = finishSpan();
assertFalse(context.currentTracing().hasCurrentSpan());
ReportSpan mockSpan = MockEaseAgent.getLastSpan();
SpanTestUtils.sameId(span, mockSpan);
checkBaseInfo(mockSpan);
assertEquals(key, mockSpan.tag(KafkaTags.KAFKA_KEY_TAG));
record = new ProducerRecord<>(topic, value);
methodInfo = MethodInfo.builder().invoker(kafkaProducer).args(new Object[] { record, null }).build();
context = EaseAgent.getContext();
interceptor.doBefore(methodInfo, context);
assertTrue(context.currentTracing().hasCurrentSpan());
span = finishSpan();
assertFalse(context.currentTracing().hasCurrentSpan());
mockSpan = MockEaseAgent.getLastSpan();
SpanTestUtils.sameId(span, mockSpan);
checkBaseInfo(mockSpan);
assertNull(mockSpan.tag(KafkaTags.KAFKA_KEY_TAG));
record = new ProducerRecord<>(topic, value);
methodInfo = MethodInfo.builder().invoker(kafkaProducer).args(new Object[] { record, null }).build();
context = EaseAgent.getContext();
interceptor.doBefore(methodInfo, context);
assertTrue(context.currentTracing().hasCurrentSpan());
finishSpan();
assertFalse(context.currentTracing().hasCurrentSpan());
assertNotNull(methodInfo.getArgs()[1]);
assertTrue(methodInfo.getArgs()[1] instanceof TraceCallback);
}
Aggregations