Commit 388d2481 authored by 吴晟's avatar 吴晟
Browse files

Fix typo, and remove unnecessary lock in NoConcurrencyAceessObject. Refact...

Fix typo, and remove unnecessary lock in NoConcurrencyAceessObject. Refact FileWriter and SnifferConfigInitializer.
parent fa81a0f6
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -24,7 +24,8 @@ SkyWalking: Large-Scale Distributed Systems Tracing Infrastructure, also known D
* Support popular rpc frameworks, such as [dubbo](https://github.com/alibaba/dubbo), [dubbox](https://github.com/dangdangdotcom/dubbox), [motan](https://github.com/weibocom/motan) etc., trigger email-alert when application occurs unexpected exception.
* Auto-instrumentation mechenism, **no need to CHANGE any application source code**.
* Easy to deploy, **even in product mode** (since 2.0) . No need of Hadoop, HBase, or Cassandra Cluster.
* Pure Java server implementation. provide gRPC (since 2.0)  and HTTP (since 2.1) cross-platform spans collecting service.
* Pure Java server implementation. provide HTTP (since 2.1) cross-platform spans collecting service.
* High performance stream process. 


# Supported components
+9 −6
Original line number Diff line number Diff line
@@ -19,20 +19,24 @@ public class ConfigInitializer {
        initNextLevel(properties, rootConfigType, new ConfigDesc());
    }

    private static void initNextLevel(Properties properties, Class<?> recentConfigType, ConfigDesc parentDesc) throws IllegalArgumentException, IllegalAccessException {
    private static void initNextLevel(Properties properties, Class<?> recentConfigType,
        ConfigDesc parentDesc) throws IllegalArgumentException, IllegalAccessException {
        for (Field field : recentConfigType.getFields()) {
            if (Modifier.isPublic(field.getModifiers()) && Modifier.isStatic(field.getModifiers())) {
                String configKey = (parentDesc + "." + field.getName()).toLowerCase();
                String value = properties.getProperty(configKey);
                if (value != null) {
                    if (field.getType().equals(int.class))
                    Class<?> type = field.getType();
                    if (type.equals(int.class))
                        field.set(null, Integer.valueOf(value));
                    if (field.getType().equals(String.class))
                    else if (type.equals(String.class))
                        field.set(null, value);
                    if (field.getType().equals(long.class))
                    else if (type.equals(long.class))
                        field.set(null, Long.valueOf(value));
                    if (field.getType().equals(boolean.class))
                    else if (type.equals(boolean.class))
                        field.set(null, Boolean.valueOf(value));
                    else if (type.isEnum())
                        field.set(null, Enum.valueOf((Class<Enum>)type, value.toUpperCase()));
                }
            }
        }
@@ -44,7 +48,6 @@ public class ConfigInitializer {
    }
}


class ConfigDesc {
    private LinkedList<String> descs = new LinkedList<String>();

+3 −37
Original line number Diff line number Diff line
@@ -2,16 +2,15 @@ package com.a.eye.skywalking.agent;

import com.a.eye.skywalking.agent.junction.SkyWalkingEnhanceMatcher;
import com.a.eye.skywalking.api.boot.ServiceManager;
import com.a.eye.skywalking.api.conf.Config;
import com.a.eye.skywalking.api.conf.SnifferConfigInitializer;
import com.a.eye.skywalking.api.logging.EasyLogResolver;
import com.a.eye.skywalking.api.plugin.AbstractClassEnhancePluginDefine;
import com.a.eye.skywalking.api.plugin.PluginBootstrap;
import com.a.eye.skywalking.api.plugin.PluginFinder;
import com.a.eye.skywalking.api.plugin.PluginException;

import com.a.eye.skywalking.api.plugin.PluginFinder;
import com.a.eye.skywalking.logging.ILog;
import com.a.eye.skywalking.logging.LogManager;
import java.lang.instrument.Instrumentation;
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.description.NamedElement;
import net.bytebuddy.description.type.TypeDescription;
@@ -19,10 +18,6 @@ import net.bytebuddy.dynamic.DynamicType;
import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.utility.JavaModule;

import java.io.File;
import java.lang.instrument.Instrumentation;
import java.net.URL;

import static net.bytebuddy.matcher.ElementMatchers.isInterface;
import static net.bytebuddy.matcher.ElementMatchers.not;

@@ -50,7 +45,7 @@ public class SkyWalkingAgent {
    public static void premain(String agentArgs, Instrumentation instrumentation) throws PluginException {
        logger = LogManager.getLogger(SkyWalkingAgent.class);

        initConfig();
        SnifferConfigInitializer.initialize();

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

@@ -92,33 +87,4 @@ public class SkyWalkingAgent {
    private static <T extends NamedElement> ElementMatcher.Junction<T> enhanceClassMatcher(PluginFinder pluginFinder) {
        return new SkyWalkingEnhanceMatcher<T>(pluginFinder);
    }

    private static String generateLocationPath() {
        return SkyWalkingAgent.class.getName().replaceAll("\\.", "/") + ".class";
    }


    private static void initConfig() {
        Config.Agent.IS_PREMAIN_MODE = true;
        Config.Agent.PATH = initAgentBasePath();

        SnifferConfigInitializer.initialize();
    }

    /**
     * Try to allocate the skywalking-agent.jar
     * Some config files or output resources are from this path.
     *
     * @return the path, where the skywalking-agent.jar is.
     */
    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 "";
        }
    }
}
+8 −11
Original line number Diff line number Diff line
package com.a.eye.skywalking.api.conf;

import com.a.eye.skywalking.api.logging.LogLevel;

public class Config {

    public static class Agent {
        public static String APPLICATION_CODE = "";

        public static boolean IS_PREMAIN_MODE = false;

        public static String PATH = "";

        public static int SAMPLING_CYCLE = 1;
    }

@@ -24,15 +22,14 @@ public class Config {
        public static int SIZE = 512;
    }


    public static class Logging {
        // log文件名
        public static String LOG_FILE_NAME              = "skywalking-api.log";
        public static String FILE_NAME = "skywalking-api.log";
        // log文件文件夹名字
        public static String LOG_DIR_NAME               = "logs";
        public static String DIR = "";
        // 最大文件大小
        public static int    MAX_LOG_FILE_LENGTH        = 300 * 1024 * 1024;
        // skywalking 系统错误文件日志
        public static String SYSTEM_ERROR_LOG_FILE_NAME = "skywalking-api-error.log";
        public static int MAX_FILE_SIZE = 300 * 1024 * 1024;

        public static LogLevel LEVEL = LogLevel.DEBUG;
    }
}
+3 −7
Original line number Diff line number Diff line
package com.a.eye.skywalking.api.conf;

import com.a.eye.skywalking.trace.GlobalIdGenerator;

public class Constants {
	/**
	 * This is the version, which will be the first segment of traceid.
	 * Ref {@link GlobalIdGenerator#generate()}
	 */
	public final static String SDK_VERSION = "302017";
    public static String PATH_SEPARATOR = System.getProperty("file.separator", "/");

    public static String LINE_SEPARATOR = System.getProperty("line.separator", "\n");
}
Loading