Skip to content
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

DefaultConfigProperties#getMap filters entries with blank values intead of throwing #5784

Merged
merged 2 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ default List<String> getList(String name, List<String> defaultValue) {
/**
* Returns a Map configuration property. The format of the original value must be comma-separated
* for each key, with an '=' separating the key and value. For instance, <code>
* service.name=Greatest Service,host.name=localhost</code> Empty values will be removed.
* service.name=Greatest Service,host.name=localhost</code>. Empty values will be removed.
*
* @return an empty map if the property has not been configured.
* @throws ConfigurationException for malformed map strings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ public static Set<String> getSet(ConfigProperties config, String name) {
public Map<String, String> getMap(String name) {
return getList(ConfigUtil.normalizePropertyKey(name)).stream()
.map(keyValuePair -> filterBlanksAndNulls(keyValuePair.split("=", 2)))
// Filter entries with an empty value, i.e. "foo="
.filter(splitKeyValuePairs -> !(splitKeyValuePairs.size() == 1))
jack-berg marked this conversation as resolved.
Show resolved Hide resolved
.map(
splitKeyValuePairs -> {
if (splitKeyValuePairs.size() != 2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class ResourceConfigurationTest {
void customConfigResource() {
Map<String, String> props = new HashMap<>();
props.put("otel.service.name", "test-service");
props.put("otel.resource.attributes", "food=cheesecake,drink=juice");
props.put(
"otel.resource.attributes", "food=cheesecake,drink=juice,animal= ,color=,shape=square");
props.put("otel.experimental.resource.disabled-keys", "drink");

assertThat(
Expand All @@ -42,6 +43,7 @@ void customConfigResource() {
Resource.getDefault().toBuilder()
.put(ResourceAttributes.SERVICE_NAME, "test-service")
.put("food", "cheesecake")
.put("shape", "square")
.setSchemaUrl(ResourceAttributes.SCHEMA_URL)
.build());
}
Expand Down