修复无法找到Auth文件的问题,修噶JDBCPluginDefine的名字
This commit is contained in:
parent
682a4cc6f1
commit
875ca84a57
|
|
@ -2,32 +2,38 @@ package com.ai.cloud.skywalking.agent;
|
|||
|
||||
import com.ai.cloud.skywalking.conf.AuthDesc;
|
||||
import com.ai.cloud.skywalking.conf.Config;
|
||||
import com.ai.cloud.skywalking.conf.ConfigInitializer;
|
||||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
import com.ai.cloud.skywalking.plugin.*;
|
||||
import com.ai.cloud.skywalking.plugin.boot.IBootPluginDefine;
|
||||
import net.bytebuddy.agent.builder.AgentBuilder;
|
||||
import net.bytebuddy.description.NamedElement;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.dynamic.DynamicType;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
import net.bytebuddy.matcher.ElementMatchers;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
|
||||
public class SkywalkingAgent {
|
||||
|
||||
private static Logger logger = LogManager.getLogger(SkywalkingAgent.class);
|
||||
|
||||
|
||||
|
||||
public static void premain(String agentArgs, Instrumentation instrumentation) throws PluginException {
|
||||
Config.SkyWalking.IS_PREMAIN_MODE = true;
|
||||
if (!AuthDesc.isAuth()) {
|
||||
initConfig();
|
||||
if (AuthDesc.isAuth()) {
|
||||
List<IPlugin> plugins = new PluginBootstrap().loadPlugins();
|
||||
logger.info("Loaded " + plugins.size() + " plugin");
|
||||
final PluginDefineCategory pluginDefineCategory = PluginDefineCategory.category(plugins);
|
||||
|
||||
startBootPluginDefines(pluginDefineCategory.getBootPluginsDefines());
|
||||
|
||||
new AgentBuilder.Default().type(ElementMatchers.<TypeDescription>any()).transform(new AgentBuilder.Transformer() {
|
||||
new AgentBuilder.Default().type(exclusivePackageClass()).transform(new AgentBuilder.Transformer() {
|
||||
public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder, TypeDescription typeDescription, ClassLoader classLoader) {
|
||||
AbstractClassEnhancePluginDefine pluginDefine = pluginDefineCategory.getClassEnhancePluginDefines().get(typeDescription.getTypeName());
|
||||
if (pluginDefine == null) {
|
||||
|
|
@ -36,7 +42,8 @@ public class SkywalkingAgent {
|
|||
|
||||
try {
|
||||
return pluginDefine.define(builder);
|
||||
} catch (PluginException e) {
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Failed to enhance plugin " + pluginDefine.getClass().getName(), e);
|
||||
return builder;
|
||||
}
|
||||
|
|
@ -46,10 +53,36 @@ public class SkywalkingAgent {
|
|||
}
|
||||
}
|
||||
|
||||
private static ElementMatcher.Junction<NamedElement> exclusivePackageClass() {
|
||||
return ElementMatchers.nameStartsWith("com.alibaba");
|
||||
}
|
||||
|
||||
|
||||
public static void startBootPluginDefines(List<IBootPluginDefine> IBootPluginDefines) throws PluginException {
|
||||
for (IBootPluginDefine bootPluginDefine : IBootPluginDefines) {
|
||||
bootPluginDefine.boot();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static String generateLocationPath() {
|
||||
return SkywalkingAgent.class.getName().replaceAll("\\.", "/") + ".class";
|
||||
}
|
||||
|
||||
|
||||
private static void initConfig() {
|
||||
Config.SkyWalking.IS_PREMAIN_MODE = true;
|
||||
Config.SkyWalking.AGENT_BASE_PATH = initAgentBasePath();
|
||||
}
|
||||
|
||||
private static String initAgentBasePath() {
|
||||
try {
|
||||
String urlString = SkywalkingAgent.class.getClassLoader().getSystemClassLoader().getResource(generateLocationPath()).toString();
|
||||
urlString = urlString.substring(urlString.indexOf("file:"), urlString.indexOf('!'));
|
||||
return new File(new URL(urlString).getFile()).getParentFile().getAbsolutePath();
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to init config .", e);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import com.ai.cloud.skywalking.selfexamination.SDKHealthCollector;
|
|||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
|
||||
public class AuthDesc {
|
||||
private static Logger logger = LogManager.getLogger(AuthDesc.class);
|
||||
|
|
@ -28,23 +27,13 @@ public class AuthDesc {
|
|||
|
||||
private static InputStream fetchAuthFileInputStream() {
|
||||
try {
|
||||
InputStream authFileInputStream;
|
||||
String urlString = ClassLoader.getSystemClassLoader().getResource(generateLocationPath()).toString();
|
||||
urlString = urlString.substring(urlString.indexOf("file:"), urlString.indexOf('!'));
|
||||
URL url = new URL(urlString);
|
||||
File file = new File(url.toURI());
|
||||
authFileInputStream = new FileInputStream(file.getParentFile().getName() + File.separator + "/sky-walking.auth");
|
||||
return authFileInputStream;
|
||||
return new FileInputStream(Config.SkyWalking.AGENT_BASE_PATH + File.separator + "/sky-walking.auth");
|
||||
} catch (Exception e) {
|
||||
logger.error("Error to fetch auth file input stream.", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static String generateLocationPath() {
|
||||
return AuthDesc.class.getName().replaceAll(".", "/") + ".class";
|
||||
}
|
||||
|
||||
public static boolean isAuth() {
|
||||
return isAuth;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ public class Config {
|
|||
public static boolean ALL_METHOD_MONITOR = false;
|
||||
|
||||
public static boolean IS_PREMAIN_MODE = false;
|
||||
|
||||
public static String AGENT_BASE_PATH = "";
|
||||
}
|
||||
|
||||
public static class BuriedPoint {
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ import com.ai.cloud.skywalking.logging.Logger;
|
|||
import com.ai.cloud.skywalking.plugin.boot.BootException;
|
||||
import com.ai.cloud.skywalking.plugin.boot.IBootPluginDefine;
|
||||
|
||||
public class JDBCPluginDefineI implements IBootPluginDefine {
|
||||
private static Logger logger = LogManager.getLogger(JDBCPluginDefineI.class);
|
||||
public class JDBCPluginDefine implements IBootPluginDefine {
|
||||
private static Logger logger = LogManager.getLogger(JDBCPluginDefine.class);
|
||||
|
||||
@Override
|
||||
public void boot() throws BootException {
|
||||
|
|
@ -1 +1 @@
|
|||
com.ai.cloud.skywalking.plugin.jdbc.JDBCPluginDefineI
|
||||
com.ai.cloud.skywalking.plugin.jdbc.JDBCPluginDefine
|
||||
|
|
|
|||
Loading…
Reference in New Issue