IanCao 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..42de6476a 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 = "sw.specified_config_path";
+ 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..948593abd 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
+ * [Replace the default Agent Config with the specified Agent
Config](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..9f0c1de4e
--- /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)` 的方式来设置探针配置文件路径
+
+ ```
+ -Dsw.specified_config_path=/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..bc7e7b943
--- /dev/null
+++ b/docs/en/Specified-agent-config.md
@@ -0,0 +1,28 @@
+# The Specified Agent Config File
+
+## Supported version
+
+5.0.0-RC+
+
+## What is the specified agent config file ?
+In Default. The agent will try to locate `agent.config`, which should be in
the `/config` dictionary of agent package. <br>
+If User set the specified agent config file, The agent will try to load the
specified agent config file.<br>
+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
+
+ ```
+ -Dsw.specified_config_path=/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:
[email protected]
With regards,
Apache Git Services