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 64f6e33ba79e22c4f175c87a608f635f96e63860..d33d30471772163b33357ddd81bf73d0c957aaad 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. *

* 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 1d9544b8a18de51efd9b5e2897248f2bec369f44..dc048e7325605099fcb4581b50f2a5442d93722c 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 0000000000000000000000000000000000000000..bd0b70641a021c6c3810727149020872fdf5b455 --- /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 + + + +