移除Tomcat插件测试代码,修复部分问题
This commit is contained in:
parent
19e64e0271
commit
0b0bc1cf95
|
|
@ -19,7 +19,7 @@
|
|||
<shade.package>com.a.eye.skywalking.api.dependencies</shade.package>
|
||||
<premain.class>com.a.eye.skywalking.agent.SkyWalkingAgent</premain.class>
|
||||
<shade.net.bytebuddy.source>net.bytebuddy</shade.net.bytebuddy.source>
|
||||
<shade.net.bytebuddy.target>${shade.package}.${shade.net.bytebuddy.source}}</shade.net.bytebuddy.target>
|
||||
<shade.net.bytebuddy.target>${shade.package}.${shade.net.bytebuddy.source}</shade.net.bytebuddy.target>
|
||||
<!-- disruptor -->
|
||||
<shade.com.lmax.disruptor.source>com.lmax.disruptor</shade.com.lmax.disruptor.source>
|
||||
<shade.com.lmax.disruptor.target>${shade.package}.${shade.com.lmax.disruptor.source}</shade.com.lmax.disruptor.target>
|
||||
|
|
|
|||
|
|
@ -25,13 +25,13 @@ import java.util.concurrent.locks.LockSupport;
|
|||
public class Agent2RoutingClient extends Thread {
|
||||
private static ILog logger = LogManager.getLogger(Agent2RoutingClient.class);
|
||||
|
||||
private List<ServerAddr> addrList;
|
||||
private Client client;
|
||||
private List<ServerAddr> addrList;
|
||||
private Client client;
|
||||
private SpanStorageClient spanStorageClient;
|
||||
private NetworkListener listener;
|
||||
private SendRequestSpanEventHandler requestSpanDataSupplier = null;
|
||||
private SendAckSpanEventHandler ackSpanDataSupplier = null;
|
||||
private volatile boolean connected = false;
|
||||
private NetworkListener listener;
|
||||
private SendRequestSpanEventHandler requestSpanDataSupplier = null;
|
||||
private SendAckSpanEventHandler ackSpanDataSupplier = null;
|
||||
private volatile boolean connected = false;
|
||||
|
||||
public static Agent2RoutingClient INSTANCE = new Agent2RoutingClient();
|
||||
|
||||
|
|
@ -80,7 +80,7 @@ public class Agent2RoutingClient extends Thread {
|
|||
public void run() {
|
||||
while (true) {
|
||||
try {
|
||||
while (connected && !client.isShutdown()) {
|
||||
while (requestSpanDataSupplier != null && ackSpanDataSupplier != null && connected && !client.isShutdown()) {
|
||||
List<RequestSpan> requestData = this.requestSpanDataSupplier.getBufferData();
|
||||
List<AckSpan> ackData = this.ackSpanDataSupplier.getBufferData();
|
||||
|
||||
|
|
@ -103,7 +103,7 @@ public class Agent2RoutingClient extends Thread {
|
|||
listener.wait2Confirm();
|
||||
}
|
||||
|
||||
if(!hasData) {
|
||||
if (!hasData) {
|
||||
try {
|
||||
Thread.sleep(10 * 1000L);
|
||||
} catch (InterruptedException e) {
|
||||
|
|
@ -150,13 +150,13 @@ public class Agent2RoutingClient extends Thread {
|
|||
HealthCollector.getCurrentHeathReading("Agent2RoutingClient").updateData(HeathReading.INFO, "batch send data to routing node.");
|
||||
}
|
||||
|
||||
void wait2Confirm(){
|
||||
void wait2Confirm() {
|
||||
// wait 20s, most.
|
||||
int countDown = 100 * 20;
|
||||
while (!listener.isBatchFinished()) {
|
||||
try {
|
||||
Thread.sleep(10L);
|
||||
if(countDown-- < 0){
|
||||
if (countDown-- < 0) {
|
||||
batchFinished = true;
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
|
|
@ -169,7 +169,7 @@ public class Agent2RoutingClient extends Thread {
|
|||
|
||||
|
||||
class ServerAddr {
|
||||
String ip;
|
||||
String ip;
|
||||
Integer port;
|
||||
|
||||
public ServerAddr(String ip, String port) {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import com.a.eye.skywalking.health.report.HeathReading;
|
|||
import com.a.eye.skywalking.logging.api.ILog;
|
||||
import com.a.eye.skywalking.logging.api.LogManager;
|
||||
import com.a.eye.skywalking.network.grpc.AckSpan;
|
||||
import com.a.eye.skywalking.network.grpc.RequestSpan;
|
||||
import com.lmax.disruptor.EventHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -16,10 +15,10 @@ import java.util.List;
|
|||
* Created by wusheng on 2016/11/24.
|
||||
*/
|
||||
public class SendAckSpanEventHandler implements EventHandler<AckSpanHolder> {
|
||||
private static ILog logger = LogManager.getLogger(SendAckSpanEventHandler.class);
|
||||
private int bufferSize = 100;
|
||||
private AckSpan[] buffer = new AckSpan[bufferSize];
|
||||
private int bufferIdx = 0;
|
||||
private static ILog logger = LogManager.getLogger(SendAckSpanEventHandler.class);
|
||||
private int bufferSize = 100;
|
||||
private AckSpan[] buffer = new AckSpan[bufferSize];
|
||||
private int bufferIdx = 0;
|
||||
|
||||
public SendAckSpanEventHandler() {
|
||||
Agent2RoutingClient.INSTANCE.setAckSpanDataSupplier(this);
|
||||
|
|
@ -27,7 +26,7 @@ public class SendAckSpanEventHandler implements EventHandler<AckSpanHolder> {
|
|||
|
||||
@Override
|
||||
public void onEvent(AckSpanHolder event, long sequence, boolean endOfBatch) throws Exception {
|
||||
if(buffer[bufferIdx] != null){
|
||||
if (buffer[bufferIdx] != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -43,11 +42,13 @@ public class SendAckSpanEventHandler implements EventHandler<AckSpanHolder> {
|
|||
}
|
||||
}
|
||||
|
||||
public List<AckSpan> getBufferData(){
|
||||
public List<AckSpan> getBufferData() {
|
||||
List<AckSpan> data = new ArrayList<AckSpan>(bufferSize);
|
||||
for (int i = 0; i < buffer.length; i++) {
|
||||
data.add(buffer[i]);
|
||||
buffer[i] = null;
|
||||
if (buffer[i] != null) {
|
||||
data.add(buffer[i]);
|
||||
buffer[i] = null;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,10 +15,10 @@ import java.util.List;
|
|||
* Created by wusheng on 2016/11/24.
|
||||
*/
|
||||
public class SendRequestSpanEventHandler implements EventHandler<RequestSpanHolder> {
|
||||
private static ILog logger = LogManager.getLogger(SendRequestSpanEventHandler.class);
|
||||
private static final int bufferSize = 100;
|
||||
private RequestSpan[] buffer = new RequestSpan[bufferSize];
|
||||
private int bufferIdx = 0;
|
||||
private static ILog logger = LogManager.getLogger(SendRequestSpanEventHandler.class);
|
||||
private static final int bufferSize = 100;
|
||||
private RequestSpan[] buffer = new RequestSpan[bufferSize];
|
||||
private int bufferIdx = 0;
|
||||
|
||||
public SendRequestSpanEventHandler() {
|
||||
Agent2RoutingClient.INSTANCE.setRequestSpanDataSupplier(this);
|
||||
|
|
@ -26,14 +26,14 @@ public class SendRequestSpanEventHandler implements EventHandler<RequestSpanHold
|
|||
|
||||
@Override
|
||||
public void onEvent(RequestSpanHolder event, long sequence, boolean endOfBatch) throws Exception {
|
||||
if(buffer[bufferIdx] != null){
|
||||
if (buffer[bufferIdx] != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
buffer[bufferIdx] = event.getData();
|
||||
bufferIdx++;
|
||||
|
||||
if(bufferIdx == buffer.length){
|
||||
if (bufferIdx == buffer.length) {
|
||||
bufferIdx = 0;
|
||||
}
|
||||
|
||||
|
|
@ -42,11 +42,13 @@ public class SendRequestSpanEventHandler implements EventHandler<RequestSpanHold
|
|||
}
|
||||
}
|
||||
|
||||
public List<RequestSpan> getBufferData(){
|
||||
public List<RequestSpan> getBufferData() {
|
||||
List<RequestSpan> data = new ArrayList<RequestSpan>(bufferSize);
|
||||
for (int i = 0; i < buffer.length; i++) {
|
||||
data.add(buffer[i]);
|
||||
buffer[i] = null;
|
||||
if (buffer[i] != null) {
|
||||
data.add(buffer[i]);
|
||||
buffer[i] = null;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,19 +43,21 @@ public abstract class BaseInvokeMonitor {
|
|||
return new ContextData(spanData);
|
||||
}
|
||||
|
||||
protected void sendRequestSpan(Span span, Identification id){
|
||||
protected void sendRequestSpan(Span span, Identification id) {
|
||||
RequestSpan.Builder requestSpanBuilder = span.buildRequestSpan(RequestSpan.newBuilder());
|
||||
if (id.getBusinessKey() != null && id.getBusinessKey().length() > 0) {
|
||||
requestSpanBuilder = requestSpanBuilder.setBusinessKey(id.getBusinessKey());
|
||||
}
|
||||
RequestSpan requestSpan = requestSpanBuilder
|
||||
.setViewPointId(id.getViewPoint())
|
||||
.setSpanTypeDesc(id.getSpanTypeDesc())
|
||||
.setBusinessKey(id.getBusinessKey())
|
||||
.setCallType(id.getCallType()).setProcessNo(BuriedPointMachineUtil.getProcessNo())
|
||||
.setAddress(BuriedPointMachineUtil.getHostDesc()).build();
|
||||
|
||||
RequestSpanDisruptor.INSTANCE.ready2Send(requestSpan);
|
||||
}
|
||||
|
||||
protected void sendAckSpan(Span span){
|
||||
protected void sendAckSpan(Span span) {
|
||||
AckSpan ackSpan = span.buildAckSpan(AckSpan.newBuilder()).build();
|
||||
|
||||
AckSpanDisruptor.INSTANCE.ready2Send(ackSpan);
|
||||
|
|
|
|||
|
|
@ -1,39 +0,0 @@
|
|||
package test.com.ai.skywalking.plugin.tomcat78x;
|
||||
|
||||
import org.apache.catalina.LifecycleException;
|
||||
import org.apache.catalina.WebResourceRoot;
|
||||
import org.apache.catalina.core.StandardContext;
|
||||
import org.apache.catalina.startup.Tomcat;
|
||||
import org.apache.catalina.webresources.DirResourceSet;
|
||||
import org.apache.catalina.webresources.StandardRoot;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import java.io.File;
|
||||
|
||||
public class EmbedTomcat {
|
||||
|
||||
@Test
|
||||
public void testGetResourcePath(){
|
||||
System.out.println(EmbedTomcat.class.getResource("/").getPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartTomcat() throws ServletException, LifecycleException {
|
||||
start();
|
||||
}
|
||||
|
||||
public static void start() throws ServletException, LifecycleException {
|
||||
String webappDirLocation = EmbedTomcat.class.getResource("/").getPath() + "webapp/";
|
||||
Tomcat tomcat = new Tomcat();
|
||||
tomcat.setPort(8080);
|
||||
|
||||
StandardContext standardContext = (StandardContext) tomcat.addWebapp("/",new File(webappDirLocation).getAbsolutePath());
|
||||
File additionWebInfClasses = new File(EmbedTomcat.class.getResource("/").getPath());
|
||||
WebResourceRoot resourceRoot = new StandardRoot(standardContext);
|
||||
resourceRoot.addPreResources(new DirResourceSet(resourceRoot,"/WEB-INF/classes", additionWebInfClasses.getAbsolutePath(), "/"));
|
||||
standardContext.setResources(resourceRoot);
|
||||
|
||||
tomcat.start();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
package test.com.ai.skywalking.plugin.tomcat78x;
|
||||
|
||||
import com.a.eye.skywalking.plugin.PluginException;
|
||||
import com.a.eye.skywalking.plugin.TracingBootstrap;
|
||||
import com.a.eye.skywalking.testframework.api.RequestSpanAssert;
|
||||
import org.apache.catalina.LifecycleException;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.ResponseHandler;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class TomcatPluginTest {
|
||||
|
||||
@Test
|
||||
public void test() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, PluginException {
|
||||
TracingBootstrap.main(new String[] {TomcatPluginTest.class.getName()});
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws ServletException, LifecycleException, IOException, InterruptedException {
|
||||
// start tomcat
|
||||
EmbedTomcat.start();
|
||||
// curl httpclient
|
||||
visitURL("http://127.0.0.1:8080/hello");
|
||||
// assert client
|
||||
RequestSpanAssert.assertEquals(new String[][] {{"0", "http://127.0.0.1:8080/hello", ""}});
|
||||
}
|
||||
|
||||
public static void visitURL(String url) throws IOException {
|
||||
CloseableHttpClient httpclient = HttpClients.createDefault();
|
||||
try {
|
||||
HttpGet httpget = new HttpGet(url);
|
||||
ResponseHandler<String> responseHandler = new ResponseHandler<String>() {
|
||||
@Override
|
||||
public String handleResponse(final HttpResponse response) throws ClientProtocolException, IOException {
|
||||
int status = response.getStatusLine().getStatusCode();
|
||||
if (status >= 200 && status < 300) {
|
||||
HttpEntity entity = response.getEntity();
|
||||
return entity != null ? EntityUtils.toString(entity) : null;
|
||||
} else {
|
||||
throw new ClientProtocolException("Unexpected response status: " + status);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
String responseBody = httpclient.execute(httpget, responseHandler);
|
||||
} finally {
|
||||
httpclient.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
package test.com.ai.skywalking.plugin.tomcat78x.servlet;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by xin on 16/7/22.
|
||||
*/
|
||||
@WebServlet(
|
||||
name="myServlet",
|
||||
urlPatterns = {"/hello"}
|
||||
)
|
||||
public class HelloServlet extends HttpServlet{
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
System.out.println("Hello World");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
#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
|
||||
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
<html>
|
||||
<body>
|
||||
<h2>Hello World</h2>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Reference in New Issue