-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the order of configuration file application (open-telemetry#6697)
Fixes open-telemetry#6696
- Loading branch information
Showing
6 changed files
with
87 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
.../src/test/java/io/opentelemetry/javaagent/tooling/config/ConfigurationFileLoaderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.tooling.config; | ||
|
||
import static java.util.Collections.singleton; | ||
import static java.util.Collections.singletonMap; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import io.opentelemetry.api.GlobalOpenTelemetry; | ||
import io.opentelemetry.javaagent.tooling.OpenTelemetryInstaller; | ||
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk; | ||
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizer; | ||
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
import org.junitpioneer.jupiter.ClearSystemProperty; | ||
import org.junitpioneer.jupiter.SetSystemProperty; | ||
|
||
@ClearSystemProperty(key = ConfigurationFileLoader.CONFIGURATION_FILE_PROPERTY) | ||
class ConfigurationFileLoaderTest { | ||
|
||
@BeforeAll | ||
@AfterAll | ||
static void cleanUp() { | ||
GlobalOpenTelemetry.resetForTest(); | ||
} | ||
|
||
// regression for https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/6696 | ||
@SetSystemProperty(key = "otel.experimental.sdk.enabled", value = "false") // don't setup the SDK | ||
@Test | ||
void fileConfigOverwritesUserPropertiesSupplier(@TempDir Path tempDir) throws IOException { | ||
// given | ||
Path configFile = tempDir.resolve("test-config.properties"); | ||
Files.write(configFile, singleton("custom.key = 42")); | ||
System.setProperty(ConfigurationFileLoader.CONFIGURATION_FILE_PROPERTY, configFile.toString()); | ||
|
||
// when | ||
AutoConfiguredOpenTelemetrySdk autoConfiguredSdk = | ||
OpenTelemetryInstaller.installOpenTelemetrySdk(); | ||
|
||
// then | ||
assertThat(autoConfiguredSdk.getConfig().getString("custom.key")).isEqualTo("42"); | ||
} | ||
|
||
// SPI used in test | ||
public static class UserCustomPropertiesSupplier implements AutoConfigurationCustomizerProvider { | ||
|
||
@Override | ||
public void customize(AutoConfigurationCustomizer autoConfiguration) { | ||
autoConfiguration.addPropertiesSupplier(() -> singletonMap("custom.key", "123")); | ||
} | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
...A-INF/services/io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
io.opentelemetry.javaagent.tooling.config.ConfigurationFileLoader | ||
io.opentelemetry.javaagent.tooling.config.ConfigurationFileLoaderTest$UserCustomPropertiesSupplier |