Merge branch 'master' of https://github.com/wu-sheng/sky-walking
# By ascrutae # Via ascrutae * 'master' of https://github.com/wu-sheng/sky-walking: 1. 解决在Tomcat的Classloader下取不到授权文件 2. Log增加一种模式,直接Console输出,Console输出只针对非Premain模式下才会生效
This commit is contained in:
commit
a0ea987e93
|
|
@ -1,14 +1,15 @@
|
|||
#skyWalking用户ID
|
||||
skywalking.user_id=123
|
||||
#skyWalking应用编码
|
||||
skywalking.application_code=test
|
||||
skywalking.application_code=skywalking-sample-dubbo
|
||||
#skywalking auth的环境变量名字
|
||||
skywalking.auth_system_env_name=SKYWALKING_RUN
|
||||
#skywalking数据编码
|
||||
skywalking.charset=UTF-8
|
||||
skywalking.auth_override=true
|
||||
|
||||
#是否打印数据
|
||||
buriedpoint.printf=false
|
||||
buriedpoint.printf=true
|
||||
#埋点异常的最大长度
|
||||
buriedpoint.max_exception_stack_length=4000
|
||||
#业务字段的最大长度
|
||||
|
|
@ -27,11 +28,8 @@ sender.max_send_length=20000
|
|||
#当没有Sender时,尝试获取sender的等待周期
|
||||
sender.retry_get_sender_wait_interval=2000
|
||||
|
||||
|
||||
|
||||
|
||||
#最大消费线程数
|
||||
consumer.max_consumer=2
|
||||
consumer.max_consumer=0
|
||||
#消费者最大等待时间
|
||||
consumer.max_wait_time=5
|
||||
#发送失败等待时间
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
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;
|
||||
|
|
@ -19,9 +20,8 @@ public class SkywalkingAgent {
|
|||
private static Logger logger = LogManager.getLogger(SkywalkingAgent.class);
|
||||
|
||||
public static void premain(String agentArgs, Instrumentation instrumentation) throws PluginException {
|
||||
ConfigInitializer.initialize();
|
||||
Config.SkyWalking.IS_PREMAIN_MODE = true;
|
||||
if (!AuthDesc.isAuth()) {
|
||||
|
||||
List<IPlugin> plugins = new PluginBootstrap().loadPlugins();
|
||||
final PluginDefineCategory pluginDefineCategory = PluginDefineCategory.category(plugins);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +1,50 @@
|
|||
package com.ai.cloud.skywalking.conf;
|
||||
|
||||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
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 {
|
||||
static boolean isAuth = false;
|
||||
private static Logger logger = LogManager.getLogger(AuthDesc.class);
|
||||
static boolean isAuth = false;
|
||||
|
||||
static {
|
||||
ConfigInitializer.initialize();
|
||||
InputStream authFileInputStream;
|
||||
if (Config.SkyWalking.IS_PREMAIN_MODE) {
|
||||
authFileInputStream = fetchAuthFileInputStream();
|
||||
} else {
|
||||
authFileInputStream = AuthDesc.class.getResourceAsStream("/sky-walking.auth");
|
||||
}
|
||||
|
||||
ConfigInitializer.initialize(authFileInputStream);
|
||||
ConfigValidator.validate();
|
||||
|
||||
SDKHealthCollector.init();
|
||||
}
|
||||
|
||||
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;
|
||||
} 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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ public class Config {
|
|||
public static String CHARSET = "UTF-8";
|
||||
|
||||
public static boolean ALL_METHOD_MONITOR = false;
|
||||
|
||||
public static boolean IS_PREMAIN_MODE = false;
|
||||
}
|
||||
|
||||
public static class BuriedPoint {
|
||||
|
|
|
|||
|
|
@ -16,8 +16,7 @@ import java.util.Properties;
|
|||
public class ConfigInitializer {
|
||||
private static Logger logger = LogManager.getLogger(ConfigInitializer.class);
|
||||
|
||||
public static void initialize() {
|
||||
InputStream inputStream = ConfigInitializer.class.getResourceAsStream("/sky-walking.auth");
|
||||
static void initialize(InputStream inputStream) {
|
||||
if (inputStream == null) {
|
||||
logger.info("No provider sky-walking certification documents, sky-walking api auto shutdown.");
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
package com.ai.cloud.skywalking.logging;
|
||||
|
||||
public interface IFileWriter {
|
||||
public interface IWriter {
|
||||
void write(String message);
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@ public class Logger {
|
|||
|
||||
private Class toBeLoggerClass;
|
||||
|
||||
|
||||
public Logger(Class toBeLoggerClass) {
|
||||
this.toBeLoggerClass = toBeLoggerClass;
|
||||
}
|
||||
|
|
@ -22,11 +23,11 @@ public class Logger {
|
|||
StackTraceElement locations[] = dummyException.getStackTrace();
|
||||
|
||||
if (locations != null && locations.length > 2) {
|
||||
SyncFileWriter.instance().write(formatMessage(level, message, locations[2]));
|
||||
WriterFactory.getLogWriter().write(formatMessage(level, message, locations[2]));
|
||||
}
|
||||
|
||||
if (e != null) {
|
||||
SyncFileWriter.instance().write(LoggingUtil.fetchThrowableStack(e));
|
||||
WriterFactory.getLogWriter().write(LoggingUtil.fetchThrowableStack(e));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
package com.ai.cloud.skywalking.logging;
|
||||
|
||||
public class STDOutWriter implements IWriter {
|
||||
|
||||
|
||||
@Override
|
||||
public void write(String message) {
|
||||
System.err.println(message);
|
||||
}
|
||||
}
|
||||
|
|
@ -14,7 +14,7 @@ import java.util.Date;
|
|||
import static com.ai.cloud.skywalking.conf.Config.Logging.LOG_FILE_NAME;
|
||||
import static com.ai.cloud.skywalking.conf.Config.Logging.LOG_FILE_PATH;
|
||||
|
||||
public class SyncFileWriter implements IFileWriter {
|
||||
public class SyncFileWriter implements IWriter {
|
||||
|
||||
private static SyncFileWriter writer;
|
||||
private FileOutputStream os;
|
||||
|
|
@ -35,7 +35,7 @@ public class SyncFileWriter implements IFileWriter {
|
|||
}
|
||||
|
||||
|
||||
public static IFileWriter instance() {
|
||||
public static IWriter instance() {
|
||||
if (writer == null) {
|
||||
writer = new SyncFileWriter();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
package com.ai.cloud.skywalking.logging;
|
||||
|
||||
import com.ai.cloud.skywalking.conf.Config;
|
||||
|
||||
public class WriterFactory {
|
||||
private WriterFactory(){
|
||||
}
|
||||
|
||||
public static IWriter getLogWriter(){
|
||||
if (Config.SkyWalking.IS_PREMAIN_MODE){
|
||||
return SyncFileWriter.instance();
|
||||
}else{
|
||||
return new STDOutWriter();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue