Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mechanism to disable any or all plugins #191

Merged
merged 5 commits into from
May 9, 2017

Conversation

ascrutae
Copy link
Member

@ascrutae ascrutae commented May 5, 2017

Relate: #186

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 71.354% when pulling 56daa9ac1d4039af6f30393e5214da5386de482c on ascrutae:zhangxin/feature/186 into ecf7a2b on wu-sheng:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.07%) to 71.265% when pulling 56daa9ac1d4039af6f30393e5214da5386de482c on ascrutae:zhangxin/feature/186 into ecf7a2b on wu-sheng:master.

private List<PluginDefine> pluginClassList = new ArrayList<PluginDefine>();
protected List<String> disabledPlugins = new ArrayList<String>();

PluginCfg() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the contructor for initialization should very careful, if this enum is used before config initialization, the disable mechanism will fail.

So I prefer to make the initialization as a boot service, rather than this.

@@ -12,15 +13,29 @@
public enum PluginCfg {
INSTANCE;

private List<String> pluginClassList = new ArrayList<String>();
private List<PluginDefine> pluginClassList = new ArrayList<PluginDefine>();
protected List<String> disabledPlugins = new ArrayList<String>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DisableList is only used in plugin initialization, shouldn't set it as a class field.

@@ -29,6 +44,55 @@ void load(InputStream input) throws IOException {
}

public List<String> getPluginClassList() {
return pluginClassList;
List<String> pluginClasses = new ArrayList<String>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why need this new list? Just a list copy?

private static class PluginDefine {


private static final PluginDefine NOOP_PLUGIN = new PluginDefine() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a Noop. It always set a empty plugin define.


public static PluginDefine build(String define) {
if (StringUtil.isEmpty(define)) {
return NOOP_PLUGIN;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did not like the design of retuning noop plugin define. Hard to understand and make no sense.

* if you have multiple plugins need to disable.
*
* Here are the plugin names :
* TOMCAT, DUBBO, JEDIS, MOTAN, HTTPCLIENT, JDBC, MONGODB.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All existed config items are in lower case, why choose upper case this time?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some plugin names should include version, I think

@ascrutae ascrutae force-pushed the zhangxin/feature/186 branch 2 times, most recently from 4e6df40 to fa39a4c Compare May 7, 2017 14:36
@coveralls
Copy link

Coverage Status

Coverage increased (+0.008%) to 71.2% when pulling fa39a4c475c80645a871989140243ad46a46dfa6 on ascrutae:zhangxin/feature/186 into ecf7a2b on wu-sheng:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 71.289% when pulling fa39a4c475c80645a871989140243ad46a46dfa6 on ascrutae:zhangxin/feature/186 into ecf7a2b on wu-sheng:master.

@@ -1 +1 @@
org.skywalking.apm.plugin.tomcat78x.define.TomcatInstrumentation
tomcat-7.x=org.skywalking.apm.plugin.tomcat78x.define.TomcatInstrumentation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, the key should be tomcat-7.x/8.x, if.f / is legal.

String pluginDefine = null;
while ((pluginDefine = reader.readLine()) != null) {
PluginDefine plugin = PluginDefine.build(pluginDefine);
if (!plugin.disabled(disabledPlugins)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this is going to work?

According to premain

    public static void premain(String agentArgs, Instrumentation instrumentation) throws PluginException {
        SnifferConfigInitializer.initialize();

        final PluginFinder pluginFinder = new PluginFinder(new PluginBootstrap().loadPlugins());

        ServiceManager.INSTANCE.boot();

load(InputStream input) invokes before ServiceManager.boot. disabledPlugins(initialize in DisabledPluginInitService) must be empty every time, how does this pr work?

@ascrutae ascrutae changed the title [POC-PR] Add mechanism to disable any or all plugins Add mechanism to disable any or all plugins May 8, 2017
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 71.068% when pulling 9c7053b on ascrutae:zhangxin/feature/186 into e3a42f7 on wu-sheng:master.

Copy link
Member

@wu-sheng wu-sheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pr has evolved to a formal pr. I think you have a lot of works to do.

cc @pengys5

@@ -46,6 +50,19 @@ else if (type.isEnum())
parentDesc.removeLastDesc();
}
}

private static List convert2List(String value) {
List result = new ArrayList();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think LinkedList is better choice for performance.

* Here are the plugin names :
* tomcat-7.x/8.x, dubbo, jedis-2.x, motan, httpclient-4.x, jdbc, mongodb-3.x.
*/
public static List DISABLED_PLUGINS = new ArrayList();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same performance concern. Prefer LinkedList.

plugin.setClassTypePool(classTypePool);
plugins.add(plugin);
} catch (Throwable t) {
logger.error(t, "load plugin [{}] failure.", pluginClassName);
logger.error(t, "loade plugin [{}] failure.", pluginDefine.getDefineClass());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loade, typo.

String pluginDefine = null;
while ((pluginDefine = reader.readLine()) != null) {
PluginDefine plugin = PluginDefine.build(pluginDefine);
if (!plugin.disabled(Config.Plugin.DISABLED_PLUGINS)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are using a static field as a parameter, why? You can use is in disabled method, no parameter is needed.

And I prefer the method name should be boolean enable().


public static PluginDefine build(String define) {
if (StringUtil.isEmpty(define)) {
return IllegalPluginDefine.INSTANCE;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still don't understand this enum class, also strange name IllegalPluginDefine. If it is illegal, why don't throw exception?

return defineClass;
}

static class IllegalPluginDefine extends PluginDefine {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again and again, don't accept this design.

org.skywalking.apm.plugin.jedis.v2.define.JedisClusterInstrumentation
org.skywalking.apm.plugin.jedis.v2.define.JedisInstrumentation
jedis=org.skywalking.apm.plugin.jedis.v2.define.JedisClusterInstrumentation
jedis=org.skywalking.apm.plugin.jedis.v2.define.JedisInstrumentation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jedis-2.x, I think

@@ -1,2 +1,2 @@
org.skywalking.apm.plugin.motan.define.MotanConsumerInstrumentation
org.skywalking.apm.plugin.motan.define.MotanProviderInstrumentation
motan=org.skywalking.apm.plugin.motan.define.MotanConsumerInstrumentation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

motan-0.x, I think.

@ascrutae
Copy link
Member Author

ascrutae commented May 8, 2017

@wu-sheng yeah. I think so, I will test it.

Copy link
Member

@wu-sheng wu-sheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still need some adjustments.

while ((pluginDefine = reader.readLine()) != null) {
try {
PluginDefine plugin = PluginDefine.build(pluginDefine);
if (!plugin.disabled()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You never used disabled, just want to know enable or not.


public static PluginDefine build(String define) throws IllegalPluginDefineException {
if (StringUtil.isEmpty(define)) {
throw new IllegalPluginDefineException();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not constructor parameter, why?


String[] pluginDefine = define.split("=");
if (pluginDefine.length != 2) {
throw new IllegalPluginDefineException();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not constructor parameter, why?

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.09%) to 71.104% when pulling 32dfb848c3bd367e691d2a661aa31c5bda0e5b32 on ascrutae:zhangxin/feature/186 into e3a42f7 on wu-sheng:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 71.093% when pulling 152715a7ae008b0bb680b3af5df46734d8b6cf97 on ascrutae:zhangxin/feature/186 into e3a42f7 on wu-sheng:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.01%) to 71.182% when pulling 152715a7ae008b0bb680b3af5df46734d8b6cf97 on ascrutae:zhangxin/feature/186 into e3a42f7 on wu-sheng:master.

Copy link
Member

@wu-sheng wu-sheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still need some changes.


String[] segments = value.split(",");
for (String segment : segments) {
result.add(segment);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You miss segment.trim() and avoid empty string.


/**
* {@link IllegalPluginDefineException} present that the value of plugin define can
* not be formatted.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't understand the comments.....

@ascrutae ascrutae force-pushed the zhangxin/feature/186 branch 3 times, most recently from e12ee04 to 3f902ca Compare May 9, 2017 11:27
org.skywalking.apm.toolkit.activation.opentracing.span.SkyWalkingSpanActivation
org.skywalking.apm.toolkit.activation.opentracing.tracer.SkyWalkingTracerActivation
opentracing-0.20.x=org.skywalking.apm.toolkit.activation.opentracing.span.SkyWalkingSpanActivation
opentracing-0.20.x=org.skywalking.apm.toolkit.activation.opentracing.tracer.SkyWalkingTracerActivation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opentracing activation is based on our application toolkit, so the name should not include version, especially ot version. Keep the name just opentracing

tracecontext-3.x=org.skywalking.apm.toolkit.activation.trace.TraceContextActivation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does 3.x comes from? Our project version? Same as opentracing-toolkit-activation, just tracecontext is enough.

@ascrutae
Copy link
Member Author

ascrutae commented May 9, 2017

Both of test applications were disabled jdbc plugin

Here is the topological graph
wx20170509-223712 2x

Here is the trace segment graph
snip20170509_1

Copy link
Member

@wu-sheng wu-sheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wu-sheng wu-sheng merged commit 4a56043 into apache:master May 9, 2017
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.01%) to 71.182% when pulling f5565569c148d0a4d609f6158512128d5115e77f on ascrutae:zhangxin/feature/186 into e3a42f7 on wu-sheng:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 71.072% when pulling b04888ce9965c14f8302e286b91826fd33d06e44 on ascrutae:zhangxin/feature/186 into e3a42f7 on wu-sheng:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 71.072% when pulling b04888ce9965c14f8302e286b91826fd33d06e44 on ascrutae:zhangxin/feature/186 into e3a42f7 on wu-sheng:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 71.072% when pulling 3f902ca5c4e85ce7bcc25752722ea9a00755ec09 on ascrutae:zhangxin/feature/186 into e3a42f7 on wu-sheng:master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants