修复部分问题
This commit is contained in:
parent
503e8a7f63
commit
6c4213a970
|
|
@ -3,6 +3,7 @@ package com.a.eye.skywalking.storage.alarm;
|
|||
import com.a.eye.skywalking.network.grpc.AckSpan;
|
||||
import com.a.eye.skywalking.storage.alarm.checker.*;
|
||||
import com.a.eye.skywalking.storage.alarm.sender.AlarmMessageSenderFactory;
|
||||
import com.a.eye.skywalking.storage.data.spandata.AckSpanData;
|
||||
import com.lmax.disruptor.EventHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -11,7 +12,7 @@ import java.util.List;
|
|||
/**
|
||||
* Created by xin on 2016/12/8.
|
||||
*/
|
||||
public class SpanAlarmHandler implements EventHandler<AckSpan> {
|
||||
public class SpanAlarmHandler implements EventHandler<AckSpanData> {
|
||||
private List<ISpanChecker> spanCheckers = new ArrayList<ISpanChecker>();
|
||||
|
||||
public SpanAlarmHandler() {
|
||||
|
|
@ -20,17 +21,17 @@ public class SpanAlarmHandler implements EventHandler<AckSpan> {
|
|||
spanCheckers.add(new ExecuteTimePossibleErrorChecker());
|
||||
}
|
||||
|
||||
private String generateAlarmMessageKey(AckSpanData span, FatalReason reason) {
|
||||
return span.getUserName() + "-" + span.getApplicationCode() + "-" + (System.currentTimeMillis() / (10000 * 6)) + "-" + reason;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(AckSpan span, long sequence, boolean endOfBatch) throws Exception {
|
||||
public void onEvent(AckSpanData spanData, long sequence, boolean endOfBatch) throws Exception {
|
||||
for (ISpanChecker spanChecker : spanCheckers) {
|
||||
CheckResult result = spanChecker.check(span);
|
||||
CheckResult result = spanChecker.check(spanData);
|
||||
if (!result.isPassed()) {
|
||||
AlarmMessageSenderFactory.getSender().send(generateAlarmMessageKey(span, result.getFatalReason()), result.getMessage());
|
||||
AlarmMessageSenderFactory.getSender().send(generateAlarmMessageKey(spanData, result.getFatalReason()), result.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String generateAlarmMessageKey(AckSpan span, FatalReason reason) {
|
||||
return span.getUsername() + "-" + span.getApplicationCode() + "-" + (System.currentTimeMillis() / (10000 * 6)) + "-" + reason;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
package com.a.eye.skywalking.storage.alarm.checker;
|
||||
|
||||
import com.a.eye.skywalking.network.grpc.AckSpan;
|
||||
import com.a.eye.skywalking.storage.config.Config;
|
||||
import com.a.eye.skywalking.storage.data.spandata.AckSpanData;
|
||||
|
||||
public class ExceptionChecker implements ISpanChecker {
|
||||
|
||||
@Override
|
||||
public CheckResult check(AckSpan span) {
|
||||
public CheckResult check(AckSpanData span) {
|
||||
if (span.getStatusCode() != 1)
|
||||
return new CheckResult();
|
||||
String exceptionStack = span.getExceptionStack();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.a.eye.skywalking.storage.alarm.checker;
|
||||
|
||||
import com.a.eye.skywalking.network.grpc.AckSpan;
|
||||
import com.a.eye.skywalking.storage.data.spandata.AckSpanData;
|
||||
|
||||
/**
|
||||
* Created by xin on 2016/12/8.
|
||||
|
|
@ -8,7 +9,7 @@ import com.a.eye.skywalking.network.grpc.AckSpan;
|
|||
public abstract class ExecuteTimeChecker implements ISpanChecker {
|
||||
|
||||
@Override
|
||||
public CheckResult check(AckSpan span) {
|
||||
public CheckResult check(AckSpanData span) {
|
||||
long cost = span.getCost();
|
||||
if (isOverThreshold(cost)) {
|
||||
return new CheckResult(getFatalLevel(), generateAlarmMessage(span));
|
||||
|
|
@ -21,8 +22,8 @@ public abstract class ExecuteTimeChecker implements ISpanChecker {
|
|||
|
||||
protected abstract FatalReason getFatalLevel();
|
||||
|
||||
protected String generateAlarmMessage(AckSpan span) {
|
||||
return span.getViewpointId() + " cost " + span.getCost() + " ms.";
|
||||
protected String generateAlarmMessage(AckSpanData span) {
|
||||
return span.getViewPointId() + " cost " + span.getCost() + " ms.";
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
package com.a.eye.skywalking.storage.alarm.checker;
|
||||
|
||||
import com.a.eye.skywalking.network.grpc.AckSpan;
|
||||
import com.a.eye.skywalking.storage.data.spandata.AckSpanData;
|
||||
|
||||
/**
|
||||
* Created by xin on 2016/12/8.
|
||||
*/
|
||||
public interface ISpanChecker {
|
||||
CheckResult check(AckSpan span);
|
||||
CheckResult check(AckSpanData span);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ public class Config {
|
|||
public static int PORT = 34000;
|
||||
}
|
||||
|
||||
public static class Disruptor{
|
||||
public static class Disruptor {
|
||||
public static int BUFFER_SIZE = 1024 * 128;
|
||||
|
||||
public static int FLUSH_SIZE = 100;
|
||||
|
|
@ -43,4 +43,7 @@ public class Config {
|
|||
public static String PATH_PREFIX = "/skywalking/storage_list/";
|
||||
}
|
||||
|
||||
public static class Alarm {
|
||||
public static int ALARM_EXCEPTION_STACK_LENGTH = 300;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,4 +56,16 @@ public class AckSpanData extends AbstractSpanData {
|
|||
public int getStatusCode() {
|
||||
return ackSpan.getStatusCode();
|
||||
}
|
||||
|
||||
public String getViewPointId(){
|
||||
return ackSpan.getViewpointId();
|
||||
}
|
||||
|
||||
public String getUserName(){
|
||||
return ackSpan.getUsername();
|
||||
}
|
||||
|
||||
public String getApplicationCode(){
|
||||
return ackSpan.getApplicationCode();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ 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.a.eye.skywalking.network.listener.server.SpanStorageServerListener;
|
||||
import com.a.eye.skywalking.storage.alarm.SpanAlarmHandler;
|
||||
import com.a.eye.skywalking.storage.config.Config;
|
||||
import com.a.eye.skywalking.storage.data.spandata.AckSpanData;
|
||||
import com.a.eye.skywalking.storage.data.spandata.RequestSpanData;
|
||||
|
|
@ -35,7 +36,7 @@ public class StorageListener implements SpanStorageServerListener {
|
|||
requestSpanRingBuffer = requestSpanDisruptor.getRingBuffer();
|
||||
|
||||
ackSpanDisruptor = new Disruptor<AckSpanData>(new AckSpanFactory(), Config.Disruptor.BUFFER_SIZE, DaemonThreadFactory.INSTANCE);
|
||||
ackSpanDisruptor.handleEventsWith(new StoreAckSpanEventHandler());
|
||||
ackSpanDisruptor.handleEventsWith(new StoreAckSpanEventHandler(), new SpanAlarmHandler());
|
||||
ackSpanDisruptor.start();
|
||||
ackSpanRingBuffer = ackSpanDisruptor.getRingBuffer();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,44 @@
|
|||
package com.a.eye.skywalking.storage;
|
||||
|
||||
import com.a.eye.skywalking.health.report.HealthCollector;
|
||||
import com.a.eye.skywalking.health.report.HeathReading;
|
||||
import com.a.eye.skywalking.storage.config.Config;
|
||||
import com.a.eye.skywalking.storage.data.spandata.RequestSpanData;
|
||||
import com.lmax.disruptor.EventHandler;
|
||||
import com.lmax.disruptor.RingBuffer;
|
||||
import com.lmax.disruptor.dsl.Disruptor;
|
||||
import com.lmax.disruptor.util.DaemonThreadFactory;
|
||||
|
||||
/**
|
||||
* Created by xin on 2016/12/7.
|
||||
*/
|
||||
public class TestMain {
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
Disruptor<StringBuilder> requestSpanDataDisruptor = null;
|
||||
requestSpanDataDisruptor = new Disruptor<StringBuilder>(new StringBuilderFactory(), Config.Disruptor.BUFFER_SIZE, DaemonThreadFactory.INSTANCE);
|
||||
requestSpanDataDisruptor.handleEventsWith(new EventHandler<StringBuilder>() {
|
||||
@Override
|
||||
public void onEvent(StringBuilder event, long sequence, boolean endOfBatch) throws Exception {
|
||||
System.out.println("AA: " + event);
|
||||
}
|
||||
}, new EventHandler<StringBuilder>() {
|
||||
@Override
|
||||
public void onEvent(StringBuilder event, long sequence, boolean endOfBatch) throws Exception {
|
||||
System.out.println("BB: " + event);
|
||||
}
|
||||
});
|
||||
requestSpanDataDisruptor.start();
|
||||
RingBuffer<StringBuilder> stringBuilderRingBuffer = requestSpanDataDisruptor.getRingBuffer();
|
||||
|
||||
long sequence = stringBuilderRingBuffer.next(); // Grab the next sequence
|
||||
try {
|
||||
StringBuilder data = stringBuilderRingBuffer.get(sequence);
|
||||
data.append("A");
|
||||
} catch (Exception e) {
|
||||
} finally {
|
||||
stringBuilderRingBuffer.publish(sequence);
|
||||
}
|
||||
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ import com.a.eye.skywalking.network.grpc.AckSpan;
|
|||
import com.a.eye.skywalking.network.grpc.TraceId;
|
||||
import com.a.eye.skywalking.storage.alarm.sender.AlarmMessageSender;
|
||||
import com.a.eye.skywalking.storage.alarm.sender.AlarmMessageSenderFactory;
|
||||
import com.a.eye.skywalking.storage.data.spandata.AckSpanData;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
|
@ -24,10 +25,10 @@ public class SpanAlarmHandlerTest {
|
|||
private AlarmMessageSender messageHandler;
|
||||
@InjectMocks
|
||||
private SpanAlarmHandler handler;
|
||||
private AckSpan normalAckSpan;
|
||||
private AckSpan costMuchSpan;
|
||||
private AckSpan costTooMuchSpan;
|
||||
private AckSpan exceptionSpan;
|
||||
private AckSpanData normalAckSpan;
|
||||
private AckSpanData costMuchSpan;
|
||||
private AckSpanData costTooMuchSpan;
|
||||
private AckSpanData exceptionSpan;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
|
@ -39,10 +40,10 @@ public class SpanAlarmHandlerTest {
|
|||
.addSegments(2016).addSegments(startTime).addSegments(2).addSegments(100).addSegments(30)
|
||||
.addSegments(1).build());
|
||||
|
||||
normalAckSpan = builder.build();
|
||||
costMuchSpan = builder.setCost(600).build();
|
||||
costTooMuchSpan = builder.setCost(4000).build();
|
||||
exceptionSpan = builder.setCost(20).setStatusCode(1).setExceptionStack("occur exception").build();
|
||||
normalAckSpan = new AckSpanData(builder.build());
|
||||
costMuchSpan = new AckSpanData(builder.setCost(600).build());
|
||||
costTooMuchSpan = new AckSpanData(builder.setCost(4000).build());
|
||||
exceptionSpan = new AckSpanData(builder.setCost(20).setStatusCode(1).setExceptionStack("occur exception").build());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -65,7 +66,7 @@ public class SpanAlarmHandlerTest {
|
|||
|
||||
@Test
|
||||
public void testCostTooMuchSpan() throws Exception {
|
||||
handler.onEvent(costTooMuchSpan,1, false);
|
||||
handler.onEvent(costTooMuchSpan, 1, false);
|
||||
verify(messageHandler, times(1)).send(any(), anyString());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue