use of org.apache.dubbo.rpc.Invoker in project pinpoint by naver.
the class ApacheDubboProviderInterceptor method readRequestTrace.
private Trace readRequestTrace(Object target, Object[] args) {
final Invoker invoker = (Invoker) target;
// Ignore monitor service.
if (ApacheDubboConstants.MONITOR_SERVICE_FQCN.equals(invoker.getInterface().getName())) {
return traceContext.disableSampling();
}
final RpcInvocation invocation = (RpcInvocation) args[0];
// If this transaction is not traceable, mark as disabled.
if (invocation.getAttachment(ApacheDubboConstants.META_DO_NOT_TRACE) != null) {
return traceContext.disableSampling();
}
final String transactionId = invocation.getAttachment(ApacheDubboConstants.META_TRANSACTION_ID);
// We'll have to check if a trace object already exists and create a span event instead of a span in that case.
if (transactionId == null) {
return traceContext.newTraceObject();
}
// otherwise, continue tracing with given data.
final long parentSpanID = NumberUtils.parseLong(invocation.getAttachment(ApacheDubboConstants.META_PARENT_SPAN_ID), SpanId.NULL);
final long spanID = NumberUtils.parseLong(invocation.getAttachment(ApacheDubboConstants.META_SPAN_ID), SpanId.NULL);
final short flags = NumberUtils.parseShort(invocation.getAttachment(ApacheDubboConstants.META_FLAGS), (short) 0);
final TraceId traceId = traceContext.createTraceId(transactionId, parentSpanID, spanID, flags);
return traceContext.continueTraceObject(traceId);
}
use of org.apache.dubbo.rpc.Invoker in project pinpoint by naver.
the class ApacheDubboProviderInterceptorTest method createTrace.
@Test
public void createTrace() {
doReturn(true).when(trace).canSampled();
doReturn(spanRecorder).when(trace).getSpanRecorder();
doReturn(trace).when(traceContext).newTraceObject();
Invoker invoker = new DubboInvoker(Object.class, new URL("http", "127.0.0.1", 8080), null);
ApacheDubboProviderInterceptor interceptor = new ApacheDubboProviderInterceptor(traceContext, descriptor);
RpcInvocation rpcInvocation = new RpcInvocation();
rpcInvocation.setInvoker(invoker);
rpcInvocation.setMethodName("test");
rpcInvocation.setAttachment(ApacheDubboConstants.META_PARENT_APPLICATION_NAME, UUID.randomUUID().toString());
Object[] args = new Object[] { rpcInvocation };
interceptor.createTrace(invoker, args);
}
use of org.apache.dubbo.rpc.Invoker in project dubbo by alibaba.
the class DubboMonitorTest method testLookUp.
@Test
public void testLookUp() {
Invoker invoker = mock(Invoker.class);
MonitorService monitorService = mock(MonitorService.class);
URL queryUrl = URL.valueOf("dubbo://127.0.0.1:7070?interval=20");
given(invoker.getUrl()).willReturn(queryUrl);
DubboMonitor dubboMonitor = new DubboMonitor(invoker, monitorService);
dubboMonitor.lookup(queryUrl);
verify(monitorService).lookup(eq(queryUrl));
}
use of org.apache.dubbo.rpc.Invoker in project dubbo by alibaba.
the class DubboMonitorTest method testSum.
@Test
public void testSum() {
URL statistics = new URLBuilder(DUBBO_PROTOCOL, "10.20.153.11", 0).addParameter(MonitorService.APPLICATION, "morgan").addParameter(MonitorService.INTERFACE, "MemberService").addParameter(MonitorService.METHOD, "findPerson").addParameter(MonitorService.CONSUMER, "10.20.153.11").addParameter(MonitorService.SUCCESS, 1).addParameter(MonitorService.FAILURE, 0).addParameter(MonitorService.ELAPSED, 3).addParameter(MonitorService.MAX_ELAPSED, 3).addParameter(MonitorService.CONCURRENT, 1).addParameter(MonitorService.MAX_CONCURRENT, 1).build();
Invoker invoker = mock(Invoker.class);
MonitorService monitorService = mock(MonitorService.class);
given(invoker.getUrl()).willReturn(URL.valueOf("dubbo://127.0.0.1:7070?interval=20"));
DubboMonitor dubboMonitor = new DubboMonitor(invoker, monitorService);
dubboMonitor.collect(statistics);
dubboMonitor.collect(statistics.addParameter(MonitorService.SUCCESS, 3).addParameter(MonitorService.CONCURRENT, 2).addParameter(MonitorService.INPUT, 1).addParameter(MonitorService.OUTPUT, 2));
dubboMonitor.collect(statistics.addParameter(MonitorService.SUCCESS, 6).addParameter(MonitorService.ELAPSED, 2));
dubboMonitor.send();
ArgumentCaptor<URL> summaryCaptor = ArgumentCaptor.forClass(URL.class);
verify(monitorService, atLeastOnce()).collect(summaryCaptor.capture());
List<URL> allValues = summaryCaptor.getAllValues();
assertThat(allValues, not(nullValue()));
assertThat(allValues, hasItem(new CustomMatcher<URL>("Monitor count should greater than 1") {
@Override
public boolean matches(Object item) {
URL url = (URL) item;
return Integer.valueOf(url.getParameter(MonitorService.SUCCESS)) > 1;
}
}));
}
use of org.apache.dubbo.rpc.Invoker in project dubbo by alibaba.
the class MonitorFilterTest method testSkipMonitorIfNotHasKey.
@Test
public void testSkipMonitorIfNotHasKey() {
MonitorFilter monitorFilter = new MonitorFilter();
MonitorFactory mockMonitorFactory = mock(MonitorFactory.class);
monitorFilter.setMonitorFactory(mockMonitorFactory);
Invocation invocation = new RpcInvocation("aaa", MonitorService.class.getName(), "", new Class<?>[0], new Object[0]);
Invoker invoker = mock(Invoker.class);
given(invoker.getUrl()).willReturn(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880?" + APPLICATION_KEY + "=abc&" + SIDE_KEY + "=" + CONSUMER_SIDE));
monitorFilter.invoke(invoker, invocation);
verify(mockMonitorFactory, never()).getMonitor(any(URL.class));
}
Aggregations