You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2018/08/25 11:00:28 UTC

[GitHub] wu-sheng closed pull request #1584: add the function of the specified agent config

wu-sheng closed pull request #1584: add the function of the specified agent config 
URL: https://github.com/apache/incubator-skywalking/pull/1584
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/SnifferConfigInitializer.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/SnifferConfigInitializer.java
index 477455b76..1509afb96 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/SnifferConfigInitializer.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/SnifferConfigInitializer.java
@@ -41,12 +41,14 @@
  */
 public class SnifferConfigInitializer {
     private static final ILog logger = LogManager.getLogger(SnifferConfigInitializer.class);
-    private static String CONFIG_FILE_NAME = "/config/agent.config";
+    private static String SPECIFIED_CONFIG_PATH = "skywalking_config";
+    private static String DEFAULT_CONFIG_FILE_NAME = "/config/agent.config";
     private static String ENV_KEY_PREFIX = "skywalking.";
     private static boolean IS_INIT_COMPLETED = false;
 
     /**
-     * Try to locate `agent.config`, which should be in the /config dictionary of agent package.
+     * If the specified agent config path is set, the agent will try to locate the specified agent config.
+     * If the specified agent config path is not set , the agent will try to locate `agent.config`, which should be in the /config dictionary of agent package.
      * <p>
      * Also try to override the config by system.env and system.properties. All the keys in these two places should
      * start with {@link #ENV_KEY_PREFIX}. e.g. in env `skywalking.agent.application_code=yourAppName` to override
@@ -58,7 +60,7 @@ public static void initialize() throws ConfigNotFoundException, AgentPackageNotF
         InputStreamReader configFileStream;
 
         try {
-            configFileStream = loadConfigFromAgentFolder();
+            configFileStream = loadConfig();
             Properties properties = new Properties();
             properties.load(configFileStream);
             ConfigInitializer.initialize(properties, Config.class);
@@ -113,12 +115,15 @@ private static void overrideConfigBySystemEnv() throws IllegalAccessException {
     }
 
     /**
-     * Load the config file, where the agent jar is.
+     * Load the specified config file or default config file
      *
      * @return the config file {@link InputStream}, or null if not needEnhance.
      */
-    private static InputStreamReader loadConfigFromAgentFolder() throws AgentPackageNotFoundException, ConfigNotFoundException, ConfigReadFailedException {
-        File configFile = new File(AgentPackagePath.getPath(), CONFIG_FILE_NAME);
+    private static InputStreamReader loadConfig() throws AgentPackageNotFoundException, ConfigNotFoundException, ConfigReadFailedException {
+
+        String specifiedConfigPath = System.getProperties().getProperty(SPECIFIED_CONFIG_PATH);
+        File configFile = StringUtil.isEmpty(specifiedConfigPath) ? new File(AgentPackagePath.getPath(), DEFAULT_CONFIG_FILE_NAME) : new File(specifiedConfigPath);
+
         if (configFile.exists() && configFile.isFile()) {
             try {
                 logger.info("Config file found in {}.", configFile);
diff --git a/docs/README.md b/docs/README.md
index 0d3481c3a..d6c68b956 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -13,6 +13,7 @@
         * [[**Incubating**] Filter traces through custom services](../apm-sniffer/optional-plugins/trace-ignore-plugin/README.md)
   * [Architecture Design](en/Architecture.md)
   * Advanced Features
+    * [Locate agent config file by system property](en/Specified-agent-config.md)
     * [Override settings through System.properties](en/Setting-override.md)
     * [Direct uplink and disable naming discovery](en/Direct-uplink.md)
     * [Open TLS](en/TLS.md)
diff --git a/docs/README_ZH.md b/docs/README_ZH.md
index d31902bf9..d1bd9e645 100644
--- a/docs/README_ZH.md
+++ b/docs/README_ZH.md
@@ -15,6 +15,7 @@
         * [[**孵化特性**] 自定义配置忽略追踪信息](../apm-sniffer/optional-plugins/trace-ignore-plugin/README_CN.md)
   * [架构设计](cn/Architecture-CN.md)  
   * 高级特性
+    * [自定义探针配置文件路径](cn/Specified-agent-config-CN.md)
     * [通过系统启动参数进行覆盖配置](cn/Setting-override-CN.md)
     * [服务直连(Direct uplink)及禁用名称服务(naming service)](cn/Direct-uplink-CN.md)
     * [开启TLS](cn/TLS-CN.md)
diff --git a/docs/cn/Specified-agent-config-CN.md b/docs/cn/Specified-agent-config-CN.md
new file mode 100644
index 000000000..67db7fa15
--- /dev/null
+++ b/docs/cn/Specified-agent-config-CN.md
@@ -0,0 +1,26 @@
+# 自定义探针配置文件路径
+
+## 版本支持
+
+5.0.0-RC+
+
+## 什么是自定义探针配置文件路径? 
+默认情况下, SkyWalking 探针读取与 `SkyWalking-agent.jar` 同目录级别下的 `config` 目录下的 `agent.config` 配置文件。
+用户可以自定义探针配置文件的路径,让探针监控的每个服务都是用其特有文件目录的探针配置,用来统一管理一台物理机器上面的多个不同运行服务的探针配置。此自定义探针配置文件与[通过系统启动参数进行覆盖配置](Setting-override-CN.md)无任何冲突。
+
+## 配置优先级
+自定义探针配置文件 > 默认的配置文件
+ 
+## 自定义探针配置路径
+ 自定义的探针配置文件内容格式必须与默认探针配置文件内容格式一致,这里所改变的仅仅只是配置文件的路径
+
+**使用方式:使用 `启动参数(-D)` 的方式来设置探针配置文件路径**
+ 
+ ```
+ -Dskywalking_config=/path/to/agent.config
+ ```
+ 其中的`/path/to/agent.config` 代表的是自定义探针配置文件的绝对路径
+ 
+
+
+  
diff --git a/docs/en/Specified-agent-config.md b/docs/en/Specified-agent-config.md
new file mode 100644
index 000000000..bd0b70641
--- /dev/null
+++ b/docs/en/Specified-agent-config.md
@@ -0,0 +1,29 @@
+# Locate agent config file by system property
+
+## Supported version
+
+5.0.0-RC+
+
+## What is Locate agent config file by system property ?
+In Default. The agent will try to locate `agent.config`, which should be in the `/config` dictionary of agent package.
+If User sets the specified agent config file through system properties, The agent will try to load file from there.
+By the way, This function has no conflict with [Setting Override](Setting-override.md)
+
+## Override priority
+The specified agent config > The default agent config
+ 
+## How to use
+
+The content formats of the specified config must be same as the default config. 
+
+
+**Using `System.Properties(-D)` to set the specified config path**
+ 
+ ```
+ -Dskywalking_config=/path/to/agent.config
+ ```
+ `/path/to/agent.config`  is the absolute path of the specified config file
+ 
+
+
+  


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services