Update consumer register
This commit is contained in:
parent
61f8d3ee50
commit
098251c2e6
|
|
@ -48,10 +48,10 @@ public class ProducerOperationHandlerInterceptor implements InstanceMethodsAroun
|
|||
next = next.next();
|
||||
next.setHeadValue(invocation.getContext().get(next.getHeadKey()));
|
||||
}
|
||||
if (null == invocation.getOperationMeta()) {
|
||||
return;
|
||||
String operationName = "servicecomb/chassis" + method.getName();
|
||||
if (null != invocation.getOperationMeta()) {
|
||||
operationName = invocation.getMicroserviceQualifiedName();
|
||||
}
|
||||
String operationName = invocation.getMicroserviceQualifiedName();
|
||||
AbstractSpan span = ContextManager.createEntrySpan(operationName, contextCarrier);
|
||||
String url = invocation.getOperationMeta().getOperationPath();
|
||||
Tags.URL.set(span, url);
|
||||
|
|
@ -62,9 +62,6 @@ public class ProducerOperationHandlerInterceptor implements InstanceMethodsAroun
|
|||
@Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Object ret) throws Throwable {
|
||||
Invocation invocation = (Invocation)allArguments[0];
|
||||
if (null == invocation.getOperationMeta()) {
|
||||
return ret;
|
||||
}
|
||||
AbstractSpan span = ContextManager.activeSpan();
|
||||
int statusCode = invocation.getStatus().getStatusCode();
|
||||
if (statusCode >= 400) {
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ package org.apache.skywalking.apm.plugin.servicecomb;
|
|||
import io.servicecomb.core.Invocation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import org.apache.skywalking.apm.agent.core.context.CarrierItem;
|
||||
import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
|
||||
import org.apache.skywalking.apm.agent.core.context.ContextManager;
|
||||
|
|
@ -43,11 +44,10 @@ public class TransportClientHandlerInterceptor implements InstanceMethodsAroundI
|
|||
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
|
||||
Invocation invocation = (Invocation)allArguments[0];
|
||||
if (null == invocation.getOperationMeta() || null == invocation.getEndpoint()) {
|
||||
String peer = AsserRegister(invocation);
|
||||
if (null == peer) {
|
||||
return;
|
||||
}
|
||||
URI uri = new URI(invocation.getEndpoint().toString());
|
||||
String peer = uri.getHost() + ":" + uri.getPort();
|
||||
String operationName = invocation.getMicroserviceQualifiedName();
|
||||
final ContextCarrier contextCarrier = new ContextCarrier();
|
||||
AbstractSpan span = ContextManager.createExitSpan(operationName, contextCarrier, peer);
|
||||
|
|
@ -65,7 +65,8 @@ public class TransportClientHandlerInterceptor implements InstanceMethodsAroundI
|
|||
@Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Object ret) throws Throwable {
|
||||
Invocation invocation = (Invocation)allArguments[0];
|
||||
if (null == invocation.getOperationMeta() || null == invocation.getEndpoint()) {
|
||||
String peer = AsserRegister(invocation);
|
||||
if (null == peer) {
|
||||
return ret;
|
||||
}
|
||||
AbstractSpan span = ContextManager.activeSpan();
|
||||
|
|
@ -75,15 +76,31 @@ public class TransportClientHandlerInterceptor implements InstanceMethodsAroundI
|
|||
Tags.STATUS_CODE.set(span, Integer.toString(statusCode));
|
||||
}
|
||||
ContextManager.stopSpan();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Throwable t) {
|
||||
Invocation invocation = (Invocation)allArguments[0];
|
||||
if (null == invocation.getOperationMeta() || null == invocation.getEndpoint()) {
|
||||
return;
|
||||
}
|
||||
AbstractSpan span = ContextManager.activeSpan();
|
||||
span.errorOccurred();
|
||||
span.log(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serviecomb chissis Consumers and providers need to register at the service center. If the consumer is not
|
||||
* registered then return
|
||||
*/
|
||||
private String AsserRegister(Invocation invocation) throws URISyntaxException {
|
||||
if (null == invocation.getOperationMeta() || null == invocation.getEndpoint()) {
|
||||
return null;
|
||||
}
|
||||
URI uri = new URI(invocation.getEndpoint().toString());
|
||||
String peer = uri.getHost() + ":" + uri.getPort();
|
||||
return peer;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import io.servicecomb.core.definition.OperationMeta;
|
|||
import io.servicecomb.core.definition.SchemaMeta;
|
||||
import io.servicecomb.swagger.invocation.InvocationType;
|
||||
import io.servicecomb.swagger.invocation.SwaggerInvocation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import javax.ws.rs.core.Response;
|
||||
import org.apache.skywalking.apm.agent.core.boot.ServiceManager;
|
||||
|
|
@ -74,6 +75,8 @@ public class ProducerOperationHandlerInterceptorTest {
|
|||
@Mock
|
||||
private Endpoint endpoint;
|
||||
@Mock
|
||||
private Method method;
|
||||
@Mock
|
||||
private SwaggerInvocation swagger;
|
||||
private Object[] allArguments;
|
||||
private Class[] argumentsType;
|
||||
|
|
@ -95,19 +98,21 @@ public class ProducerOperationHandlerInterceptorTest {
|
|||
when(invocation.getOperationMeta()).thenReturn(operationMeta);
|
||||
when(invocation.getStatus()).thenReturn(statusType);
|
||||
when(statusType.getStatusCode()).thenReturn(200);
|
||||
when(method.getName()).thenReturn("producer");
|
||||
when(invocation.getInvocationType()).thenReturn(InvocationType.PRODUCER);
|
||||
Config.Agent.APPLICATION_CODE = "serviceComnTestCases-APP";
|
||||
|
||||
allArguments = new Object[] {invocation,};
|
||||
argumentsType = new Class[] {};
|
||||
swaggerArguments = new Class[] {};
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConsumer() throws Throwable {
|
||||
|
||||
invocationInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentsType, null);
|
||||
invocationInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentsType, null);
|
||||
invocationInterceptor.beforeMethod(enhancedInstance, method, allArguments, argumentsType, null);
|
||||
invocationInterceptor.afterMethod(enhancedInstance, method, allArguments, argumentsType, null);
|
||||
|
||||
Assert.assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
|
|
|
|||
Loading…
Reference in New Issue