Search in sources :

Example 1 with Invoker

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);
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) Invoker(org.apache.dubbo.rpc.Invoker) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId)

Example 2 with Invoker

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);
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) Invoker(org.apache.dubbo.rpc.Invoker) DubboInvoker(org.apache.dubbo.rpc.protocol.dubbo.DubboInvoker) DubboInvoker(org.apache.dubbo.rpc.protocol.dubbo.DubboInvoker) URL(org.apache.dubbo.common.URL) Test(org.junit.Test)

Example 3 with Invoker

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));
}
Also used : Invoker(org.apache.dubbo.rpc.Invoker) MonitorService(org.apache.dubbo.monitor.MonitorService) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 4 with Invoker

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;
        }
    }));
}
Also used : CustomMatcher(org.hamcrest.CustomMatcher) Invoker(org.apache.dubbo.rpc.Invoker) MonitorService(org.apache.dubbo.monitor.MonitorService) URL(org.apache.dubbo.common.URL) URLBuilder(org.apache.dubbo.common.URLBuilder) Test(org.junit.jupiter.api.Test)

Example 5 with Invoker

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));
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) MonitorFactory(org.apache.dubbo.monitor.MonitorFactory) Invocation(org.apache.dubbo.rpc.Invocation) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) Invoker(org.apache.dubbo.rpc.Invoker) MonitorService(org.apache.dubbo.monitor.MonitorService) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Aggregations

Invoker (org.apache.dubbo.rpc.Invoker)128 Test (org.junit.jupiter.api.Test)104 URL (org.apache.dubbo.common.URL)74 RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)66 ArrayList (java.util.ArrayList)48 Invocation (org.apache.dubbo.rpc.Invocation)42 Result (org.apache.dubbo.rpc.Result)26 AppResponse (org.apache.dubbo.rpc.AppResponse)21 MockClusterInvoker (org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker)21 RegistryDirectory (org.apache.dubbo.registry.integration.RegistryDirectory)20 Router (org.apache.dubbo.rpc.cluster.Router)18 MockInvoker (org.apache.dubbo.rpc.cluster.router.MockInvoker)18 HashMap (java.util.HashMap)13 LoadBalance (org.apache.dubbo.rpc.cluster.LoadBalance)13 AsyncRpcResult (org.apache.dubbo.rpc.AsyncRpcResult)12 RpcException (org.apache.dubbo.rpc.RpcException)12 LeastActiveLoadBalance (org.apache.dubbo.rpc.cluster.loadbalance.LeastActiveLoadBalance)8 RandomLoadBalance (org.apache.dubbo.rpc.cluster.loadbalance.RandomLoadBalance)8 RoundRobinLoadBalance (org.apache.dubbo.rpc.cluster.loadbalance.RoundRobinLoadBalance)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8