-
Couldn't load subscription status.
- Fork 913
Add getStructured default method, add empty StructuredConfigProperties #6759
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.sdk.autoconfigure.spi.internal; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| /** Empty instance of {@link StructuredConfigProperties}. */ | ||
| final class EmptyStructuredConfigProperties implements StructuredConfigProperties { | ||
|
|
||
| private static final EmptyStructuredConfigProperties INSTANCE = | ||
| new EmptyStructuredConfigProperties(); | ||
|
|
||
| private EmptyStructuredConfigProperties() {} | ||
|
|
||
| static EmptyStructuredConfigProperties getInstance() { | ||
| return INSTANCE; | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public String getString(String name) { | ||
| return null; | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public Boolean getBoolean(String name) { | ||
| return null; | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public Integer getInt(String name) { | ||
| return null; | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public Long getLong(String name) { | ||
| return null; | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public Double getDouble(String name) { | ||
| return null; | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public <T> List<T> getScalarList(String name, Class<T> scalarType) { | ||
| return null; | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public StructuredConfigProperties getStructured(String name) { | ||
| return null; | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public List<StructuredConfigProperties> getStructuredList(String name) { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public Set<String> getPropertyKeys() { | ||
| return Collections.emptySet(); | ||
|
Check warning on line 75 in sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/EmptyStructuredConfigProperties.java
|
||
| } | ||
| } | ||
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.
can you give an example of how you see this method being used?
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.
There's a demonstration here in the unit test:
I give the same example in the javadoc for the new
empty()method, but should probably copy it here as well.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.
Sorry, I meant specifically the list method, it's not clear to me if that variant is needed
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.
Ah sorry for misunderstanding.
At that point, it was just for completeness. Every other accessor has a "get or default" variant, and so it feels out of place for this one omission. Its true that it doesn't have utility for tree walking, but that doesn't mean it doesn't have utility at all. For example, this code for interpreting OTLP headers could be simplified to:
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.
good point, I hadn't thought about the existing methods already having the default variant