提交 6e6e13b9 编写于 作者: C caoyixiong 提交者: wu-sheng

add the function of the specified agent config (#1584)

* Fix bug stop stopSpan when not createSpan

* Fix bug stop stopSpan when not createSpan

* change the agent log level to millisecond

* add the function of the specified-agent-config

* Update README_ZH.md

* Use -D  to set the specified config path

* add docs

* update docs

* change method name

* add link

* change the function name

* change the key

* format doc
上级 15263bce
......@@ -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);
......
......@@ -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)
......
......@@ -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)
......
# 自定义探针配置文件路径
## 版本支持
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` 代表的是自定义探针配置文件的绝对路径
# 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.
先完成此消息的编辑!
想要评论请 注册