提交 ac491464 编写于 作者: A ascrutae

1.支持Motan框架

2.修复服务端启动脚本
上级 24dbf997
<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>skywalking-sdk-plugin</artifactId>
<groupId>com.a.eye</groupId>
<version>2.0-2016</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>motan-plugin</artifactId>
<packaging>jar</packaging>
<name>motan-plugin</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- Motan -->
<dependency>
<groupId>com.weibo</groupId>
<artifactId>motan-core</artifactId>
<version>0.2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.weibo</groupId>
<artifactId>motan-transport-netty</artifactId>
<version>0.2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.weibo</groupId>
<artifactId>motan-springsupport</artifactId>
<version>0.2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.4.RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
package com.a.eye.skywalking.plugin.motan;
import com.a.eye.skywalking.model.Identification;
import com.weibo.api.motan.rpc.Request;
import com.weibo.api.motan.rpc.URL;
import java.util.Map;
public class IdentificationUtil {
/**
* for example:
* <p>
* <strong>service URL</strong> : motan://172.18.80.208:0/org.a.eye.skywalking.motan
* .FooService?group=default_rpc
* <strong>execute method</strong> : helloWorld
* <strong>execute parameter</strong>: java.lang.String,java.lang.String
* <p>
* <p>
* <strong>view point</strong>: motan://172.18.80.208:0/org.a.eye.skywalking.motan.FooService.helloWorld
* (java.lang.String,java.lang.String)?group=default_rpc
*
* @param serviceURI such as: motan://172.18.80.208:0/org.a.eye.skywalking.motan.FooService?group=default_rpc
* @param request
* @return such as: motan://172.18.80.208:0/org.a.eye.skywalking.motan.FooService.helloWorld
* (java.lang.String,java.lang.String)?group=default_rpc
*/
private static String generateViewPoint(URL serviceURI, Request request) {
StringBuilder viewPoint = new StringBuilder(serviceURI.getUri());
viewPoint.append("." + request.getMethodName());
viewPoint.append("(" + request.getParamtersDesc() + ")?group=" + serviceURI.getGroup());
return viewPoint.toString();
}
/**
* @param request
* @param serviceURI such as: motan://172.18.80.208:0/org.a.eye.skywalking.motan.FooService?group=default_rpc
* @return
*/
public static Identification generateIdentify(Request request, URL serviceURI) {
return Identification.newBuilder().viewPoint(generateViewPoint(serviceURI, request))
.spanType(MotanBuriedPointType.instance()).build();
}
}
package com.a.eye.skywalking.plugin.motan;
import com.a.eye.skywalking.api.IBuriedPointType;
import com.a.eye.skywalking.protocol.common.CallType;
public class MotanBuriedPointType implements IBuriedPointType {
private static MotanBuriedPointType motanBuriedPointType;
public static IBuriedPointType instance() {
if (motanBuriedPointType == null) {
motanBuriedPointType = new MotanBuriedPointType();
}
return motanBuriedPointType;
}
@Override
public String getTypeName() {
return "M";
}
@Override
public CallType getCallType() {
return CallType.SYNC;
}
private MotanBuriedPointType() {
//Non
}
}
package com.a.eye.skywalking.plugin.motan;
import com.a.eye.skywalking.invoke.monitor.RPCClientInvokeMonitor;
import com.a.eye.skywalking.model.ContextData;
import com.a.eye.skywalking.plugin.interceptor.EnhancedClassInstanceContext;
import com.a.eye.skywalking.plugin.interceptor.enhance.ConstructorInvokeContext;
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext;
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
import com.a.eye.skywalking.plugin.interceptor.enhance.MethodInterceptResult;
import com.weibo.api.motan.rpc.Request;
import com.weibo.api.motan.rpc.URL;
import static com.a.eye.skywalking.plugin.motan.IdentificationUtil.generateIdentify;
/**
* Motan client interceptor
*/
public class MotanClientInterceptor implements InstanceMethodsAroundInterceptor {
@Override
public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) {
context.set("serviceURI", interceptorContext.allArguments()[1]);
}
@Override
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext,
MethodInterceptResult result) {
Request request = (Request) interceptorContext.allArguments()[0];
if (request != null) {
ContextData contextData = new RPCClientInvokeMonitor()
.beforeInvoke(generateIdentify(request, (URL) context.get("serviceURI")));
String contextDataStr = contextData.toString();
request.setAttachment("contextData", contextDataStr);
}
}
@Override
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext,
Object ret) {
new RPCClientInvokeMonitor().afterInvoke();
return ret;
}
@Override
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context,
InstanceMethodInvokeContext interceptorContext) {
new RPCClientInvokeMonitor().occurException(t);
}
}
package com.a.eye.skywalking.plugin.motan;
import com.a.eye.skywalking.invoke.monitor.RPCServerInvokeMonitor;
import com.a.eye.skywalking.model.ContextData;
import com.a.eye.skywalking.plugin.interceptor.EnhancedClassInstanceContext;
import com.a.eye.skywalking.plugin.interceptor.enhance.ConstructorInvokeContext;
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext;
import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
import com.a.eye.skywalking.plugin.interceptor.enhance.MethodInterceptResult;
import com.weibo.api.motan.rpc.Request;
import com.weibo.api.motan.rpc.URL;
public class MotanServerInterceptor implements InstanceMethodsAroundInterceptor {
@Override
public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) {
context.set("serviceURI", interceptorContext.allArguments()[0]);
}
@Override
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext,
MethodInterceptResult result) {
Request request = (Request) interceptorContext.allArguments()[0];
if (request != null) {
new RPCServerInvokeMonitor().beforeInvoke(new ContextData(request.getAttachments().get("contextData")),
IdentificationUtil.generateIdentify(request, (URL) context.get("serviceURI")));
}
}
@Override
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext,
Object ret) {
new RPCServerInvokeMonitor().afterInvoke();
return ret;
}
@Override
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context,
InstanceMethodInvokeContext interceptorContext) {
new RPCServerInvokeMonitor().occurException(t);
}
}
package com.a.eye.skywalking.plugin.motan.define;
import com.a.eye.skywalking.plugin.interceptor.MethodMatcher;
import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import com.a.eye.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher;
public class MotanClientDefine extends ClassInstanceMethodsEnhancePluginDefine {
@Override
protected String enhanceClassName() {
return "com.weibo.api.motan.rpc.AbstractReferer";
}
@Override
protected MethodMatcher[] getInstanceMethodsMatchers() {
return new MethodMatcher[] {new SimpleMethodMatcher("call")};
}
@Override
protected String getInstanceMethodsInterceptor() {
return "com.a.eye.skywalking.plugin.motan.MotanClientInterceptor";
}
}
package com.a.eye.skywalking.plugin.motan.define;
import com.a.eye.skywalking.plugin.interceptor.MethodMatcher;
import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import com.a.eye.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher;
public class MotanServerDefine extends ClassInstanceMethodsEnhancePluginDefine {
@Override
protected String enhanceClassName() {
return "com.weibo.api.motan.rpc.AbstractProvider";
}
@Override
protected MethodMatcher[] getInstanceMethodsMatchers() {
return new MethodMatcher[] {new SimpleMethodMatcher("call")};
}
@Override
protected String getInstanceMethodsInterceptor() {
return "com.a.eye.skywalking.plugin.motan.MotanServerInterceptor";
}
}
com.a.eye.skywalking.plugin.motan.define.MotanClientDefine
com.a.eye.skywalking.plugin.motan.define.MotanServerDefine
package com.a.eye.skywalking.plugin.motan;
import com.a.eye.skywalking.plugin.PluginException;
import com.a.eye.skywalking.plugin.TracingBootstrap;
import com.a.eye.skywalking.testframework.api.RequestSpanAssert;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.lang.reflect.InvocationTargetException;
/**
* Created by xin on 16/9/27.
*/
public class Client {
@Test
public void test()
throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException,
PluginException {
TracingBootstrap.main(new String[] {Client.class.getName()});
}
public static void main(String[] args) throws InterruptedException {
ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:motan_client.xml");
FooService service = (FooService) ctx.getBean("remoteService");
System.out.println(service.hello("motan", "1"));
RequestSpanAssert
.assertEquals(new String[][] {{"0", "motan://localhost:8002/com.a.eye.skywalking.plugin.motan.FooService.hello(java.lang.String,java.lang.String)?group=default_rpc", ""}});
}
}
package com.a.eye.skywalking.plugin.motan;
public interface FooService {
public String hello(String name, String value);
}
package com.a.eye.skywalking.plugin.motan;
/**
* Created by xin on 16/9/27.
*/
public class FooServiceImpl implements FooService {
public String hello(String name, String value) {
System.out.println(name + " invoked rpc service");
return "hello " + name + " " + value;
}
}
package com.a.eye.skywalking.plugin.motan;
import com.a.eye.skywalking.plugin.PluginException;
import com.a.eye.skywalking.plugin.TracingBootstrap;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.lang.reflect.InvocationTargetException;
public class Server {
@Test
public void test()
throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException,
PluginException {
TracingBootstrap.main(new String[] {Server.class.getName()});
}
public static void main(String[] args) throws InterruptedException {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:motan_server.xml");
System.out.println("server start...");
while (true) {
Thread.sleep(100000L);
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:motan="http://api.weibo.com/schema/motan"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://api.weibo.com/schema/motan http://api.weibo.com/schema/motan.xsd">
<!-- reference to the remote service -->
<motan:referer id="remoteService" interface="com.a.eye.skywalking.plugin.motan.FooService"
directUrl="localhost:8002"/>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:motan="http://api.weibo.com/schema/motan"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://api.weibo.com/schema/motan http://api.weibo.com/schema/motan.xsd">
<!-- service implemention bean -->
<bean id="serviceImpl" class="com.a.eye.skywalking.plugin.motan.FooServiceImpl"/>
<!-- exporting service by motan -->
<motan:service interface="com.a.eye.skywalking.plugin.motan.FooService" ref="serviceImpl" export="8002"/>
</beans>
#skyWalking用户ID
skywalking.user_id=123
#skyWalking应用编码
skywalking.application_code=test
#skywalking auth的环境变量名字
skywalking.auth_system_env_name=SKYWALKING_RUN
#skywalking数据编码
skywalking.charset=UTF-8
skywalking.auth_override=true
#是否打印数据
buriedpoint.printf=true
#埋点异常的最大长度
buriedpoint.max_exception_stack_length=4000
#业务字段的最大长度
buriedpoint.businesskey_max_length=300
#过滤异常
buriedpoint.exclusive_exceptions=java.lang.RuntimeException
#最大发送者的连接数阀比例
sender.connect_percent=100
#发送服务端配置
sender.servers_addr=127.0.0.1:34000
#最大发送的副本数量
sender.max_copy_num=2
#发送的最大长度
sender.max_send_length=20000
#当没有Sender时,尝试获取sender的等待周期
sender.retry_get_sender_wait_interval=2000
#最大消费线程数
consumer.max_consumer=0
#消费者最大等待时间
consumer.max_wait_time=5
#发送失败等待时间
consumer.consumer_fail_retry_wait_interval=50
#每个Buffer的最大个数
buffer.buffer_max_size=18000
#Buffer池的最大长度
buffer.pool_size=5
#发送检查线程检查周期
senderchecker.check_polling_time=200
......@@ -17,7 +17,8 @@
<module>jedis-2.x-plugin</module>
<module>tomcat-7.x-8.x-plugin</module>
<module>custom-local-method-interceptor-plugin</module>
</modules>
<module>motan-plugin</module>
</modules>
<packaging>pom</packaging>
<name>skywalking-sdk-plugin</name>
......
......@@ -48,4 +48,5 @@ echo "CLASSPATH=$CLASSPATH"
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
$JAVA ${JAVA_OPTS} -classpath $CLASSPATH com.ai.cloud.skywalking.reciever.CollectionServer >> ${SW_SERVER_BIN_DIR}/../log/sw-server.log & 2>&1&
$JAVA ${JAVA_OPTS} -classpath $CLASSPATH com.a.eye.skywalking.reciever.CollectionServer >> ${SW_SERVER_BIN_DIR}/.
./log/sw-server.log & 2>&1&
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册