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 11:00:31 UTC
[incubator-skywalking] branch master updated: add the function of
the specified agent config (#1584)
This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-skywalking.git
The following commit(s) were added to refs/heads/master by this push:
new 6e6e13b add the function of the specified agent config (#1584)
6e6e13b is described below
commit 6e6e13b9f53214164abd0d707ebc9947bd6fa495
Author: caoyixiong <32...@users.noreply.github.com>
AuthorDate: Sat Aug 25 19:00:27 2018 +0800
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
---
.../agent/core/conf/SnifferConfigInitializer.java | 17 ++++++++-----
docs/README.md | 1 +
docs/README_ZH.md | 1 +
docs/cn/Specified-agent-config-CN.md | 26 +++++++++++++++++++
docs/en/Specified-agent-config.md | 29 ++++++++++++++++++++++
5 files changed, 68 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 477455b..1509afb 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/README.md b/docs/README.md
index 0d3481c..d6c68b9 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
+ * [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)
diff --git a/docs/README_ZH.md b/docs/README_ZH.md
index d31902b..d1bd9e6 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 0000000..67db7fa
--- /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)` 的方式来设置探针配置文件路径**
+
+ ```
+ -Dskywalking_config=/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 0000000..bd0b706
--- /dev/null
+++ b/docs/en/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
+
+
+
+