You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@skywalking.apache.org by wu...@apache.org on 2018/08/25 13:41:48 UTC

[incubator-skywalking] branch 6.0 updated: Add the function of the specified agent config

This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch 6.0
in repository https://gitbox.apache.org/repos/asf/incubator-skywalking.git


The following commit(s) were added to refs/heads/6.0 by this push:
     new 60e829f  Add the function of the specified agent config
60e829f is described below

commit 60e829fa30e71a488f1d40a331031f2de7993917
Author: caoyixiong <32...@users.noreply.github.com>
AuthorDate: Sat Aug 25 19:00:27 2018 +0800

    Add the function of the specified agent config
---
 .../agent/core/conf/SnifferConfigInitializer.java  | 17 ++++++++-----
 docs/en/setup/service-agent/java-agent/README.md   |  1 +
 .../java-agent/Specified-agent-config.md           | 29 ++++++++++++++++++++++
 3 files changed, 41 insertions(+), 6 deletions(-)

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 64f6e33..d33d304 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 @@ import org.apache.skywalking.apm.util.StringUtil;
  */
 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 class SnifferConfigInitializer {
         InputStreamReader configFileStream;
 
         try {
-            configFileStream = loadConfigFromAgentFolder();
+            configFileStream = loadConfig();
             Properties properties = new Properties();
             properties.load(configFileStream);
             ConfigInitializer.initialize(properties, Config.class);
@@ -113,12 +115,15 @@ public class SnifferConfigInitializer {
     }
 
     /**
-     * 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/en/setup/service-agent/java-agent/README.md b/docs/en/setup/service-agent/java-agent/README.md
index 1d9544b..dc048e7 100644
--- a/docs/en/setup/service-agent/java-agent/README.md
+++ b/docs/en/setup/service-agent/java-agent/README.md
@@ -66,6 +66,7 @@ Now, we have the following known plugins.
 [log4j2](Application-toolkit-log4j-2.x.md), [logback](Application-toolkit-logback-1.x.md)
     * If you want to use annotations or SkyWalking native APIs to read context, try [SkyWalking manual APIs](Application-toolkit-trace.md)
     * If you want to continue traces across thread manually, use [across thread solution APIs](Application-toolkit-trace-cross-thread.md).
+* If you want to specify the path of your agent.config file. Read [set config file through system properties](Specified-agent-config.md)
 
 ## Plugin Development Guide
 SkyWalking java agent supports plugin to extend [the supported list](Supported-list.md). Please follow 
diff --git a/docs/en/setup/service-agent/java-agent/Specified-agent-config.md b/docs/en/setup/service-agent/java-agent/Specified-agent-config.md
new file mode 100644
index 0000000..bd0b706
--- /dev/null
+++ b/docs/en/setup/service-agent/java-agent/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
+ 
+
+
+