Remove duplicate ServiceComb plugin codes. (#189)
Follow https://github.com/apache/skywalking-java/pull/127#issuecomment-1140764345
This commit is contained in:
parent
e81638ea4e
commit
d468806f43
|
|
@ -28,7 +28,6 @@
|
|||
<artifactId>servicecomb-plugin</artifactId>
|
||||
|
||||
<modules>
|
||||
<module>servicecomb-java-chassis-1.x-plugin</module>
|
||||
<module>servicecomb-java-chassis-2.x-plugin</module>
|
||||
</modules>
|
||||
<packaging>pom</packaging>
|
||||
|
|
|
|||
|
|
@ -1,46 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
~ contributor license agreements. See the NOTICE file distributed with
|
||||
~ this work for additional information regarding copyright ownership.
|
||||
~ The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
~ (the "License"); you may not use this file except in compliance with
|
||||
~ the License. You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
~
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>servicecomb-plugin</artifactId>
|
||||
<groupId>org.apache.skywalking</groupId>
|
||||
<version>8.11.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>apm-servicecomb-java-chassis-1.x-plugin</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>servicecomb-java-chassis-1.x-plugin</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<java-chassis-core.version>1.0.0-m1</java-chassis-core.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.servicecomb</groupId>
|
||||
<artifactId>java-chassis-core</artifactId>
|
||||
<version>${java-chassis-core.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.apm.plugin.servicecomb.v1;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import org.apache.servicecomb.core.Invocation;
|
||||
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;
|
||||
import org.apache.skywalking.apm.agent.core.context.tag.Tags;
|
||||
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
|
||||
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
|
||||
|
||||
public class ProducerOperationHandlerInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
|
||||
@Override
|
||||
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
|
||||
MethodInterceptResult result) throws Throwable {
|
||||
Invocation invocation = (Invocation) allArguments[0];
|
||||
ContextCarrier contextCarrier = new ContextCarrier();
|
||||
CarrierItem next = contextCarrier.items();
|
||||
while (next.hasNext()) {
|
||||
next = next.next();
|
||||
next.setHeadValue(invocation.getContext().get(next.getHeadKey()));
|
||||
}
|
||||
String operationName = invocation.getMicroserviceQualifiedName();
|
||||
AbstractSpan span = ContextManager.createEntrySpan(operationName, contextCarrier);
|
||||
String url = invocation.getOperationMeta().getOperationPath();
|
||||
Tags.URL.set(span, url);
|
||||
span.setComponent(ComponentsDefine.SERVICECOMB);
|
||||
SpanLayer.asRPCFramework(span);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
|
||||
Object ret) throws Throwable {
|
||||
Invocation invocation = (Invocation) allArguments[0];
|
||||
AbstractSpan span = ContextManager.activeSpan();
|
||||
int statusCode = invocation.getStatus().getStatusCode();
|
||||
if (statusCode >= 400) {
|
||||
span.errorOccurred();
|
||||
Tags.HTTP_RESPONSE_STATUS_CODE.set(span, statusCode);
|
||||
}
|
||||
ContextManager.stopSpan();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Throwable t) {
|
||||
AbstractSpan span = ContextManager.activeSpan();
|
||||
span.log(t);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,96 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.apm.plugin.servicecomb.v1;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import org.apache.servicecomb.core.Invocation;
|
||||
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;
|
||||
import org.apache.skywalking.apm.agent.core.context.tag.Tags;
|
||||
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
|
||||
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
|
||||
|
||||
public class TransportClientHandlerInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
|
||||
@Override
|
||||
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
|
||||
MethodInterceptResult result) throws Throwable {
|
||||
Invocation invocation = (Invocation) allArguments[0];
|
||||
if (!checkRegisterStatus(invocation)) {
|
||||
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);
|
||||
CarrierItem next = contextCarrier.items();
|
||||
while (next.hasNext()) {
|
||||
next = next.next();
|
||||
invocation.getContext().put(next.getHeadKey(), next.getHeadValue());
|
||||
}
|
||||
String url = invocation.getOperationMeta().getOperationPath();
|
||||
Tags.URL.set(span, url);
|
||||
span.setComponent(ComponentsDefine.SERVICECOMB);
|
||||
SpanLayer.asRPCFramework(span);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
|
||||
Object ret) throws Throwable {
|
||||
Invocation invocation = (Invocation) allArguments[0];
|
||||
if (!checkRegisterStatus(invocation)) {
|
||||
return ret;
|
||||
}
|
||||
AbstractSpan span = ContextManager.activeSpan();
|
||||
int statusCode = invocation.getStatus().getStatusCode();
|
||||
if (statusCode >= 400) {
|
||||
span.errorOccurred();
|
||||
Tags.HTTP_RESPONSE_STATUS_CODE.set(span, 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 (!checkRegisterStatus(invocation)) {
|
||||
return;
|
||||
}
|
||||
AbstractSpan span = ContextManager.activeSpan();
|
||||
span.log(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serviecomb chassis Consumers and providers need to register at the service center. If the consumer is not
|
||||
* registered then return false.
|
||||
*/
|
||||
private Boolean checkRegisterStatus(Invocation invocation) {
|
||||
return null != invocation.getOperationMeta() && null != invocation.getEndpoint();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.apm.plugin.servicecomb.v1.define;
|
||||
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
|
||||
/**
|
||||
* {@link ProducerOperationHandlerInstrumentation} represents that skywalking intercept {@link
|
||||
* org.apache.servicecomb.core.handler.impl.ProducerOperationHandler#handle(org.apache.servicecomb.core.Invocation,
|
||||
* org.apache.servicecomb.swagger.invocation.AsyncResponse)} by using ProducerOperationHandlerInterceptor
|
||||
*/
|
||||
public class ProducerOperationHandlerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
|
||||
private static final String ENHANCE_CLASS = "org.apache.servicecomb.core.handler.impl.ProducerOperationHandler";
|
||||
|
||||
private static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.servicecomb.v1.ProducerOperationHandlerInterceptor";
|
||||
|
||||
@Override
|
||||
protected ClassMatch enhanceClass() {
|
||||
return NameMatch.byName(ENHANCE_CLASS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
|
||||
return new ConstructorInterceptPoint[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||
return new InstanceMethodsInterceptPoint[] {
|
||||
new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named("handle");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return INTERCEPT_CLASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOverrideArgs() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.apm.plugin.servicecomb.v1.define;
|
||||
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
|
||||
/**
|
||||
* {@link TransportClientHandlerInstrumentation} represents that skywalking intercept {@link
|
||||
* org.apache.servicecomb.core.handler.impl.TransportClientHandler} by using linkTransportClientHandlerInterceptor
|
||||
*/
|
||||
public class TransportClientHandlerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
|
||||
private static final String ENHANCE_CLASS = "org.apache.servicecomb.core.handler.impl.TransportClientHandler";
|
||||
|
||||
private static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.servicecomb.v1.TransportClientHandlerInterceptor";
|
||||
|
||||
@Override
|
||||
protected ClassMatch enhanceClass() {
|
||||
return NameMatch.byName(ENHANCE_CLASS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
|
||||
return new ConstructorInterceptPoint[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||
return new InstanceMethodsInterceptPoint[] {
|
||||
new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named("handle");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return INTERCEPT_CLASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOverrideArgs() {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
servicecomb-1.x=org.apache.skywalking.apm.plugin.servicecomb.v1.define.ProducerOperationHandlerInstrumentation
|
||||
servicecomb-1.x=org.apache.skywalking.apm.plugin.servicecomb.v1.define.TransportClientHandlerInstrumentation
|
||||
|
|
@ -1,133 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.apm.plugin.servicecomb.v1;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import javax.ws.rs.core.Response;
|
||||
import org.apache.servicecomb.core.Endpoint;
|
||||
import org.apache.servicecomb.core.Invocation;
|
||||
import org.apache.servicecomb.core.definition.OperationMeta;
|
||||
import org.apache.servicecomb.core.definition.SchemaMeta;
|
||||
import org.apache.servicecomb.swagger.invocation.InvocationType;
|
||||
import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
|
||||
import org.apache.skywalking.apm.agent.core.boot.ServiceManager;
|
||||
import org.apache.skywalking.apm.agent.core.conf.Config;
|
||||
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
|
||||
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
|
||||
import org.apache.skywalking.apm.agent.core.context.util.TagValuePair;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
import org.apache.skywalking.apm.agent.test.helper.SegmentHelper;
|
||||
import org.apache.skywalking.apm.agent.test.helper.SpanHelper;
|
||||
import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule;
|
||||
import org.apache.skywalking.apm.agent.test.tools.SegmentStorage;
|
||||
import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint;
|
||||
import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
|
||||
public class ProducerOperationHandlerInterceptorTest {
|
||||
|
||||
@Rule
|
||||
public AgentServiceRule agentServiceRule = new AgentServiceRule();
|
||||
@Mock
|
||||
Response.StatusType statusType;
|
||||
@SegmentStoragePoint
|
||||
private SegmentStorage segmentStorage;
|
||||
private ProducerOperationHandlerInterceptor invocationInterceptor;
|
||||
@Mock
|
||||
private OperationMeta operationMeta;
|
||||
@Mock
|
||||
private EnhancedInstance enhancedInstance;
|
||||
@Mock
|
||||
private Invocation invocation;
|
||||
@Mock
|
||||
private Endpoint endpoint;
|
||||
@Mock
|
||||
private Method method;
|
||||
@Mock
|
||||
private SwaggerInvocation swagger;
|
||||
private Object[] allArguments;
|
||||
private Class[] argumentsType;
|
||||
private Object[] swaggerArguments;
|
||||
|
||||
@Mock
|
||||
private SchemaMeta schemaMeta;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
ServiceManager.INSTANCE.boot();
|
||||
invocationInterceptor = new ProducerOperationHandlerInterceptor();
|
||||
PowerMockito.mock(Invocation.class);
|
||||
when(operationMeta.getSchemaMeta()).thenReturn(schemaMeta);
|
||||
when(endpoint.getAddress()).thenReturn("0.0.0.0:7777");
|
||||
when(invocation.getEndpoint()).thenReturn(endpoint);
|
||||
when(invocation.getMicroserviceQualifiedName()).thenReturn("productorTest");
|
||||
when(operationMeta.getOperationPath()).thenReturn("/bmi");
|
||||
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.SERVICE_NAME = "serviceComnTestCases-APP";
|
||||
|
||||
allArguments = new Object[] {invocation};
|
||||
argumentsType = new Class[] {};
|
||||
swaggerArguments = new Class[] {};
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConsumer() throws Throwable {
|
||||
|
||||
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);
|
||||
|
||||
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
|
||||
assertCombSpan(spans.get(0));
|
||||
verify(invocation, times(3)).getContext();
|
||||
}
|
||||
|
||||
private void assertCombSpan(AbstractTracingSpan span) {
|
||||
assertThat(span.getOperationName(), is("productorTest"));
|
||||
assertThat(SpanHelper.getComponentId(span), is(28));
|
||||
List<TagValuePair> tags = SpanHelper.getTags(span);
|
||||
assertThat(tags.get(0).getValue(), is("/bmi"));
|
||||
assertThat(span.isEntry(), is(true));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,128 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.apm.plugin.servicecomb.v1;
|
||||
|
||||
import java.util.List;
|
||||
import javax.ws.rs.core.Response;
|
||||
import org.apache.servicecomb.core.Endpoint;
|
||||
import org.apache.servicecomb.core.Invocation;
|
||||
import org.apache.servicecomb.core.definition.OperationMeta;
|
||||
import org.apache.servicecomb.core.definition.SchemaMeta;
|
||||
import org.apache.servicecomb.core.provider.consumer.ReferenceConfig;
|
||||
import org.apache.servicecomb.swagger.invocation.InvocationType;
|
||||
import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
|
||||
import org.apache.skywalking.apm.agent.core.boot.ServiceManager;
|
||||
import org.apache.skywalking.apm.agent.core.conf.Config;
|
||||
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
|
||||
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
|
||||
import org.apache.skywalking.apm.agent.core.context.util.TagValuePair;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
import org.apache.skywalking.apm.agent.test.helper.SegmentHelper;
|
||||
import org.apache.skywalking.apm.agent.test.helper.SpanHelper;
|
||||
import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule;
|
||||
import org.apache.skywalking.apm.agent.test.tools.SegmentStorage;
|
||||
import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint;
|
||||
import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
|
||||
public class TransportClientHandlerInterceptorTest {
|
||||
|
||||
@Rule
|
||||
public AgentServiceRule agentServiceRule = new AgentServiceRule();
|
||||
@Mock
|
||||
Response.StatusType statusType;
|
||||
@Mock
|
||||
ReferenceConfig referenceConfig;
|
||||
@SegmentStoragePoint
|
||||
private SegmentStorage segmentStorage;
|
||||
private TransportClientHandlerInterceptor nextInterceptor;
|
||||
@Mock
|
||||
private OperationMeta operationMeta;
|
||||
@Mock
|
||||
private EnhancedInstance enhancedInstance;
|
||||
@Mock
|
||||
private Invocation invocation;
|
||||
@Mock
|
||||
private Endpoint endpoint;
|
||||
@Mock
|
||||
private SwaggerInvocation swagger;
|
||||
private Object[] allArguments;
|
||||
private Class[] argumentsType;
|
||||
private Object[] swaggerArguments;
|
||||
|
||||
@Mock
|
||||
private SchemaMeta schemaMeta;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
ServiceManager.INSTANCE.boot();
|
||||
nextInterceptor = new TransportClientHandlerInterceptor();
|
||||
PowerMockito.mock(Invocation.class);
|
||||
when(operationMeta.getSchemaMeta()).thenReturn(schemaMeta);
|
||||
when(endpoint.toString()).thenReturn("/bmi");
|
||||
when(invocation.getEndpoint()).thenReturn(endpoint);
|
||||
when(invocation.getMicroserviceQualifiedName()).thenReturn("consumerTest");
|
||||
when(operationMeta.getOperationPath()).thenReturn("/bmi");
|
||||
when(invocation.getOperationMeta()).thenReturn(operationMeta);
|
||||
when(invocation.getStatus()).thenReturn(statusType);
|
||||
when(statusType.getStatusCode()).thenReturn(200);
|
||||
when(invocation.getInvocationType()).thenReturn(InvocationType.CONSUMER);
|
||||
Config.Agent.SERVICE_NAME = "serviceComnTestCases-APP";
|
||||
|
||||
allArguments = new Object[] {invocation};
|
||||
argumentsType = new Class[] {};
|
||||
swaggerArguments = new Class[] {};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConsumer() throws Throwable {
|
||||
nextInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentsType, null);
|
||||
nextInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentsType, null);
|
||||
Assert.assertThat(segmentStorage.getTraceSegments().size(), is(1));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
|
||||
assertCombSpan(spans.get(0));
|
||||
verify(invocation, times(3)).getContext();
|
||||
}
|
||||
|
||||
private void assertCombSpan(AbstractTracingSpan span) {
|
||||
assertThat(span.getOperationName(), is("consumerTest"));
|
||||
assertThat(SpanHelper.getComponentId(span), is(28));
|
||||
List<TagValuePair> tags = SpanHelper.getTags(span);
|
||||
assertThat(tags.get(0).getValue(), is("/bmi"));
|
||||
assertThat(span.isExit(), is(true));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -77,7 +77,6 @@
|
|||
- rocketMQ-3.x
|
||||
- rocketMQ-4.x
|
||||
- sentinel-1.x
|
||||
- servicecomb-1.x
|
||||
- servicecomb-2.x
|
||||
- sharding-sphere-3.x
|
||||
- sharding-sphere-4.0.0
|
||||
|
|
|
|||
Loading…
Reference in New Issue