Because of key issue, system env override can't be supported. (#1017)
* Because of key issue, system env override can't be supported. * Override value only in supported types. Int, String, Long, Boolean.
This commit is contained in:
parent
56c11d4020
commit
90fb7b7149
|
|
@ -109,10 +109,6 @@ public class ApplicationConfigLoader implements ConfigLoader<ApplicationConfigur
|
|||
overrideModuleSettings(configuration, prop.getKey().toString(), prop.getValue().toString(), true);
|
||||
}
|
||||
|
||||
Map<String, String> envs = System.getenv();
|
||||
for (String envKey : envs.keySet()) {
|
||||
overrideModuleSettings(configuration, envKey, envs.get(envKey), false);
|
||||
}
|
||||
}
|
||||
|
||||
private void overrideModuleSettings(ApplicationConfiguration configuration, String key, String value,
|
||||
|
|
@ -137,7 +133,23 @@ public class ApplicationConfigLoader implements ConfigLoader<ApplicationConfigur
|
|||
return;
|
||||
}
|
||||
Properties providerSettings = moduleConfiguration.getProviderConfiguration(providerName);
|
||||
providerSettings.put(settingKey, value);
|
||||
if (!providerSettings.containsKey(settingKey)) {
|
||||
return;
|
||||
}
|
||||
Object originValue = providerSettings.get(settingKey);
|
||||
Class<?> type = originValue.getClass();
|
||||
if (type.equals(int.class) || type.equals(Integer.class))
|
||||
providerSettings.put(settingKey, Integer.valueOf(value));
|
||||
else if (type.equals(String.class))
|
||||
providerSettings.put(settingKey, value);
|
||||
else if (type.equals(long.class) || type.equals(Long.class))
|
||||
providerSettings.put(settingKey, Long.valueOf(value));
|
||||
else if (type.equals(boolean.class) || type.equals(Boolean.class)) {
|
||||
providerSettings.put(settingKey, Boolean.valueOf(value));
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info("The setting has been override by key: {}, value: {}, in {} provider of {} module through {}",
|
||||
settingKey, value, providerName, moduleName, isSystemProperty ? "System.properties" : "System.envs");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,14 +105,6 @@ public class SnifferConfigInitializer {
|
|||
}
|
||||
}
|
||||
|
||||
Map<String, String> envs = System.getenv();
|
||||
for (String envKey : envs.keySet()) {
|
||||
if (envKey.startsWith(ENV_KEY_PREFIX)) {
|
||||
String realKey = envKey.substring(ENV_KEY_PREFIX.length());
|
||||
properties.setProperty(realKey, envs.get(envKey));
|
||||
}
|
||||
}
|
||||
|
||||
if (!properties.isEmpty()) {
|
||||
ConfigInitializer.initialize(properties, Config.class);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,10 +7,10 @@ _Agent setting override supported since 3.2.5_
|
|||
## What is setting override?
|
||||
In default, SkyWalking provide `agent.config` for client, and `application.yml` for server settings.
|
||||
|
||||
Setting override means end user can override the settings in these config file, by using system properties, or system environment variables.
|
||||
Setting override means end user can override the settings in these config file, by using system properties.
|
||||
|
||||
## Override priority
|
||||
System.Env > System.Properties(-D) > Config file
|
||||
System.Properties(-D) > Config file
|
||||
|
||||
## Override
|
||||
### Agent
|
||||
|
|
@ -21,4 +21,18 @@ Use `skywalking.` + key in config file as system properties and envs key, to ove
|
|||
The agent system properites and env share with target application, this prefix can avoid variable conflict.
|
||||
|
||||
### Collector
|
||||
Use key in config file as system properties and envs key, to override the value.
|
||||
Use key in config file as system properties and envs key, to override the value.
|
||||
|
||||
Example:
|
||||
- Setting in `application.yml`
|
||||
```yaml
|
||||
agent_gRPC:
|
||||
gRPC:
|
||||
host: localhost
|
||||
port: 11800
|
||||
```
|
||||
|
||||
- Override port to 31200 by system property, add the following line into startup script.
|
||||
```
|
||||
-Dagent_gRPC.gRPC.port=31200
|
||||
```
|
||||
Loading…
Reference in New Issue