Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
* 1. The default agent configuration located under the agent-distribution/conf
* 2. The external configuration specified via -Dbithon.configuration.location command line argument
* 3. All parameters defined by -Dbithon.xxx
* 4. All environment variables starting with bithon_
* 4. All environment variables starting with BITHON_
* 5. Dynamic configuration from the remote controller
*
* Different configuration sources may contain the same property keys,
Expand Down Expand Up @@ -124,7 +124,7 @@ static ConfigurationManager create(File defaultConfigLocation) {
return new ConfigurationManager(PropertySource.from(PropertySourceType.INTERNAL, defaultConfigLocation, true),
ExternalSource.build(),
CommandLineArgsSource.build("bithon."),
EnvironmentSource.build("bithon_"));
EnvironmentSource.build("BITHON_"));
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can keep the lower case for compatibility.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that the case of environment variables should not be strictly enforced. It is only necessary to ensure that the environment variables can be recognized, regardless of whether they are in uppercase or lowercase

}

// Sorted in priority
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.bithon.agent.instrumentation.expt.AgentException;

import java.io.IOException;
import java.util.Locale;
import java.util.Map;

/**
Expand All @@ -31,9 +32,10 @@ public static PropertySource build(String envPrefix) {
StringBuilder propertyText = new StringBuilder();

for (Map.Entry<String, String> entry : Helper.getEnvironmentVariables().entrySet()) {
String name = entry.getKey();
String name = entry.getKey().toLowerCase(Locale.ENGLISH);
String value = entry.getValue();
if (name.startsWith(envPrefix) && !value.isEmpty()) {
String prefix = envPrefix.toLowerCase(Locale.ENGLISH);
if (name.startsWith(prefix) && !value.isEmpty()) {
name = name.substring(envPrefix.length())
// For env, the underscore is used as a replacement of '.' character,
// Here we need to convert these characters back
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ public void test_Environment() {
));

configurationMock.when(Helper::getEnvironmentVariables)
.thenReturn(ImmutableMap.of("bithon_t", "t1",
"bithon_test_prop", "from_env"));
.thenReturn(ImmutableMap.of("BITHON_T", "t1",
"BITHON_TEST_PROP", "from_env"));

ConfigurationManager manager = ConfigurationManager.create(defaultConfigLocation);

Expand All @@ -201,6 +201,33 @@ public void test_Environment() {
}
}

@Test
public void test_Environment_CaseCompatibility() {
try (MockedStatic<Helper> configurationMock = Mockito.mockStatic(Helper.class)) {
configurationMock.when(Helper::getCommandLineInputArgs)
.thenReturn(Arrays.asList("-Xms512M",
// A property without assignment
// to verify the processing is correct with such configuration
"-Dbithon.test",
// Override the in file configuration
"-Dbithon.test.prop=from_command_line",

// Also set the external configuration
"-Dbithon.configuration.location=" + externalConfigLocation
));

configurationMock.when(Helper::getEnvironmentVariables)
.thenReturn(ImmutableMap.of("bithon_t", "t1",
"bithon_test_prop", "from_env"));

ConfigurationManager manager = ConfigurationManager.create(defaultConfigLocation);

TestProp config = manager.getConfig(TestProp.class);
Assert.assertEquals("from_env", config.getProp());
}
}


static class TwoProps {
private String prop1;
private String prop2;
Expand Down Expand Up @@ -238,9 +265,9 @@ public void test_PropFromDifferentSource() {
));

configurationMock.when(Helper::getEnvironmentVariables)
.thenReturn(ImmutableMap.of("bithon_t", "t1",
.thenReturn(ImmutableMap.of("BITHON_T", "t1",
//Overwrite the prop2
"bithon_test_prop2", "from_env"));
"BITHON_TEST_PROP2", "from_env"));

ConfigurationManager manager = ConfigurationManager.create(defaultConfigLocation);

Expand Down
8 changes: 4 additions & 4 deletions doc/configuration/agent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ java -Dbithon.application.name=bithon-server -Dbithon.application.env=local -jar

## Environment variables

Configurations can also be set by environment variables. This is helpful when the agent is loaded in docker environment.
Configurations can also be set by environment variables. This is helpful when the agent is loaded in docker/container environment.

```text
export bithon_application_name=bithon-server
export bithon_application_env=local
export BITHON_APPLICATION_NAME=bithon-server
export BITHON_APPLICATION_ENV=local
java -jar bithon-server.jar
```

Note that all environment variables are in underscore mode.
Note that all environment variables are in underscore mode and uppercase.

## Dynamic Configuration

Expand Down