Rename ConfigProperties.getList / getMap. (#3593)

This commit is contained in:
Anuraag Agrawal 2021-09-10 11:33:01 +09:00 committed by GitHub
parent ece161f6e0
commit 856a9955e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 29 additions and 31 deletions

View File

@ -3,16 +3,16 @@ Comparing source compatibility of against
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.lang.Boolean getBoolean(java.lang.String)
+++ NEW ANNOTATION: javax.annotation.Nullable
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.util.Map getCommaSeparatedMap(java.lang.String)
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.util.List getCommaSeparatedValues(java.lang.String)
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.lang.Double getDouble(java.lang.String)
+++ NEW ANNOTATION: javax.annotation.Nullable
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.time.Duration getDuration(java.lang.String)
+++ NEW ANNOTATION: javax.annotation.Nullable
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.lang.Integer getInt(java.lang.String)
+++ NEW ANNOTATION: javax.annotation.Nullable
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.util.List getList(java.lang.String)
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.lang.Long getLong(java.lang.String)
+++ NEW ANNOTATION: javax.annotation.Nullable
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.util.Map getMap(java.lang.String)
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.lang.String getString(java.lang.String)
+++ NEW ANNOTATION: javax.annotation.Nullable
+++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.autoconfigure.spi.ConfigurablePropagatorProvider (not serializable)

View File

@ -90,7 +90,7 @@ public interface ConfigProperties {
* @return an empty list if the property has not been configured.
* @throws ConfigurationException if the property is not a valid comma-separated list.
*/
List<String> getCommaSeparatedValues(String name);
List<String> getList(String name);
/**
* Returns a map-valued configuration property. The format of the original value must be
@ -100,5 +100,5 @@ public interface ConfigProperties {
* @return an empty map if the property has not been configured.
* @throws ConfigurationException for malformed map strings.
*/
Map<String, String> getCommaSeparatedMap(String name);
Map<String, String> getMap(String name);
}

View File

@ -143,7 +143,7 @@ final class DefaultConfigProperties implements ConfigProperties {
}
@Override
public List<String> getCommaSeparatedValues(String name) {
public List<String> getList(String name) {
String value = config.get(name);
if (value == null) {
return Collections.emptyList();
@ -152,8 +152,8 @@ final class DefaultConfigProperties implements ConfigProperties {
}
@Override
public Map<String, String> getCommaSeparatedMap(String name) {
return getCommaSeparatedValues(name).stream()
public Map<String, String> getMap(String name) {
return getList(name).stream()
.map(keyValuePair -> filterBlanksAndNulls(keyValuePair.split("=", 2)))
.map(
splitKeyValuePairs -> {

View File

@ -38,7 +38,7 @@ public final class EnvironmentResource {
// visible for testing
static Attributes getAttributes(ConfigProperties configProperties) {
AttributesBuilder resourceAttributes = Attributes.builder();
configProperties.getCommaSeparatedMap(ATTRIBUTE_PROPERTY).forEach(resourceAttributes::put);
configProperties.getMap(ATTRIBUTE_PROPERTY).forEach(resourceAttributes::put);
String serviceName = configProperties.getString(SERVICE_NAME_PROPERTY);
if (serviceName != null) {
resourceAttributes.put(ResourceAttributes.SERVICE_NAME, serviceName);

View File

@ -36,7 +36,7 @@ public final class OpenTelemetryResourceAutoConfiguration {
// otel.java.disabled.resource-providers. But fetching by the dot version is the simplest way
// to implement it for now.
Set<String> disabledProviders =
new HashSet<>(config.getCommaSeparatedValues("otel.java.disabled.resource.providers"));
new HashSet<>(config.getList("otel.java.disabled.resource.providers"));
for (ResourceProvider resourceProvider : ServiceLoader.load(ResourceProvider.class)) {
if (disabledProviders.contains(resourceProvider.getClass().getName())) {
continue;

View File

@ -44,10 +44,9 @@ final class OtlpConfigUtil {
setEndpoint.accept(endpoint);
}
Map<String, String> headers =
config.getCommaSeparatedMap("otel.exporter.otlp." + dataType + ".headers");
Map<String, String> headers = config.getMap("otel.exporter.otlp." + dataType + ".headers");
if (headers.isEmpty()) {
headers = config.getCommaSeparatedMap("otel.exporter.otlp.headers");
headers = config.getMap("otel.exporter.otlp.headers");
}
headers.forEach(addHeader);

View File

@ -22,7 +22,7 @@ final class PropagatorConfiguration {
static ContextPropagators configurePropagators(ConfigProperties config) {
Set<TextMapPropagator> propagators = new LinkedHashSet<>();
List<String> requestedPropagators = config.getCommaSeparatedValues("otel.propagators");
List<String> requestedPropagators = config.getList("otel.propagators");
if (requestedPropagators.isEmpty()) {
requestedPropagators = Arrays.asList("tracecontext", "baggage");
}

View File

@ -38,7 +38,7 @@ final class SpanExporterConfiguration {
// Visible for testing
static Map<String, SpanExporter> configureSpanExporters(ConfigProperties config) {
List<String> exporterNamesList = config.getCommaSeparatedValues("otel.traces.exporter");
List<String> exporterNamesList = config.getList("otel.traces.exporter");
Set<String> exporterNames = new HashSet<>(exporterNamesList);
if (exporterNamesList.size() != exporterNames.size()) {
String duplicates =

View File

@ -35,8 +35,8 @@ class ConfigPropertiesTest {
assertThat(config.getInt("int")).isEqualTo(10);
assertThat(config.getLong("long")).isEqualTo(20);
assertThat(config.getDouble("double")).isEqualTo(5.4);
assertThat(config.getCommaSeparatedValues("list")).containsExactly("cat", "dog", "bear");
assertThat(config.getCommaSeparatedMap("map"))
assertThat(config.getList("list")).containsExactly("cat", "dog", "bear");
assertThat(config.getMap("map"))
.containsExactly(entry("cat", "meow"), entry("dog", "bark"), entry("bear", "growl"));
assertThat(config.getDuration("duration")).isEqualTo(Duration.ofSeconds(1));
}
@ -48,8 +48,8 @@ class ConfigPropertiesTest {
assertThat(config.getInt("int")).isNull();
assertThat(config.getLong("long")).isNull();
assertThat(config.getDouble("double")).isNull();
assertThat(config.getCommaSeparatedValues("list")).isEmpty();
assertThat(config.getCommaSeparatedMap("map")).isEmpty();
assertThat(config.getList("list")).isEmpty();
assertThat(config.getMap("map")).isEmpty();
assertThat(config.getDuration("duration")).isNull();
}
@ -69,8 +69,8 @@ class ConfigPropertiesTest {
assertThat(config.getInt("int")).isNull();
assertThat(config.getLong("long")).isNull();
assertThat(config.getDouble("double")).isNull();
assertThat(config.getCommaSeparatedValues("list")).isEmpty();
assertThat(config.getCommaSeparatedMap("map")).isEmpty();
assertThat(config.getList("list")).isEmpty();
assertThat(config.getMap("map")).isEmpty();
assertThat(config.getDuration("duration")).isNull();
}
@ -129,7 +129,7 @@ class ConfigPropertiesTest {
assertThat(
DefaultConfigProperties.createForTest(
Collections.singletonMap("list", " a ,b,c , d,, ,"))
.getCommaSeparatedValues("list"))
.getList("list"))
.containsExactly("a", "b", "c", "d");
}
@ -138,7 +138,7 @@ class ConfigPropertiesTest {
assertThat(
DefaultConfigProperties.createForTest(
Collections.singletonMap("map", " a=1 ,b=2,c = 3 , d= 4,, ,"))
.getCommaSeparatedMap("map"))
.getMap("map"))
.containsExactly(entry("a", "1"), entry("b", "2"), entry("c", "3"), entry("d", "4"));
}
@ -147,19 +147,19 @@ class ConfigPropertiesTest {
assertThatThrownBy(
() ->
DefaultConfigProperties.createForTest(Collections.singletonMap("map", "a=1,b="))
.getCommaSeparatedMap("map"))
.getMap("map"))
.isInstanceOf(ConfigurationException.class)
.hasMessage("Invalid map property: map=a=1,b=");
assertThatThrownBy(
() ->
DefaultConfigProperties.createForTest(Collections.singletonMap("map", "a=1,b"))
.getCommaSeparatedMap("map"))
.getMap("map"))
.isInstanceOf(ConfigurationException.class)
.hasMessage("Invalid map property: map=a=1,b");
assertThatThrownBy(
() ->
DefaultConfigProperties.createForTest(Collections.singletonMap("map", "a=1,=b"))
.getCommaSeparatedMap("map"))
.getMap("map"))
.isInstanceOf(ConfigurationException.class)
.hasMessage("Invalid map property: map=a=1,=b");
}

View File

@ -31,8 +31,7 @@ class ResourceTest {
@Test
void customConfigResource() {
when(config.getString("otel.service.name")).thenReturn("test-service");
when(config.getCommaSeparatedMap("otel.resource.attributes"))
.thenReturn(singletonMap("food", "cheesecake"));
when(config.getMap("otel.resource.attributes")).thenReturn(singletonMap("food", "cheesecake"));
assertThat(OpenTelemetryResourceAutoConfiguration.configureResource(config))
.isEqualTo(

View File

@ -26,12 +26,12 @@ public class JaegerRemoteSamplerProvider implements ConfigurableSamplerProvider
public Sampler createSampler(ConfigProperties config) {
String serviceName = config.getString(SERVICE_NAME_PROPERTY);
if (serviceName == null) {
Map<String, String> resourceAttributes = config.getCommaSeparatedMap(ATTRIBUTE_PROPERTY);
Map<String, String> resourceAttributes = config.getMap(ATTRIBUTE_PROPERTY);
serviceName = resourceAttributes.get(SERVICE_NAME_PROPERTY);
}
JaegerRemoteSamplerBuilder builder = JaegerRemoteSampler.builder().setServiceName(serviceName);
Map<String, String> params = config.getCommaSeparatedMap(SAMPLER_ARG_PROPERTY);
Map<String, String> params = config.getMap(SAMPLER_ARG_PROPERTY);
// Optional configuration
String endpoint = params.get(ENDPOINT_KEY);

View File

@ -36,7 +36,7 @@ public class JaegerRemoteSamplerProviderTest {
samplerArgs.put("pollingInterval", "99");
double samplingRate = 0.33;
samplerArgs.put("initialSamplingRate", String.valueOf(samplingRate));
when(mockConfig.getCommaSeparatedMap(JaegerRemoteSamplerProvider.SAMPLER_ARG_PROPERTY))
when(mockConfig.getMap(JaegerRemoteSamplerProvider.SAMPLER_ARG_PROPERTY))
.thenReturn(samplerArgs);
Sampler sampler = Sampler.parentBased(Sampler.traceIdRatioBased(samplingRate));
@ -67,7 +67,7 @@ public class JaegerRemoteSamplerProviderTest {
ConfigProperties mockConfig = mock(ConfigProperties.class);
HashMap<String, String> attributeProperties = new HashMap<>();
attributeProperties.put(JaegerRemoteSamplerProvider.SERVICE_NAME_PROPERTY, "test_service2");
when(mockConfig.getCommaSeparatedMap(JaegerRemoteSamplerProvider.ATTRIBUTE_PROPERTY))
when(mockConfig.getMap(JaegerRemoteSamplerProvider.ATTRIBUTE_PROPERTY))
.thenReturn(attributeProperties);
ServiceLoader<ConfigurableSamplerProvider> samplerProviders =
ServiceLoader.load(ConfigurableSamplerProvider.class);