Merge branch 'master' into feature/getAlarmTrend
This commit is contained in:
commit
cc0f6f5ee9
|
|
@ -32,7 +32,7 @@ public class ServerTypeDefine {
|
|||
private ServerType[] serverTypes;
|
||||
|
||||
private ServerTypeDefine() {
|
||||
this.serverTypes = new ServerType[28];
|
||||
this.serverTypes = new ServerType[29];
|
||||
this.serverTypeNames = new String[11];
|
||||
addServerType(new ServerType(ComponentsDefine.TOMCAT.getId(), Const.NONE, Const.EMPTY_STRING));
|
||||
addServerType(new ServerType(ComponentsDefine.HTTPCLIENT.getId(), Const.NONE, Const.EMPTY_STRING));
|
||||
|
|
@ -61,6 +61,7 @@ public class ServerTypeDefine {
|
|||
addServerType(new ServerType(ComponentsDefine.ROCKET_MQ.getId(), 9, ComponentsDefine.ROCKET_MQ.getName()));
|
||||
addServerType(new ServerType(ComponentsDefine.HTTP_ASYNC_CLIENT.getId(), Const.NONE, Const.EMPTY_STRING));
|
||||
addServerType(new ServerType(ComponentsDefine.KAFKA.getId(), 10, ComponentsDefine.KAFKA.getName()));
|
||||
addServerType(new ServerType(ComponentsDefine.SERVICECOMB.getId(), Const.NONE, ComponentsDefine.SERVICECOMB.getName()));
|
||||
}
|
||||
|
||||
public static ServerTypeDefine getInstance() {
|
||||
|
|
|
|||
|
|
@ -79,6 +79,8 @@ public class ComponentsDefine {
|
|||
public static final OfficialComponent HTTP_ASYNC_CLIENT = new OfficialComponent(26, "httpasyncclient");
|
||||
|
||||
public static final OfficialComponent KAFKA = new OfficialComponent(27, "Kafka");
|
||||
|
||||
public static final OfficialComponent SERVICECOMB = new OfficialComponent(28, "ServiceComb");
|
||||
|
||||
private static ComponentsDefine INSTANCE = new ComponentsDefine();
|
||||
|
||||
|
|
@ -89,7 +91,7 @@ public class ComponentsDefine {
|
|||
}
|
||||
|
||||
public ComponentsDefine() {
|
||||
components = new String[28];
|
||||
components = new String[29];
|
||||
addComponent(TOMCAT);
|
||||
addComponent(HTTPCLIENT);
|
||||
addComponent(DUBBO);
|
||||
|
|
@ -117,6 +119,7 @@ public class ComponentsDefine {
|
|||
addComponent(ROCKET_MQ);
|
||||
addComponent(HTTP_ASYNC_CLIENT);
|
||||
addComponent(KAFKA);
|
||||
addComponent(SERVICECOMB);
|
||||
}
|
||||
|
||||
private void addComponent(OfficialComponent component) {
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@
|
|||
<module>mongodb-2.x-plugin</module>
|
||||
<module>httpasyncclient-4.x-plugin</module>
|
||||
<module>kafka-v1-plugin</module>
|
||||
<module>servicecomb-plugin</module>
|
||||
</modules>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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>apm-sdk-plugin</artifactId>
|
||||
<groupId>org.apache.skywalking</groupId>
|
||||
<version>5.0.0-alpha</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>servicecomb-plugin</artifactId>
|
||||
|
||||
<modules>
|
||||
<module>servicecomb-java-chassis-0.x-plugin</module>
|
||||
</modules>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>apm-sdk-plugin</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<sdk.plugin.related.dir>/..</sdk.plugin.related.dir>
|
||||
</properties>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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>5.0.0-alpha</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>apm-servicecomb-java-chassis-0.x-plugin</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>servicecomb-java-chassis-0.x-plugin</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.servicecomb</groupId>
|
||||
<artifactId>java-chassis-core</artifactId>
|
||||
<version>0.5.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<!-- 源码插件 -->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<!-- 发布时自动将源码同时发布的配置 -->
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<phase>none</phase>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import io.servicecomb.core.Invocation;
|
||||
import java.lang.reflect.Method;
|
||||
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;
|
||||
|
||||
/**
|
||||
* {org.apache.skywalking.apm.plugin.servicecomb.ProducerOperationHandlerInterceptor} define how to enhance class {@link
|
||||
* ProducerOperationHandler#handle(io.servicecomb.core.Invocation, io.servicecomb.swagger.invocation.AsyncResponse)}.
|
||||
*
|
||||
* @author lytscu
|
||||
*/
|
||||
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.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) {
|
||||
AbstractSpan span = ContextManager.activeSpan();
|
||||
span.errorOccurred();
|
||||
span.log(t);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import io.servicecomb.core.Invocation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
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;
|
||||
|
||||
/**
|
||||
* {@link TransportClientHandlerInterceptor} define how to enhance class {@link TransportClientHandler#handle(io.servicecomb.core.Invocation,
|
||||
* io.servicecomb.swagger.invocation.AsyncResponse)}.
|
||||
*
|
||||
* @author lytscu
|
||||
*/
|
||||
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.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 (!checkRegisterStatus(invocation)) {
|
||||
return;
|
||||
}
|
||||
AbstractSpan span = ContextManager.activeSpan();
|
||||
span.errorOccurred();
|
||||
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) {
|
||||
if (null == invocation.getOperationMeta() || null == invocation.getEndpoint()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* 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.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
|
||||
* ProducerOperationHandler#handle(io.servicecomb.core.Invocation, io.servicecomb.swagger.invocation.AsyncResponse)}by
|
||||
* using {@link ProducerOperationHandlerInterceptor}
|
||||
*
|
||||
* @author lytscu
|
||||
*/
|
||||
public class ProducerOperationHandlerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
|
||||
private static final String ENHANCE_CLASS = "io.servicecomb.core.handler.impl.ProducerOperationHandler";
|
||||
|
||||
private static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.servicecomb.ProducerOperationHandlerInterceptor";
|
||||
|
||||
@Override
|
||||
protected ClassMatch enhanceClass() {
|
||||
return NameMatch.byName(ENHANCE_CLASS);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
|
||||
return new ConstructorInterceptPoint[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
protected 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;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* 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.define;
|
||||
|
||||
import io.servicecomb.core.handler.impl.TransportClientHandler;
|
||||
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 TransportClientHandler}by
|
||||
* using {@linkTransportClientHandlerInterceptor }
|
||||
*
|
||||
* @author lytscu
|
||||
*/
|
||||
public class TransportClientHandlerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
|
||||
private static final String ENHANCE_CLASS = "io.servicecomb.core.handler.impl.TransportClientHandler";
|
||||
|
||||
private static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.servicecomb.TransportClientHandlerInterceptor";
|
||||
|
||||
@Override
|
||||
protected ClassMatch enhanceClass() {
|
||||
return NameMatch.byName(ENHANCE_CLASS);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
|
||||
return new ConstructorInterceptPoint[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
protected 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;
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
servicecomb-0.x=org.apache.skywalking.apm.plugin.servicecomb.define.ProducerOperationHandlerInstrumentation
|
||||
servicecomb-0.x=org.apache.skywalking.apm.plugin.servicecomb.define.TransportClientHandlerInstrumentation
|
||||
|
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import io.servicecomb.core.Endpoint;
|
||||
import io.servicecomb.core.Invocation;
|
||||
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;
|
||||
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.KeyValuePair;
|
||||
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.APPLICATION_CODE = "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(1)).getContext();
|
||||
}
|
||||
|
||||
private void assertCombSpan(AbstractTracingSpan span) {
|
||||
assertThat(span.getOperationName(), is("productorTest"));
|
||||
assertThat(SpanHelper.getComponentId(span), is(28));
|
||||
List<KeyValuePair> tags = SpanHelper.getTags(span);
|
||||
assertThat(tags.get(0).getValue(), is("/bmi"));
|
||||
assertThat(span.isEntry(), is(true));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,128 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import io.servicecomb.core.Endpoint;
|
||||
import io.servicecomb.core.Invocation;
|
||||
import io.servicecomb.core.definition.OperationMeta;
|
||||
import io.servicecomb.core.definition.SchemaMeta;
|
||||
import io.servicecomb.core.provider.consumer.ReferenceConfig;
|
||||
import io.servicecomb.swagger.invocation.InvocationType;
|
||||
import io.servicecomb.swagger.invocation.SwaggerInvocation;
|
||||
import java.util.List;
|
||||
import javax.ws.rs.core.Response;
|
||||
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.KeyValuePair;
|
||||
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.getAddress()).thenReturn("0.0.0.0:7777");
|
||||
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.APPLICATION_CODE = "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(1)).getContext();
|
||||
}
|
||||
|
||||
private void assertCombSpan(AbstractTracingSpan span) {
|
||||
assertThat(span.getOperationName(), is("consumerTest"));
|
||||
assertThat(SpanHelper.getComponentId(span), is(28));
|
||||
List<KeyValuePair> tags = SpanHelper.getTags(span);
|
||||
assertThat(tags.get(0).getValue(), is("/bmi"));
|
||||
assertThat(span.isExit(), is(true));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -28,6 +28,7 @@
|
|||
* [Dubbox](https://github.com/dangdangdotcom/dubbox) 2.8.4
|
||||
* [Motan](https://github.com/weibocom/motan) 0.2.x -> 1.1.0
|
||||
* [gRPC](https://github.com/grpc/grpc-java) 1.x
|
||||
* [Apache ServiceComb Java Chassis](https://github.com/apache/incubator-servicecomb-java-chassis) 0.1 -> 0.5
|
||||
* MQ
|
||||
* [RocketMQ](https://github.com/apache/rocketmq) 4.x
|
||||
* [Kafka](http://kafka.apache.org) 0.11.0.0 -> 1.0
|
||||
|
|
|
|||
Loading…
Reference in New Issue