-
Notifications
You must be signed in to change notification settings - Fork 954
Fix/declarative config no exceptions #8079
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
Bhagirath00
wants to merge
4
commits into
open-telemetry:main
Choose a base branch
from
Bhagirath00:fix/declarative-config-no-exceptions
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
df9a72b
Implement Environment Variable Context Propagation carriers in api/in…
Bhagirath00 6eed41c
Update DeclarativeConfigProperties to return null on type mismatch
Bhagirath00 2012cd9
Address feedback: clean up branch and improve safety in DeclarativeCo…
Bhagirath00 153c5d1
Improve null check messages for config property name and default value
Bhagirath00 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |||
| import io.opentelemetry.common.ComponentLoader; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| import java.util.Objects; | ||||
| import java.util.Set; | ||||
| import javax.annotation.Nullable; | ||||
|
|
||||
|
|
@@ -46,8 +47,8 @@ static Map<String, Object> toMap(DeclarativeConfigProperties declarativeConfigPr | |||
| /** | ||||
| * Returns a {@link String} configuration property. | ||||
| * | ||||
| * @return null if the property has not been configured | ||||
| * @throws DeclarativeConfigException if the property is not a valid scalar string | ||||
| * @return null if the property has not been configured or if the property is not a valid scalar | ||||
| * string | ||||
| */ | ||||
| @Nullable | ||||
| String getString(String name); | ||||
|
|
@@ -56,19 +57,19 @@ static Map<String, Object> toMap(DeclarativeConfigProperties declarativeConfigPr | |||
| * Returns a {@link String} configuration property. | ||||
| * | ||||
| * @return a {@link String} configuration property or {@code defaultValue} if a property with | ||||
| * {@code name} has not been configured | ||||
| * @throws DeclarativeConfigException if the property is not a valid scalar string | ||||
| * {@code name} has not been configured or is not a valid scalar string | ||||
| */ | ||||
| default String getString(String name, String defaultValue) { | ||||
| Objects.requireNonNull(defaultValue, "Null default value"); | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to be clear, I'm recommending we pull this until #8173 is resolved. The YamlDeclarativeConfigProperties null checks are fine, since that's where I think our guidance ends up
Suggested change
|
||||
| return defaultIfNull(getString(name), defaultValue); | ||||
| } | ||||
|
|
||||
| /** | ||||
| * Returns a {@link Boolean} configuration property. Implementations should use the same rules as | ||||
| * {@link Boolean#parseBoolean(String)} for handling the values. | ||||
| * | ||||
| * @return null if the property has not been configured | ||||
| * @throws DeclarativeConfigException if the property is not a valid scalar boolean | ||||
| * @return null if the property has not been configured or if the property is not a valid scalar | ||||
| * boolean | ||||
| */ | ||||
| @Nullable | ||||
| Boolean getBoolean(String name); | ||||
|
|
@@ -77,8 +78,7 @@ default String getString(String name, String defaultValue) { | |||
| * Returns a {@link Boolean} configuration property. | ||||
| * | ||||
| * @return a {@link Boolean} configuration property or {@code defaultValue} if a property with | ||||
| * {@code name} has not been configured | ||||
| * @throws DeclarativeConfigException if the property is not a valid scalar boolean | ||||
| * {@code name} has not been configured or is not a valid scalar boolean | ||||
| */ | ||||
| default boolean getBoolean(String name, boolean defaultValue) { | ||||
| return defaultIfNull(getBoolean(name), defaultValue); | ||||
|
|
@@ -90,8 +90,8 @@ default boolean getBoolean(String name, boolean defaultValue) { | |||
| * <p>If the underlying config property is {@link Long}, it is converted to {@link Integer} with | ||||
| * {@link Long#intValue()} which may result in loss of precision. | ||||
| * | ||||
| * @return null if the property has not been configured | ||||
| * @throws DeclarativeConfigException if the property is not a valid scalar integer | ||||
| * @return null if the property has not been configured or if the property is not a valid scalar | ||||
| * integer | ||||
| */ | ||||
| @Nullable | ||||
| Integer getInt(String name); | ||||
|
|
@@ -103,8 +103,7 @@ default boolean getBoolean(String name, boolean defaultValue) { | |||
| * {@link Long#intValue()} which may result in loss of precision. | ||||
| * | ||||
| * @return a {@link Integer} configuration property or {@code defaultValue} if a property with | ||||
| * {@code name} has not been configured | ||||
| * @throws DeclarativeConfigException if the property is not a valid scalar integer | ||||
| * {@code name} has not been configured or is not a valid scalar integer | ||||
| */ | ||||
| default int getInt(String name, int defaultValue) { | ||||
| return defaultIfNull(getInt(name), defaultValue); | ||||
|
|
@@ -113,8 +112,8 @@ default int getInt(String name, int defaultValue) { | |||
| /** | ||||
| * Returns a {@link Long} configuration property. | ||||
| * | ||||
| * @return null if the property has not been configured | ||||
| * @throws DeclarativeConfigException if the property is not a valid scalar long | ||||
| * @return null if the property has not been configured or if the property is not a valid scalar | ||||
| * long | ||||
| */ | ||||
| @Nullable | ||||
| Long getLong(String name); | ||||
|
|
@@ -123,8 +122,7 @@ default int getInt(String name, int defaultValue) { | |||
| * Returns a {@link Long} configuration property. | ||||
| * | ||||
| * @return a {@link Long} configuration property or {@code defaultValue} if a property with {@code | ||||
| * name} has not been configured | ||||
| * @throws DeclarativeConfigException if the property is not a valid scalar long | ||||
| * name} has not been configured or is not a valid scalar long | ||||
| */ | ||||
| default long getLong(String name, long defaultValue) { | ||||
| return defaultIfNull(getLong(name), defaultValue); | ||||
|
|
@@ -133,8 +131,8 @@ default long getLong(String name, long defaultValue) { | |||
| /** | ||||
| * Returns a {@link Double} configuration property. | ||||
| * | ||||
| * @return null if the property has not been configured | ||||
| * @throws DeclarativeConfigException if the property is not a valid scalar double | ||||
| * @return null if the property has not been configured or if the property is not a valid scalar | ||||
| * double | ||||
| */ | ||||
| @Nullable | ||||
| Double getDouble(String name); | ||||
|
|
@@ -143,8 +141,7 @@ default long getLong(String name, long defaultValue) { | |||
| * Returns a {@link Double} configuration property. | ||||
| * | ||||
| * @return a {@link Double} configuration property or {@code defaultValue} if a property with | ||||
| * {@code name} has not been configured | ||||
| * @throws DeclarativeConfigException if the property is not a valid scalar double | ||||
| * {@code name} has not been configured or is not a valid scalar double | ||||
| */ | ||||
| default double getDouble(String name, double defaultValue) { | ||||
| return defaultIfNull(getDouble(name), defaultValue); | ||||
|
|
@@ -158,8 +155,8 @@ default double getDouble(String name, double defaultValue) { | |||
| * @param scalarType the scalar type, one of {@link String}, {@link Boolean}, {@link Long} or | ||||
| * {@link Double} | ||||
| * @return a {@link List} configuration property, or null if the property has not been configured | ||||
| * @throws DeclarativeConfigException if the property is not a valid sequence of scalars, or if | ||||
| * {@code scalarType} is not supported | ||||
| * or if the property is not a valid sequence of scalars | ||||
| * @throws DeclarativeConfigException if {@code scalarType} is not supported | ||||
| */ | ||||
| @Nullable | ||||
| <T> List<T> getScalarList(String name, Class<T> scalarType); | ||||
|
|
@@ -172,8 +169,7 @@ default double getDouble(String name, double defaultValue) { | |||
| * @param scalarType the scalar type, one of {@link String}, {@link Boolean}, {@link Long} or | ||||
| * {@link Double} | ||||
| * @return a {@link List} configuration property or {@code defaultValue} if a property with {@code | ||||
| * name} has not been configured | ||||
| * @throws DeclarativeConfigException if the property is not a valid sequence of scalars | ||||
| * name} has not been configured or is not a valid sequence of scalars | ||||
| */ | ||||
| default <T> List<T> getScalarList(String name, Class<T> scalarType, List<T> defaultValue) { | ||||
| return defaultIfNull(getScalarList(name, scalarType), defaultValue); | ||||
|
|
@@ -183,8 +179,7 @@ default <T> List<T> getScalarList(String name, Class<T> scalarType, List<T> defa | |||
| * Returns a {@link DeclarativeConfigProperties} configuration property. | ||||
| * | ||||
| * @return a map-valued configuration property, or {@code null} if {@code name} has not been | ||||
| * configured | ||||
| * @throws DeclarativeConfigException if the property is not a mapping | ||||
| * configured or is not a mapping | ||||
| */ | ||||
| @Nullable | ||||
| DeclarativeConfigProperties getStructured(String name); | ||||
|
|
@@ -193,8 +188,7 @@ default <T> List<T> getScalarList(String name, Class<T> scalarType, List<T> defa | |||
| * Returns a list of {@link DeclarativeConfigProperties} configuration property. | ||||
| * | ||||
| * @return a map-valued configuration property, or {@code defaultValue} if {@code name} has not | ||||
| * been configured | ||||
| * @throws DeclarativeConfigException if the property is not a mapping | ||||
| * been configured or is not a mapping | ||||
| */ | ||||
| default DeclarativeConfigProperties getStructured( | ||||
| String name, DeclarativeConfigProperties defaultValue) { | ||||
|
|
@@ -210,8 +204,7 @@ default DeclarativeConfigProperties getStructured( | |||
| * but empty vs. not set, use {@link #getStructured(String)}. | ||||
| * | ||||
| * @return a map-valued configuration property, or an empty {@link DeclarativeConfigProperties} | ||||
| * instance if {@code name} has not been configured | ||||
| * @throws DeclarativeConfigException if the property is not a mapping | ||||
| * instance if {@code name} has not been configured or is not a mapping | ||||
| */ | ||||
| default DeclarativeConfigProperties get(String name) { | ||||
| return getStructured(name, empty()); | ||||
|
|
@@ -221,8 +214,7 @@ default DeclarativeConfigProperties get(String name) { | |||
| * Returns a list of {@link DeclarativeConfigProperties} configuration property. | ||||
| * | ||||
| * @return a list of map-valued configuration property, or {@code null} if {@code name} has not | ||||
| * been configured | ||||
| * @throws DeclarativeConfigException if the property is not a sequence of mappings | ||||
| * been configured or is not a sequence of mappings | ||||
| */ | ||||
| @Nullable | ||||
| List<DeclarativeConfigProperties> getStructuredList(String name); | ||||
|
|
@@ -231,8 +223,7 @@ default DeclarativeConfigProperties get(String name) { | |||
| * Returns a list of {@link DeclarativeConfigProperties} configuration property. | ||||
| * | ||||
| * @return a list of map-valued configuration property, or {@code defaultValue} if {@code name} | ||||
| * has not been configured | ||||
| * @throws DeclarativeConfigException if the property is not a sequence of mappings | ||||
| * has not been configured or is not a sequence of mappings | ||||
| */ | ||||
| default List<DeclarativeConfigProperties> getStructuredList( | ||||
| String name, List<DeclarativeConfigProperties> defaultValue) { | ||||
|
|
||||
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.
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.
For consistency I'd recommend adding here also:
Objects.requireNonNull(defaultValue, "Null default value");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.
Makes sense, added the null check for
defaultValuetoo.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.
We need to get consistent about whether or not we do this. We rely on
javax.annotation.Nullableannotation, the assumption that params and returns are non-null unless otherwise specified, leveraging thenet.ltgt.nullawayerror prone plugin to validate at build time. Of course, at runtime there is no guarantee that callers adhere to these annotations, and so we have code like this which checks for null despite the params being non-null according to the annotations.We need to be consistent about:
Let's hold off here until we get some repo level guidance on this. ConfigProperties, the env var / sys property analog of
DeclarativeConfigProperties, has the exact same method and does not do this null check.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.
Created #8173 to track.