提交 b7903076 编写于 作者: J Jared.Tan 提交者: wu-sheng

feat:Active System.env Config In Both Collector And agent.config. (#1957)

* feat:Active System.env Config In Both Collector And agent.config.
1、moving related codes into apm-util module.
2、update Setting-override.md about how to use.

* resolve docs.

* typo

* finish test case.

* Update README.md
上级 578fd703
...@@ -33,5 +33,4 @@ ...@@ -33,5 +33,4 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
</project> </project>
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* *
*/ */
package org.apache.skywalking.oap.server.library.util; package org.apache.skywalking.apm.util;
/** /**
* @author jian.tan * @author jian.tan
......
...@@ -16,17 +16,13 @@ ...@@ -16,17 +16,13 @@
* *
*/ */
package org.apache.skywalking.oap.server.library.util; package org.apache.skywalking.apm.util;
import com.google.common.base.Strings;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import org.apache.logging.log4j.core.util.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* Utility class for working with Strings that have placeholder values in them. A placeholder takes the form {@code * Utility class for working with Strings that have placeholder values in them. A placeholder takes the form {@code
...@@ -34,9 +30,7 @@ import org.slf4j.LoggerFactory; ...@@ -34,9 +30,7 @@ import org.slf4j.LoggerFactory;
* Values for substitution can be supplied using a {@link Properties} instance or using a {@link PlaceholderResolver}. * Values for substitution can be supplied using a {@link Properties} instance or using a {@link PlaceholderResolver}.
*/ */
public class PropertyPlaceholderHelper { public class PropertyPlaceholderHelper {
private static final Logger logger = LoggerFactory.getLogger(PropertyPlaceholderHelper.class); private static final Map<String, String> WELL_KNOWN_SIMPLE_PREFIXES = new HashMap<String, String>(4);
private static final Map<String, String> WELL_KNOWN_SIMPLE_PREFIXES = new HashMap<>(4);
static { static {
WELL_KNOWN_SIMPLE_PREFIXES.put("}", "{"); WELL_KNOWN_SIMPLE_PREFIXES.put("}", "{");
...@@ -66,8 +60,9 @@ public class PropertyPlaceholderHelper { ...@@ -66,8 +60,9 @@ public class PropertyPlaceholderHelper {
*/ */
public PropertyPlaceholderHelper(String placeholderPrefix, String placeholderSuffix, public PropertyPlaceholderHelper(String placeholderPrefix, String placeholderSuffix,
String valueSeparator, boolean ignoreUnresolvablePlaceholders) { String valueSeparator, boolean ignoreUnresolvablePlaceholders) {
Assert.requireNonEmpty(placeholderPrefix, "'placeholderPrefix' must not be null"); if (StringUtil.isEmpty(placeholderPrefix) || StringUtil.isEmpty(placeholderSuffix)) {
Assert.requireNonEmpty(placeholderSuffix, "'placeholderSuffix' must not be null"); throw new UnsupportedOperationException("'placeholderPrefix or placeholderSuffix' must not be null");
}
this.placeholderPrefix = placeholderPrefix; this.placeholderPrefix = placeholderPrefix;
this.placeholderSuffix = placeholderSuffix; this.placeholderSuffix = placeholderSuffix;
String simplePrefixForSuffix = WELL_KNOWN_SIMPLE_PREFIXES.get(this.placeholderSuffix); String simplePrefixForSuffix = WELL_KNOWN_SIMPLE_PREFIXES.get(this.placeholderSuffix);
...@@ -89,16 +84,19 @@ public class PropertyPlaceholderHelper { ...@@ -89,16 +84,19 @@ public class PropertyPlaceholderHelper {
* @return the supplied value with placeholders replaced inline * @return the supplied value with placeholders replaced inline
*/ */
public String replacePlaceholders(String value, final Properties properties) { public String replacePlaceholders(String value, final Properties properties) {
Assert.requireNonEmpty(properties, "'properties' must not be null"); return replacePlaceholders(value, new PlaceholderResolver() {
return replacePlaceholders(value, placeholderName -> this.getConfigValue(placeholderName, properties)); @Override public String resolvePlaceholder(String placeholderName) {
return PropertyPlaceholderHelper.this.getConfigValue(placeholderName, properties);
}
});
} }
private String getConfigValue(String key, final Properties properties) { private String getConfigValue(String key, final Properties properties) {
String value = System.getProperty(key); String value = System.getProperty(key);
if (Strings.isNullOrEmpty(value)) { if (StringUtil.isEmpty(value)) {
value = System.getenv(key); value = System.getenv(key);
} }
if (Strings.isNullOrEmpty(value)) { if (StringUtil.isEmpty(value)) {
value = properties.getProperty(key); value = properties.getProperty(key);
} }
return value; return value;
...@@ -113,7 +111,6 @@ public class PropertyPlaceholderHelper { ...@@ -113,7 +111,6 @@ public class PropertyPlaceholderHelper {
* @return the supplied value with placeholders replaced inline * @return the supplied value with placeholders replaced inline
*/ */
public String replacePlaceholders(String value, PlaceholderResolver placeholderResolver) { public String replacePlaceholders(String value, PlaceholderResolver placeholderResolver) {
Assert.requireNonEmpty(value, "'value' must not be null");
return parseStringValue(value, placeholderResolver, new HashSet<String>()); return parseStringValue(value, placeholderResolver, new HashSet<String>());
} }
...@@ -152,9 +149,6 @@ public class PropertyPlaceholderHelper { ...@@ -152,9 +149,6 @@ public class PropertyPlaceholderHelper {
// previously resolved placeholder value. // previously resolved placeholder value.
propVal = parseStringValue(propVal, placeholderResolver, visitedPlaceholders); propVal = parseStringValue(propVal, placeholderResolver, visitedPlaceholders);
result.replace(startIndex, endIndex + this.placeholderSuffix.length(), propVal); result.replace(startIndex, endIndex + this.placeholderSuffix.length(), propVal);
if (logger.isTraceEnabled()) {
logger.trace("Resolved placeholder '" + placeholder + "'");
}
startIndex = result.indexOf(this.placeholderPrefix, startIndex + propVal.length()); startIndex = result.indexOf(this.placeholderPrefix, startIndex + propVal.length());
} else if (this.ignoreUnresolvablePlaceholders) { } else if (this.ignoreUnresolvablePlaceholders) {
// Proceed with unprocessed value. // Proceed with unprocessed value.
...@@ -175,14 +169,14 @@ public class PropertyPlaceholderHelper { ...@@ -175,14 +169,14 @@ public class PropertyPlaceholderHelper {
int index = startIndex + this.placeholderPrefix.length(); int index = startIndex + this.placeholderPrefix.length();
int withinNestedPlaceholder = 0; int withinNestedPlaceholder = 0;
while (index < buf.length()) { while (index < buf.length()) {
if (StringUtils.substringMatch(buf, index, this.placeholderSuffix)) { if (StringUtil.substringMatch(buf, index, this.placeholderSuffix)) {
if (withinNestedPlaceholder > 0) { if (withinNestedPlaceholder > 0) {
withinNestedPlaceholder--; withinNestedPlaceholder--;
index = index + this.placeholderSuffix.length(); index = index + this.placeholderSuffix.length();
} else { } else {
return index; return index;
} }
} else if (StringUtils.substringMatch(buf, index, this.simplePrefix)) { } else if (StringUtil.substringMatch(buf, index, this.simplePrefix)) {
withinNestedPlaceholder++; withinNestedPlaceholder++;
index = index + this.simplePrefix.length(); index = index + this.simplePrefix.length();
} else { } else {
......
...@@ -50,4 +50,16 @@ public final class StringUtil { ...@@ -50,4 +50,16 @@ public final class StringUtil {
} }
return sb.toString(); return sb.toString();
} }
public static boolean substringMatch(CharSequence str, int index, CharSequence substring) {
if (index + substring.length() > str.length()) {
return false;
}
for (int i = 0; i < substring.length(); i++) {
if (str.charAt(index + i) != substring.charAt(i)) {
return false;
}
}
return true;
}
} }
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
~ ~
--> -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
...@@ -58,6 +59,7 @@ ...@@ -58,6 +59,7 @@
<shade.org.apache.commons.source>org.apache.commons</shade.org.apache.commons.source> <shade.org.apache.commons.source>org.apache.commons</shade.org.apache.commons.source>
<shade.org.apache.commons.target>${shade.package}.${shade.org.apache.http.source} <shade.org.apache.commons.target>${shade.package}.${shade.org.apache.http.source}
</shade.org.apache.commons.target> </shade.org.apache.commons.target>
<ststem-rules.version>1.18.0</ststem-rules.version>
</properties> </properties>
<dependencies> <dependencies>
...@@ -142,6 +144,12 @@ ...@@ -142,6 +144,12 @@
<artifactId>apm-datacarrier</artifactId> <artifactId>apm-datacarrier</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>com.github.stefanbirkner</groupId>
<artifactId>system-rules</artifactId>
<version>${ststem-rules.version}</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>
......
...@@ -37,8 +37,8 @@ public class Config { ...@@ -37,8 +37,8 @@ public class Config {
public static String NAMESPACE = ""; public static String NAMESPACE = "";
/** /**
* Application code is showed in sky-walking-ui. Suggestion: set an unique name for each application, one * Application code is showed in skywalking-ui. Suggestion: set a unique name for each service,
* application's nodes share the same code. * service instance nodes share the same code
*/ */
public static String SERVICE_NAME = ""; public static String SERVICE_NAME = "";
...@@ -50,7 +50,7 @@ public class Config { ...@@ -50,7 +50,7 @@ public class Config {
/** /**
* Negative or zero means off, by default. {@link #SAMPLE_N_PER_3_SECS} means sampling N {@link TraceSegment} in * Negative or zero means off, by default. {@link #SAMPLE_N_PER_3_SECS} means sampling N {@link TraceSegment} in
* 10 seconds tops. * 3 seconds tops.
*/ */
public static int SAMPLE_N_PER_3_SECS = -1; public static int SAMPLE_N_PER_3_SECS = -1;
...@@ -147,13 +147,15 @@ public class Config { ...@@ -147,13 +147,15 @@ public class Config {
public static class Plugin { public static class Plugin {
public static class MongoDB { public static class MongoDB {
/** /**
* If true, trace all the parameters, default is false. Only trace the operation, not include parameters. * If true, trace all the parameters in MongoDB access, default is false. Only trace the operation, not include parameters.
*/ */
public static boolean TRACE_PARAM = false; public static boolean TRACE_PARAM = false;
} }
public static class Elasticsearch { public static class Elasticsearch {
/**
* If true, trace all the DSL(Domain Specific Language) in ElasticSearch access, default is false.
*/
public static boolean TRACE_DSL = false; public static boolean TRACE_DSL = false;
} }
} }
......
...@@ -34,6 +34,8 @@ import org.apache.skywalking.apm.agent.core.boot.AgentPackagePath; ...@@ -34,6 +34,8 @@ import org.apache.skywalking.apm.agent.core.boot.AgentPackagePath;
import org.apache.skywalking.apm.agent.core.logging.api.ILog; import org.apache.skywalking.apm.agent.core.logging.api.ILog;
import org.apache.skywalking.apm.agent.core.logging.api.LogManager; import org.apache.skywalking.apm.agent.core.logging.api.LogManager;
import org.apache.skywalking.apm.util.ConfigInitializer; import org.apache.skywalking.apm.util.ConfigInitializer;
import org.apache.skywalking.apm.util.PlaceholderConfigurerSupport;
import org.apache.skywalking.apm.util.PropertyPlaceholderHelper;
import org.apache.skywalking.apm.util.StringUtil; import org.apache.skywalking.apm.util.StringUtil;
/** /**
...@@ -65,13 +67,22 @@ public class SnifferConfigInitializer { ...@@ -65,13 +67,22 @@ public class SnifferConfigInitializer {
configFileStream = loadConfig(); configFileStream = loadConfig();
Properties properties = new Properties(); Properties properties = new Properties();
properties.load(configFileStream); properties.load(configFileStream);
PropertyPlaceholderHelper helper =
new PropertyPlaceholderHelper(PlaceholderConfigurerSupport.DEFAULT_PLACEHOLDER_PREFIX,
PlaceholderConfigurerSupport.DEFAULT_PLACEHOLDER_SUFFIX,
PlaceholderConfigurerSupport.DEFAULT_VALUE_SEPARATOR, true);
for (String key : properties.stringPropertyNames()) {
String value = (String)properties.get(key);
//replace the key's value. properties.replace(key,value) in jdk8+
properties.put(key, helper.replacePlaceholders(value, properties));
}
ConfigInitializer.initialize(properties, Config.class); ConfigInitializer.initialize(properties, Config.class);
} catch (Exception e) { } catch (Exception e) {
logger.error(e, "Failed to read the config file, skywalking is going to run in default config."); logger.error(e, "Failed to read the config file, skywalking is going to run in default config.");
} }
try { try {
overrideConfigBySystemEnv(); overrideConfigBySystemProp();
} catch (Exception e) { } catch (Exception e) {
logger.error(e, "Failed to read the system env."); logger.error(e, "Failed to read the system env.");
} }
...@@ -142,7 +153,7 @@ public class SnifferConfigInitializer { ...@@ -142,7 +153,7 @@ public class SnifferConfigInitializer {
} }
/** /**
* Override the config by system env. The env key must start with `skywalking`, the reuslt should be as same as in * Override the config by system properties. The env key must start with `skywalking`, the reuslt should be as same as in
* `agent.config` * `agent.config`
* <p> * <p>
* such as: * such as:
...@@ -150,7 +161,7 @@ public class SnifferConfigInitializer { ...@@ -150,7 +161,7 @@ public class SnifferConfigInitializer {
* *
* @return the config file {@link InputStream}, or null if not needEnhance. * @return the config file {@link InputStream}, or null if not needEnhance.
*/ */
private static void overrideConfigBySystemEnv() throws IllegalAccessException { private static void overrideConfigBySystemProp() throws IllegalAccessException {
Properties properties = new Properties(); Properties properties = new Properties();
Properties systemProperties = System.getProperties(); Properties systemProperties = System.getProperties();
Iterator<Map.Entry<Object, Object>> entryIterator = systemProperties.entrySet().iterator(); Iterator<Map.Entry<Object, Object>> entryIterator = systemProperties.entrySet().iterator();
......
...@@ -16,22 +16,33 @@ ...@@ -16,22 +16,33 @@
* *
*/ */
package org.apache.skywalking.apm.agent.core.conf; package org.apache.skywalking.apm.agent.core.conf;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import org.apache.skywalking.apm.agent.core.boot.AgentPackageNotFoundException; import org.apache.skywalking.apm.agent.core.boot.AgentPackageNotFoundException;
import org.apache.skywalking.apm.agent.core.logging.core.LogLevel; import org.apache.skywalking.apm.agent.core.logging.core.LogLevel;
import org.apache.skywalking.apm.util.ConfigInitializer;
import org.apache.skywalking.apm.util.PlaceholderConfigurerSupport;
import org.apache.skywalking.apm.util.PropertyPlaceholderHelper;
import org.junit.After; import org.junit.After;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.contrib.java.lang.system.EnvironmentVariables;
import java.util.Iterator;
import java.util.Map;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
public class SnifferConfigInitializerTest { public class SnifferConfigInitializerTest {
/**
* The EnvironmentVariables rule allows you to set environment variables for your test. All changes to environment
* variables are reverted after the test.
*/
@Rule
public final EnvironmentVariables environmentVariables = new EnvironmentVariables()
.set("AGENT_SERVICE_NAME", "testAppFromSystemEnv").set("AGENT_COLLECTOR_SERVER", "localhost:11111");
@Test @Test
public void testLoadConfigFromJavaAgentDir() throws AgentPackageNotFoundException, ConfigNotFoundException { public void testLoadConfigFromJavaAgentDir() throws AgentPackageNotFoundException, ConfigNotFoundException {
...@@ -64,6 +75,25 @@ public class SnifferConfigInitializerTest { ...@@ -64,6 +75,25 @@ public class SnifferConfigInitializerTest {
assertThat(Config.Logging.LEVEL, is(LogLevel.DEBUG)); assertThat(Config.Logging.LEVEL, is(LogLevel.DEBUG));
} }
@Test
public void testConfigOverridingFromSystemEnv() throws IllegalAccessException {
Properties properties = new Properties();
properties.put("agent.service_name", "${AGENT_SERVICE_NAME:testAppFromSystem}");
properties.put("collector.backend_service", "${AGENT_COLLECTOR_SERVER:127.0.0.1:8090}");
properties.put("logging.level", "INFO");
PropertyPlaceholderHelper placeholderHelper =
new PropertyPlaceholderHelper(PlaceholderConfigurerSupport.DEFAULT_PLACEHOLDER_PREFIX,
PlaceholderConfigurerSupport.DEFAULT_PLACEHOLDER_SUFFIX,
PlaceholderConfigurerSupport.DEFAULT_VALUE_SEPARATOR, true);
properties.put("agent.service_name", placeholderHelper.replacePlaceholders((String)properties.get("agent.service_name"), properties));
properties.put("collector.backend_service", placeholderHelper.replacePlaceholders((String)properties.get("collector.backend_service"), properties));
ConfigInitializer.initialize(properties, Config.class);
assertThat(Config.Agent.SERVICE_NAME, is("testAppFromSystemEnv"));
assertThat(Config.Collector.BACKEND_SERVICE, is("localhost:11111"));
assertThat(Config.Logging.LEVEL, is(LogLevel.INFO));
}
@Test @Test
public void testAgentOptionsSeparator() throws AgentPackageNotFoundException, ConfigNotFoundException { public void testAgentOptionsSeparator() throws AgentPackageNotFoundException, ConfigNotFoundException {
System.setProperty("skywalking.agent.service_name", "testApp"); System.setProperty("skywalking.agent.service_name", "testApp");
......
...@@ -15,31 +15,31 @@ ...@@ -15,31 +15,31 @@
# limitations under the License. # limitations under the License.
# The agent namespace # The agent namespace
# agent.namespace=default-namespace # agent.namespace=${SW_AGENT_NAMESPACE:default-namespace}
# The service name in UI # The service name in UI
agent.service_name=Your_ApplicationName agent.service_name=${SW_AGENT_NAME:Your_ApplicationName}
# The number of sampled traces per 3 seconds # The number of sampled traces per 3 seconds
# Negative number means sample traces as many as possible, most likely 100% # Negative number means sample traces as many as possible, most likely 100%
# agent.sample_n_per_3_secs=-1 # agent.sample_n_per_3_secs=${SW_AGENT_SAMPLE:-1}
# Authentication active is based on backend setting, see application.yml for more details. # Authentication active is based on backend setting, see application.yml for more details.
# agent.authentication = xxxx # agent.authentication = ${SW_AGENT_AUTHENTICATION:xxxx}
# The max amount of spans in a single segment. # The max amount of spans in a single segment.
# Through this config item, skywalking keep your application memory cost estimated. # Through this config item, skywalking keep your application memory cost estimated.
# agent.span_limit_per_segment=300 # agent.span_limit_per_segment=${SW_AGENT_SPAN_LIMIT:300}
# Ignore the segments if their operation names start with these suffix. # Ignore the segments if their operation names start with these suffix.
# agent.ignore_suffix=.jpg,.jpeg,.js,.css,.png,.bmp,.gif,.ico,.mp3,.mp4,.html,.svg # agent.ignore_suffix=${SW_AGENT_IGNORE_SUFFIX:.jpg,.jpeg,.js,.css,.png,.bmp,.gif,.ico,.mp3,.mp4,.html,.svg}
# If true, skywalking agent will save all instrumented classes files in `/debugging` folder. # If true, skywalking agent will save all instrumented classes files in `/debugging` folder.
# Skywalking team may ask for these files in order to resolve compatible problem. # Skywalking team may ask for these files in order to resolve compatible problem.
# agent.is_open_debugging_class = true # agent.is_open_debugging_class = ${SW_AGENT_OPEN_DEBUG:true}
# Backend service addresses. # Backend service addresses.
collector.backend_service=127.0.0.1:11800 collector.backend_service=${SW_AGENT_COLLECTOR_BACKEND_SERVICES:127.0.0.1:11800}
# Logging level # Logging level
logging.level=DEBUG logging.level=${SW_LOGGING_LEVEL:DEBUG}
...@@ -45,6 +45,36 @@ Add `-javaagent` argument to command line in which you start your app. eg: ...@@ -45,6 +45,36 @@ Add `-javaagent` argument to command line in which you start your app. eg:
```shell ```shell
java -javaagent:/path/to/skywalking-agent/skywalking-agent.jar -jar yourApp.jar java -javaagent:/path/to/skywalking-agent/skywalking-agent.jar -jar yourApp.jar
``` ```
## Table of Agent Configuration Properties
This is the properties list supported in `agent/config/agent.config`.
property key | Description | Default |
----------- | ---------- | --------- |
`agent.namespace` | Namespace isolates headers in cross process propagation. The HEADER name will be `HeaderName:Namespace`. | Not set |
`agent.service_name` | Application(5.x)/Service(6.x) code is showed in sky-walking-ui. Suggestion: set a unique name for each service, service instance nodes share the same code | `Your_ApplicationName` |
`agent.sample_n_per_3_secs`|Negative or zero means off, by default.SAMPLE_N_PER_3_SECS means sampling N TraceSegment in 3 seconds tops.|Not set|
`agent.authentication`|Authentication active is based on backend setting, see application.yml for more details.For most scenarios, this needs backend extensions, only basic match auth provided in default implementation.|Not set|
`agent.span_limit_per_segment`|The max number of spans in a single segment. Through this config item, skywalking keep your application memory cost estimated.|Not set |
`agent.ignore_suffix`|If the operation name of the first span is included in this set, this segment should be ignored.|Not set|
`agent.is_open_debugging_class`|If true, skywalking agent will save all instrumented classes files in `/debugging` folder.Skywalking team may ask for these files in order to resolve compatible problem.|Not set|
`agent.active_v2_header`|Active V2 header in default.|`true`|
`agent.active_v1_header `|Deactive V1 header in default.|`false`|
`collector.grpc_channel_check_interval`|grpc channel status check interval.|`30`|
`collector.app_and_service_register_check_interval`|application and service registry check interval.|`3`|
`collector.backend_service`|Collector skywalking trace receiver service addresses.|`127.0.0.1:11800`|
`logging.level`|The log level. Default is debug.|`DEBUG`|
`logging.file_name`|Log file name.|`skywalking-api.log`|
`logging.dir`|Log files directory. Default is blank string, means, use "system.out" to output logs.|`""`|
`logging.max_file_size`|The max size of log file. If the size is bigger than this, archive the current file, and write into a new file.|`300 * 1024 * 1024`|
`jvm.buffer_size`|The buffer size of collected JVM info.|`60 * 10`|
`buffer.channel_size`|The buffer channel size.|`5`|
`buffer.buffer_size`|The buffer size.|`300`|
`dictionary.service_code_buffer_size`|The buffer size of application codes and peer|`10 * 10000`|
`dictionary.endpoint_name_buffer_size`|The buffer size of endpoint names and peer|`1000 * 10000`|
`plugin.mongodb.trace_param`|If true, trace all the parameters in MongoDB access, default is false. Only trace the operation, not include parameters.|`false`|
`plugin.elasticsearch.trace_dsl`|If true, trace all the DSL(Domain Specific Language) in ElasticSearch access, default is false.|`false`|
## Supported middlewares, frameworks and libraries ## Supported middlewares, frameworks and libraries
See [supported list](Supported-list.md). See [supported list](Supported-list.md).
......
...@@ -43,7 +43,27 @@ Add the properties after the agent path in JVM arguments. ...@@ -43,7 +43,27 @@ Add the properties after the agent path in JVM arguments.
-javaagent:/path/to/skywalking-agent.jar=agent.ignore_suffix='.jpg,.jpeg' -javaagent:/path/to/skywalking-agent.jar=agent.ignore_suffix='.jpg,.jpeg'
``` ```
## System environment variables
- Example
Override `agent.application_code` and `logging.level` by this.
```
# The service name in UI
agent.service_name=${SW_AGENT_NAME:Your_ApplicationName}
# Logging level
logging.level=${SW_LOGGING_LEVEL:INFO}
```
If the `SW_AGENT_NAME ` environment variable exists in your operating system and its value is `skywalking-agent-demo`,
then the value of `agent.service_name` here will be overwritten to `skywalking-agent-demo`, otherwise, it will be set to `Your_ApplicationName`.
By the way, Placeholder nesting is also supported, like `${SW_AGENT_NAME:${ANOTHER_AGENT_NAME:Your_ApplicationName}}`.
In this case, if the `SW_AGENT_NAME ` environment variable not exists, but the ```ANOTHER_AGENT_NAME```
environment variable exists and its value is `skywalking-agent-demo`, then the value of `agent.service_name` here will be overwritten to `skywalking-agent-demo`,otherwise, it will be set to `Your_ApplicationName`.
## Override priority ## Override priority
Agent Options > System.Properties(-D) > Config file Agent Options > System.Properties(-D) > System environment variables > Config file
...@@ -29,6 +29,10 @@ ...@@ -29,6 +29,10 @@
<artifactId>library-util</artifactId> <artifactId>library-util</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<properties>
<ststem-rules.version>1.18.0</ststem-rules.version>
</properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>joda-time</groupId> <groupId>joda-time</groupId>
...@@ -43,7 +47,7 @@ ...@@ -43,7 +47,7 @@
<dependency> <dependency>
<groupId>com.github.stefanbirkner</groupId> <groupId>com.github.stefanbirkner</groupId>
<artifactId>system-rules</artifactId> <artifactId>system-rules</artifactId>
<version>1.18.0</version> <version>${ststem-rules.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
......
...@@ -36,16 +36,4 @@ public class StringUtils { ...@@ -36,16 +36,4 @@ public class StringUtils {
public static String getOrDefault(String value, String defaultValue) { public static String getOrDefault(String value, String defaultValue) {
return value == null ? defaultValue : value; return value == null ? defaultValue : value;
} }
public static boolean substringMatch(CharSequence str, int index, CharSequence substring) {
if (index + substring.length() > str.length()) {
return false;
}
for (int i = 0; i < substring.length(); i++) {
if (str.charAt(index + i) != substring.charAt(i)) {
return false;
}
}
return true;
}
} }
...@@ -22,6 +22,8 @@ import java.io.FileNotFoundException; ...@@ -22,6 +22,8 @@ import java.io.FileNotFoundException;
import java.io.Reader; import java.io.Reader;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import org.apache.skywalking.apm.util.PlaceholderConfigurerSupport;
import org.apache.skywalking.apm.util.PropertyPlaceholderHelper;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
......
...@@ -24,8 +24,8 @@ import java.util.Map; ...@@ -24,8 +24,8 @@ import java.util.Map;
import java.util.Properties; import java.util.Properties;
import org.apache.skywalking.oap.server.library.module.ApplicationConfiguration; import org.apache.skywalking.oap.server.library.module.ApplicationConfiguration;
import org.apache.skywalking.oap.server.library.util.CollectionUtils; import org.apache.skywalking.oap.server.library.util.CollectionUtils;
import org.apache.skywalking.oap.server.library.util.PlaceholderConfigurerSupport; import org.apache.skywalking.apm.util.PlaceholderConfigurerSupport;
import org.apache.skywalking.oap.server.library.util.PropertyPlaceholderHelper; import org.apache.skywalking.apm.util.PropertyPlaceholderHelper;
import org.apache.skywalking.oap.server.library.util.ResourceUtils; import org.apache.skywalking.oap.server.library.util.ResourceUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册