diff --git a/skywalking-commons/pom.xml b/skywalking-commons/pom.xml index 33782de5a..238f583e0 100644 --- a/skywalking-commons/pom.xml +++ b/skywalking-commons/pom.xml @@ -13,7 +13,6 @@ skywalking-trace skywalking-logging - skywalking-health-report skywalking-util diff --git a/skywalking-commons/skywalking-health-report/pom.xml b/skywalking-commons/skywalking-health-report/pom.xml deleted file mode 100644 index 95d6d3321..000000000 --- a/skywalking-commons/skywalking-health-report/pom.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - skywalking-commons - com.a.eye - 3.0-2017 - - 4.0.0 - - skywalking-health-report - jar - - skywalking-health-report - http://maven.apache.org - - - - com.a.eye - skywalking-logging-api - ${project.version} - - - diff --git a/skywalking-commons/skywalking-health-report/src/main/java/com/a/eye/skywalking/health/report/HealthCollector.java b/skywalking-commons/skywalking-health-report/src/main/java/com/a/eye/skywalking/health/report/HealthCollector.java deleted file mode 100644 index 601bab84c..000000000 --- a/skywalking-commons/skywalking-health-report/src/main/java/com/a/eye/skywalking/health/report/HealthCollector.java +++ /dev/null @@ -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 heathReadings = new ConcurrentHashMap(); - 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 heathReadingsSnapshot = heathReadings; - heathReadings = new ConcurrentHashMap(); - 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); - } - } - } -} diff --git a/skywalking-commons/skywalking-health-report/src/main/java/com/a/eye/skywalking/health/report/HeathReading.java b/skywalking-commons/skywalking-health-report/src/main/java/com/a/eye/skywalking/health/report/HeathReading.java deleted file mode 100644 index c413e78b5..000000000 --- a/skywalking-commons/skywalking-health-report/src/main/java/com/a/eye/skywalking/health/report/HeathReading.java +++ /dev/null @@ -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 datas = new HashMap(); - - /** - * 健康读数,只应该在工作线程中创建 - */ - 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 data : datas.entrySet()) { - sb.append(data.getKey()).append(data.getValue().toString()).append("\n"); - } - - datas = new HashMap(); - 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 + ")"; - } - } -} diff --git a/skywalking-commons/skywalking-logging/skywalking-logging-api/src/main/java/com/a/eye/skywalking/api/logging/api/NoopLogger.java b/skywalking-commons/skywalking-logging/skywalking-logging-api/src/main/java/com/a/eye/skywalking/api/logging/api/NoopLogger.java index 8088322e1..9f28294ba 100644 --- a/skywalking-commons/skywalking-logging/skywalking-logging-api/src/main/java/com/a/eye/skywalking/api/logging/api/NoopLogger.java +++ b/skywalking-commons/skywalking-logging/skywalking-logging-api/src/main/java/com/a/eye/skywalking/api/logging/api/NoopLogger.java @@ -7,8 +7,8 @@ package com.a.eye.skywalking.api.logging.api; *

* 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) { diff --git a/skywalking-commons/skywalking-logging/skywalking-logging-api/src/test/java/com/a/eye/skywalking/api/logging/api/LogManagerTest.java b/skywalking-commons/skywalking-logging/skywalking-logging-api/src/test/java/com/a/eye/skywalking/api/logging/api/LogManagerTest.java new file mode 100644 index 000000000..51ce2c81c --- /dev/null +++ b/skywalking-commons/skywalking-logging/skywalking-logging-api/src/test/java/com/a/eye/skywalking/api/logging/api/LogManagerTest.java @@ -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) { + + } + } +} diff --git a/skywalking-commons/skywalking-logging/skywalking-logging-api/src/test/java/com/a/eye/skywalking/api/logging/api/NoopLoggerTest.java b/skywalking-commons/skywalking-logging/skywalking-logging-api/src/test/java/com/a/eye/skywalking/api/logging/api/NoopLoggerTest.java new file mode 100644 index 000000000..7bbd3ab2f --- /dev/null +++ b/skywalking-commons/skywalking-logging/skywalking-logging-api/src/test/java/com/a/eye/skywalking/api/logging/api/NoopLoggerTest.java @@ -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()); + } +} diff --git a/skywalking-commons/skywalking-util/src/test/java/com/a/eye/skywalking/api/util/ConfigInitializerTest.java b/skywalking-commons/skywalking-util/src/test/java/com/a/eye/skywalking/api/util/ConfigInitializerTest.java new file mode 100644 index 000000000..73fdad22e --- /dev/null +++ b/skywalking-commons/skywalking-util/src/test/java/com/a/eye/skywalking/api/util/ConfigInitializerTest.java @@ -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; + } + } + } +} diff --git a/skywalking-commons/skywalking-util/src/test/java/com/a/eye/skywalking/api/util/StringUtilTest.java b/skywalking-commons/skywalking-util/src/test/java/com/a/eye/skywalking/api/util/StringUtilTest.java new file mode 100644 index 000000000..e4c59ee96 --- /dev/null +++ b/skywalking-commons/skywalking-util/src/test/java/com/a/eye/skywalking/api/util/StringUtilTest.java @@ -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")); + } +} diff --git a/skywalking-sniffer/skywalking-api/pom.xml b/skywalking-sniffer/skywalking-api/pom.xml index eff87bd7e..615db5f4f 100644 --- a/skywalking-sniffer/skywalking-api/pom.xml +++ b/skywalking-sniffer/skywalking-api/pom.xml @@ -36,11 +36,6 @@ disruptor 3.3.6 - - com.a.eye - skywalking-health-report - ${project.version} - com.a.eye skywalking-logging-api diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/queue/TraceSegmentProcessQueue.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/queue/TraceSegmentProcessQueue.java index 7a3ac2d1b..5da3cc5ec 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/queue/TraceSegmentProcessQueue.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/queue/TraceSegmentProcessQueue.java @@ -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 buffer; TraceSegmentProcessQueue() { - disruptor = new Disruptor(TraceSegmentHolder.Factory.INSTANCE, Config.Disruptor.BUFFER_SIZE, DaemonThreadFactory.INSTANCE); + disruptor = new Disruptor<>(TraceSegmentHolder.Factory.INSTANCE, Config.Disruptor.BUFFER_SIZE, DaemonThreadFactory.INSTANCE); buffer = disruptor.getRingBuffer(); }