提交 60e829fa 编写于 作者: C caoyixiong 提交者: wu-sheng

Add the function of the specified agent config

上级 b174f4fd
......@@ -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);
......
......@@ -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
......
# 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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册