Merge remote-tracking branch 'upstream/feature/3.0' into feature/3.0
This commit is contained in:
commit
696090b092
|
|
@ -13,7 +13,6 @@
|
|||
<modules>
|
||||
<module>skywalking-trace</module>
|
||||
<module>skywalking-logging</module>
|
||||
<module>skywalking-health-report</module>
|
||||
<module>skywalking-util</module>
|
||||
</modules>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
<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-commons</artifactId>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<version>3.0-2017</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>skywalking-health-report</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>skywalking-health-report</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>skywalking-logging-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -1,79 +0,0 @@
|
|||
package com.a.eye.skywalking.health.report;
|
||||
|
||||
|
||||
import com.a.eye.skywalking.api.logging.api.ILog;
|
||||
import com.a.eye.skywalking.api.logging.api.LogManager;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class HealthCollector extends Thread {
|
||||
private static ILog logger = LogManager.getLogger(HealthCollector.class);
|
||||
private static Map<String, HeathReading> heathReadings = new ConcurrentHashMap<String, HeathReading>();
|
||||
private static final long DEFAULT_REPORT_INTERVAL = 60 * 1000;
|
||||
private final long reportInterval;
|
||||
private String reporterName;
|
||||
|
||||
private HealthCollector(String reporterName) {
|
||||
this(DEFAULT_REPORT_INTERVAL);
|
||||
this.reporterName = reporterName;
|
||||
}
|
||||
|
||||
private HealthCollector(long reportInterval) {
|
||||
super("HealthCollector");
|
||||
this.setDaemon(true);
|
||||
this.reportInterval = reportInterval;
|
||||
}
|
||||
|
||||
public static void init(String reporterName) {
|
||||
new HealthCollector(reporterName).start();
|
||||
}
|
||||
|
||||
public static HeathReading getCurrentHeathReading(String extraId) {
|
||||
String id = getId(extraId);
|
||||
if (!heathReadings.containsKey(id)) {
|
||||
synchronized (heathReadings) {
|
||||
if (!heathReadings.containsKey(id)) {
|
||||
if (heathReadings.keySet().size() > 5000) {
|
||||
logger.warn("use HealthCollector illegal. There is an overflow trend of Server Health Collector Report Data.");
|
||||
}else {
|
||||
heathReadings.put(id, new HeathReading(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return heathReadings.get(id);
|
||||
}
|
||||
|
||||
private static String getId(String extraId) {
|
||||
return "T:" + Thread.currentThread().getName() + "(" + Thread.currentThread().getId() + ")" + (extraId == null ? "" : ",extra:" + extraId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
try {
|
||||
Map<String, HeathReading> heathReadingsSnapshot = heathReadings;
|
||||
heathReadings = new ConcurrentHashMap<String, HeathReading>();
|
||||
String[] keyList = heathReadingsSnapshot.keySet().toArray(new String[0]);
|
||||
Arrays.sort(keyList);
|
||||
StringBuilder log = new StringBuilder();
|
||||
log.append("\n---------" + reporterName + " Health Report---------\n");
|
||||
for (String key : keyList) {
|
||||
log.append(heathReadingsSnapshot.get(key)).append("\n");
|
||||
}
|
||||
log.append("------------------------------------------------\n");
|
||||
|
||||
logger.info(log.toString());
|
||||
|
||||
try {
|
||||
Thread.sleep(reportInterval);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
logger.error("HealthCollector report error.", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
package com.a.eye.skywalking.health.report;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class HeathReading {
|
||||
public static final String ERROR = "[ERROR]";
|
||||
public static final String WARNING = "[WARNING]";
|
||||
public static final String INFO = "[INFO]";
|
||||
|
||||
private String id;
|
||||
|
||||
private Map<String, HeathDetailData> datas = new HashMap<String, HeathDetailData>();
|
||||
|
||||
/**
|
||||
* 健康读数,只应该在工作线程中创建
|
||||
*/
|
||||
public HeathReading(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void updateData(String key, String message) {
|
||||
updateData(key, message, new Object[0]);
|
||||
}
|
||||
|
||||
public void updateData(String key, String newData, Object... arguments) {
|
||||
if (datas.containsKey(key)) {
|
||||
datas.get(key).updateData(newData, arguments);
|
||||
} else {
|
||||
datas.put(key, new HeathDetailData(newData, arguments));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("id<").append(this.id).append(">\n");
|
||||
for (Map.Entry<String, HeathDetailData> data : datas.entrySet()) {
|
||||
sb.append(data.getKey()).append(data.getValue().toString()).append("\n");
|
||||
}
|
||||
|
||||
datas = new HashMap<String, HeathReading.HeathDetailData>();
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
class HeathDetailData {
|
||||
private String data;
|
||||
|
||||
private long statusTime;
|
||||
|
||||
HeathDetailData(String initialData) {
|
||||
this(initialData, new Object[0]);
|
||||
}
|
||||
|
||||
HeathDetailData(String initialData, Object[] arguments) {
|
||||
data = initialData;
|
||||
if (arguments.length > 0)
|
||||
data = String.format(initialData, arguments);
|
||||
statusTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
void updateData(String newData, Object... arguments) {
|
||||
data = newData;
|
||||
if (arguments.length > 0)
|
||||
data = String.format(newData, arguments);
|
||||
statusTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
String getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
long getStatusTime() {
|
||||
return statusTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return data + "(t:" + statusTime + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,8 +7,8 @@ package com.a.eye.skywalking.api.logging.api;
|
|||
* <p>
|
||||
* Created by xin on 2016/11/10.
|
||||
*/
|
||||
public class NoopLogger implements ILog {
|
||||
public static final ILog INSTANCE = new NoopLogger();
|
||||
public enum NoopLogger implements ILog {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public void info(String message) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,93 @@
|
|||
package com.a.eye.skywalking.api.logging.api;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.powermock.api.support.membermodification.MemberModifier;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2017/2/27.
|
||||
*/
|
||||
public class LogManagerTest {
|
||||
@Test
|
||||
public void testGetLogger() {
|
||||
final TestLogger logger = new TestLogger();
|
||||
LogManager.setLogResolver(new LogResolver() {
|
||||
@Override
|
||||
public ILog getLogger(Class<?> clazz) {
|
||||
return logger;
|
||||
}
|
||||
});
|
||||
|
||||
Assert.assertEquals(logger, LogManager.getLogger(LogManagerTest.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNoopLogger(){
|
||||
ILog logger = LogManager.getLogger(LogManagerTest.class);
|
||||
Assert.assertEquals(NoopLogger.INSTANCE, logger);
|
||||
}
|
||||
|
||||
@Before
|
||||
@After
|
||||
public void clear() throws IllegalAccessException {
|
||||
MemberModifier.field(LogManager.class, "resolver").set(null, null);
|
||||
}
|
||||
|
||||
|
||||
public class TestLogger implements ILog {
|
||||
|
||||
@Override public void info(String format) {
|
||||
|
||||
}
|
||||
|
||||
@Override public void info(String format, Object... arguments) {
|
||||
|
||||
}
|
||||
|
||||
@Override public void warn(String format, Object... arguments) {
|
||||
|
||||
}
|
||||
|
||||
@Override public void warn(String format, Object arguments, Throwable e) {
|
||||
|
||||
}
|
||||
|
||||
@Override public void error(String format, Throwable e) {
|
||||
|
||||
}
|
||||
|
||||
@Override public void error(String format, Object arguments, Throwable e) {
|
||||
|
||||
}
|
||||
|
||||
@Override public boolean isDebugEnable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public boolean isInfoEnable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public boolean isWarnEnable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public boolean isErrorEnable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public void debug(String format) {
|
||||
|
||||
}
|
||||
|
||||
@Override public void debug(String format, Object... arguments) {
|
||||
|
||||
}
|
||||
|
||||
@Override public void error(String format) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package com.a.eye.skywalking.api.logging.api;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import static com.a.eye.skywalking.api.logging.api.NoopLogger.INSTANCE;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2017/2/27.
|
||||
*/
|
||||
public class NoopLoggerTest {
|
||||
@Test
|
||||
public void testOnNothing(){
|
||||
Assert.assertFalse(INSTANCE.isDebugEnable());
|
||||
Assert.assertFalse(INSTANCE.isInfoEnable());
|
||||
Assert.assertFalse(INSTANCE.isErrorEnable());
|
||||
Assert.assertFalse(INSTANCE.isWarnEnable());
|
||||
|
||||
INSTANCE.debug("Any string");
|
||||
INSTANCE.debug("Any string", new Object[0]);
|
||||
INSTANCE.info("Any string");
|
||||
INSTANCE.info("Any string", new Object[0]);
|
||||
INSTANCE.warn("Any string", new Object[0]);
|
||||
INSTANCE.warn("Any string", new Object[0], new NullPointerException());
|
||||
INSTANCE.error("Any string");
|
||||
INSTANCE.error("Any string", new NullPointerException());
|
||||
INSTANCE.error("Any string", new Object[0], new NullPointerException());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
package com.a.eye.skywalking.api.util;
|
||||
|
||||
import java.util.Properties;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2017/2/27.
|
||||
*/
|
||||
public class ConfigInitializerTest {
|
||||
@Test
|
||||
public void testInitialize() throws IllegalAccessException {
|
||||
Properties properties = new Properties();
|
||||
properties.put("Level1Object.strAttr".toLowerCase(), "stringValue");
|
||||
properties.put("Level1Object.Level2Object.intAttr".toLowerCase(), "1000");
|
||||
properties.put("Level1Object.Level2Object.longAttr".toLowerCase(), "1000");
|
||||
properties.put("Level1Object.Level2Object.booleanAttr".toLowerCase(), "true");
|
||||
|
||||
ConfigInitializer.initialize(properties, TestPropertiesObject.class);
|
||||
|
||||
Assert.assertEquals("stringValue", TestPropertiesObject.Level1Object.strAttr);
|
||||
Assert.assertEquals(1000, TestPropertiesObject.Level1Object.Level2Object.intAttr);
|
||||
Assert.assertEquals(1000L, TestPropertiesObject.Level1Object.Level2Object.longAttr);
|
||||
Assert.assertEquals(true, TestPropertiesObject.Level1Object.Level2Object.booleanAttr);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitializeWithUnsupportedConfig() throws IllegalAccessException {
|
||||
Properties properties = new Properties();
|
||||
properties.put("Level1Object.noExistAttr".toLowerCase(), "stringValue");
|
||||
|
||||
ConfigInitializer.initialize(properties, TestPropertiesObject.class);
|
||||
|
||||
Assert.assertNull(TestPropertiesObject.Level1Object.strAttr);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void clear(){
|
||||
TestPropertiesObject.Level1Object.strAttr = null;
|
||||
TestPropertiesObject.Level1Object.Level2Object.intAttr = 0;
|
||||
TestPropertiesObject.Level1Object.Level2Object.longAttr = 0;
|
||||
TestPropertiesObject.Level1Object.Level2Object.booleanAttr = false;
|
||||
}
|
||||
|
||||
public static class TestPropertiesObject {
|
||||
public static class Level1Object {
|
||||
public static String strAttr = null;
|
||||
|
||||
public static class Level2Object {
|
||||
public static int intAttr = 0;
|
||||
|
||||
public static long longAttr;
|
||||
|
||||
public static boolean booleanAttr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package com.a.eye.skywalking.api.util;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2017/2/27.
|
||||
*/
|
||||
public class StringUtilTest {
|
||||
@Test
|
||||
public void testIsEmpty(){
|
||||
Assert.assertTrue(StringUtil.isEmpty(null));
|
||||
Assert.assertTrue(StringUtil.isEmpty(""));
|
||||
Assert.assertFalse(StringUtil.isEmpty(" "));
|
||||
Assert.assertFalse(StringUtil.isEmpty("A String"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoin(){
|
||||
Assert.assertNull(StringUtil.join('.'));
|
||||
Assert.assertEquals("Single part.", StringUtil.join('.', "Single part."));
|
||||
Assert.assertEquals("part1.part2.p3", StringUtil.join('.', "part1", "part2", "p3"));
|
||||
}
|
||||
}
|
||||
|
|
@ -36,11 +36,6 @@
|
|||
<artifactId>disruptor</artifactId>
|
||||
<version>3.3.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>skywalking-health-report</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>skywalking-logging-api</artifactId>
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ package com.a.eye.skywalking.api.queue;
|
|||
import com.a.eye.skywalking.api.conf.Config;
|
||||
import com.a.eye.skywalking.api.context.TracerContext;
|
||||
import com.a.eye.skywalking.api.context.TracerContextListener;
|
||||
import com.a.eye.skywalking.health.report.HealthCollector;
|
||||
import com.a.eye.skywalking.health.report.HeathReading;
|
||||
import com.a.eye.skywalking.trace.TraceSegment;
|
||||
import com.lmax.disruptor.RingBuffer;
|
||||
import com.lmax.disruptor.dsl.Disruptor;
|
||||
|
|
@ -24,8 +22,6 @@ public enum TraceSegmentProcessQueue implements TracerContextListener {
|
|||
try {
|
||||
TraceSegmentHolder data = this.buffer.get(sequence);
|
||||
data.setValue(traceSegment);
|
||||
|
||||
HealthCollector.getCurrentHeathReading("TraceSegmentProcessQueue").updateData(HeathReading.INFO, "receive finished traceSegment.");
|
||||
} finally {
|
||||
this.buffer.publish(sequence);
|
||||
}
|
||||
|
|
@ -36,7 +32,7 @@ public enum TraceSegmentProcessQueue implements TracerContextListener {
|
|||
RingBuffer<TraceSegmentHolder> buffer;
|
||||
|
||||
TraceSegmentProcessQueue() {
|
||||
disruptor = new Disruptor<TraceSegmentHolder>(TraceSegmentHolder.Factory.INSTANCE, Config.Disruptor.BUFFER_SIZE, DaemonThreadFactory.INSTANCE);
|
||||
disruptor = new Disruptor<>(TraceSegmentHolder.Factory.INSTANCE, Config.Disruptor.BUFFER_SIZE, DaemonThreadFactory.INSTANCE);
|
||||
buffer = disruptor.getRingBuffer();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue