-
Notifications
You must be signed in to change notification settings - Fork 1k
Config property util cleanup #15809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zeitlinger
wants to merge
12
commits into
open-telemetry:main
Choose a base branch
from
zeitlinger:config-property-util-cleanup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Config property util cleanup #15809
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2ed8991
rename otel.javaagent.experimental.thread-propagation-debugger.enable…
zeitlinger c50acc5
create DeprecatedLibraryConfigPropertiesUtil
zeitlinger 376e9d1
rename otel.instrumentation.internal-reflection.enabled to otel.javaa…
zeitlinger c6172a6
fix
zeitlinger fae1b5d
fix
zeitlinger 605e7cf
fix
zeitlinger 6ff257c
fix
zeitlinger c305e0c
add otel.javaagent.internal-reflection.enabled
zeitlinger 508c0dc
rebase
zeitlinger 364451a
pr review
zeitlinger 7fd5dad
fix
zeitlinger 9467185
Merge branch 'main' into config-property-util-cleanup
zeitlinger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
106 changes: 106 additions & 0 deletions
106
.../io/opentelemetry/instrumentation/api/internal/DeprecatedLibraryConfigPropertiesUtil.java
This file contains hidden or 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,106 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.instrumentation.api.internal; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.Locale; | ||
| import java.util.stream.Collectors; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
| * This class is internal and is hence not for public use. Its APIs are unstable and can change at | ||
| * any time. | ||
| */ | ||
| public final class DeprecatedLibraryConfigPropertiesUtil { | ||
|
|
||
| /** | ||
| * Returns the boolean value of the given property name from system properties and environment | ||
| * variables. | ||
| * | ||
| * @deprecated allows library configuration via system properties and environment variables, which | ||
| * will be removed in 3.0. | ||
| */ | ||
| @Deprecated | ||
| public static boolean getBoolean(String propertyName, boolean defaultValue) { | ||
| Boolean value = getBoolean(propertyName); | ||
| return value == null ? defaultValue : value; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the boolean value of the given property name from system properties and environment | ||
| * variables. | ||
| * | ||
| * @deprecated allows library configuration via system properties and environment variables, which | ||
| * will be removed in 3.0. | ||
| */ | ||
| @Nullable | ||
| @Deprecated | ||
| public static Boolean getBoolean(String propertyName) { | ||
| String strValue = getString(propertyName); | ||
| return strValue == null ? null : Boolean.parseBoolean(strValue); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the string value of the given property name from system properties and environment | ||
| * variables. | ||
| * | ||
| * @deprecated allows library configuration via system properties and environment variables, which | ||
| * will be removed in 3.0. | ||
| */ | ||
| @Nullable | ||
| @Deprecated | ||
| private static String getString(String propertyName) { | ||
| String value = System.getProperty(propertyName); | ||
| if (value != null) { | ||
| return value; | ||
| } | ||
| return System.getenv(toEnvVarName(propertyName)); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the string value of the given property name from system properties and environment | ||
| * variables, or the default value if not found. | ||
| * | ||
| * @deprecated allows library configuration via system properties and environment variables, which | ||
| * will be removed in 3.0. | ||
| */ | ||
| @Deprecated | ||
| public static String getString(String propertyName, String defaultValue) { | ||
| String strValue = getString(propertyName); | ||
| return strValue == null ? defaultValue : strValue; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the list of strings value of the given property name from system properties and | ||
| * environment variables, or the default value if not found. The property value is expected to be | ||
| * a comma-separated list. | ||
| * | ||
| * @deprecated allows library configuration via system properties and environment variables, which | ||
| * will be removed in 3.0. | ||
| */ | ||
| @Deprecated | ||
| public static List<String> getList(String propertyName, List<String> defaultValue) { | ||
| String value = getString(propertyName); | ||
| if (value == null) { | ||
| return defaultValue; | ||
| } | ||
| return filterBlanksAndNulls(value.split(",")); | ||
| } | ||
|
|
||
| private static List<String> filterBlanksAndNulls(String[] values) { | ||
| return Arrays.stream(values) | ||
| .map(String::trim) | ||
| .filter(s -> !s.isEmpty()) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| private static String toEnvVarName(String propertyName) { | ||
| return propertyName.toUpperCase(Locale.ROOT).replace('-', '_').replace('.', '_'); | ||
| } | ||
|
|
||
| private DeprecatedLibraryConfigPropertiesUtil() {} | ||
| } | ||
This file contains hidden or 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
37 changes: 37 additions & 0 deletions
37
...opentelemetry/instrumentation/api/internal/DeprecatedLibraryConfigPropertiesUtilTest.java
This file contains hidden or 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,37 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.instrumentation.api.internal; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.junitpioneer.jupiter.SetEnvironmentVariable; | ||
| import org.junitpioneer.jupiter.SetSystemProperty; | ||
|
|
||
| @SuppressWarnings("deprecation") // using deprecated config property | ||
| class DeprecatedLibraryConfigPropertiesUtilTest { | ||
|
|
||
| @SetEnvironmentVariable(key = "TEST_PROPERTY_BOOLEAN", value = "false") | ||
| @SetSystemProperty(key = "test.property.boolean", value = "true") | ||
| @Test | ||
| void getBoolean_systemProperty() { | ||
| assertThat(DeprecatedLibraryConfigPropertiesUtil.getBoolean("test.property.boolean", false)) | ||
| .isTrue(); | ||
| } | ||
|
|
||
| @SetEnvironmentVariable(key = "TEST_PROPERTY_BOOLEAN", value = "true") | ||
| @Test | ||
| void getBoolean_environmentVariable() { | ||
| assertThat(DeprecatedLibraryConfigPropertiesUtil.getBoolean("test.property.boolean", false)) | ||
| .isTrue(); | ||
| } | ||
|
|
||
| @Test | ||
| void getBoolean_none() { | ||
| assertThat(DeprecatedLibraryConfigPropertiesUtil.getBoolean("test.property.boolean", false)) | ||
| .isFalse(); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see what we gain from this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it allows the methods to be deprecated - this has caused some confusion in a previous PR
@trask fyi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think things are getting clearer now and we could avoid the rename and instead deprecate it saying will be removed in 3.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a rename - the class is split to distinguish the cases that are deprecated from the ones we still need in the future (which are few, but it's still confusing to understand right now)