Merge branch 'master' into zhangxin/fix/windows-script-start-failure

This commit is contained in:
吴晟 Wu Sheng 2017-06-27 10:01:52 +08:00 committed by GitHub
commit 834468f55b
5 changed files with 86 additions and 4 deletions

View File

@ -101,6 +101,12 @@ public class Config {
*/
public static List DISABLED_PLUGINS = new LinkedList();
/**
* Name of force enable plugin, The value spilt by <code>,</code>
* if you have multiple plugins need to enable.
*/
public static List FORCE_ENABLE_PLUGINS = new LinkedList();
public static class MongoDB {
/**
* If true, trace all the parameters, default is false.

View File

@ -383,7 +383,7 @@ public class Span implements AbstractSpan {
}
}
if (span.tagsWithInt != null) {
if (tagWithInt != null) {
if (tagWithInt == null) {
tagWithInt = new JsonObject();
}
for (IntTagItem item : span.tagsWithInt) {

View File

@ -5,6 +5,7 @@ import org.skywalking.apm.agent.core.plugin.exception.IllegalPluginDefineExcepti
import org.skywalking.apm.util.StringUtil;
public class PluginDefine {
public static final String PLUGIN_OFF_PREFIX = "[OFF]";
/**
* Plugin name.
*/
@ -15,9 +16,15 @@ public class PluginDefine {
*/
private String defineClass;
private PluginDefine(String name, String defineClass) {
/**
* The sate of plugin.
*/
private State state;
private PluginDefine(String name, String defineClass, State state) {
this.name = name;
this.defineClass = defineClass;
this.state = state;
}
public static PluginDefine build(String define) throws IllegalPluginDefineException {
@ -30,16 +37,34 @@ public class PluginDefine {
throw new IllegalPluginDefineException(define);
}
return new PluginDefine(pluginDefine[0], pluginDefine[1]);
String pluginName = pluginDefine[0];
String defineClass = pluginDefine[1];
if (pluginName.toUpperCase().startsWith(PLUGIN_OFF_PREFIX)) {
return new PluginDefine(pluginName.substring(PLUGIN_OFF_PREFIX.length()), defineClass, State.OFF);
} else {
return new PluginDefine(pluginName, defineClass, State.ON);
}
}
public boolean enable() {
return !Config.Plugin.DISABLED_PLUGINS.contains(name);
return !forceDisable() || forceEnable();
}
private boolean forceDisable() {
return state != State.ON || Config.Plugin.DISABLED_PLUGINS.contains(name);
}
private boolean forceEnable() {
return state == State.OFF && Config.Plugin.FORCE_ENABLE_PLUGINS.contains(name);
}
public String getDefineClass() {
return defineClass;
}
private enum State {
OFF, ON;
}
}

View File

@ -0,0 +1,48 @@
package org.skywalking.apm.agent.core.plugin;
import org.junit.Test;
import org.skywalking.apm.agent.core.conf.Config;
import org.skywalking.apm.agent.core.plugin.exception.IllegalPluginDefineException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class PluginDefineTest {
private static final String TEST_PLUGIN = "test_plugin";
private static final String TEST_DEFINE_CLASS = "test_define_class";
@Test(expected = IllegalPluginDefineException.class)
public void testIllegalPluginDefine() throws IllegalPluginDefineException {
PluginDefine.build("illegal_plugin_define");
}
@Test(expected = IllegalPluginDefineException.class)
public void testEmptyPluginDefine() throws IllegalPluginDefineException {
PluginDefine.build("");
}
@Test
public void testOffStatePlugin() throws IllegalPluginDefineException {
PluginDefine pluginDefine = PluginDefine.build(PluginDefine.PLUGIN_OFF_PREFIX + TEST_PLUGIN + "=" + TEST_DEFINE_CLASS);
assertFalse(pluginDefine.enable());
assertEquals(TEST_DEFINE_CLASS, pluginDefine.getDefineClass());
}
@Test
public void testDefaultStatePlugin() throws IllegalPluginDefineException {
PluginDefine pluginDefine = PluginDefine.build(TEST_PLUGIN + "=" + TEST_DEFINE_CLASS);
assertTrue(pluginDefine.enable());
assertEquals(TEST_DEFINE_CLASS, pluginDefine.getDefineClass());
}
@Test
public void testForceEnablePlugin() throws IllegalPluginDefineException {
Config.Plugin.FORCE_ENABLE_PLUGINS.add(TEST_PLUGIN);
PluginDefine pluginDefine = PluginDefine.build(PluginDefine.PLUGIN_OFF_PREFIX + TEST_PLUGIN + "=" + TEST_DEFINE_CLASS);
assertTrue(pluginDefine.enable());
assertEquals(TEST_DEFINE_CLASS, pluginDefine.getDefineClass());
Config.Plugin.FORCE_ENABLE_PLUGINS.clear();
}
}

View File

@ -30,6 +30,9 @@ services:
es-server:
image: elasticsearch:5.3
command: "-Enode.name=TestNode -Enetwork.host=0.0.0.0 -Ehttp.cors.enabled=true -Ehttp.cors.allow-origin=* -Ethread_pool.bulk.queue_size=1000 -Ecluster.name=CollectorDBCluster"
environment:
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
expose:
- "9200"
- "9300"