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

Move DefaultConfigProperties to autoconfigure-spi #5001

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.sdk.autoconfigure;
package io.opentelemetry.sdk.autoconfigure.spi.internal;

import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.joining;
Expand All @@ -27,26 +27,33 @@
import javax.annotation.Nullable;

/**
* Properties to be used for auto-configuration of the OpenTelemetry SDK components. These
* properties will be a combination of system properties and environment variables. The properties
* for both of these will be normalized to be all lower case, and underscores will be replaced with
* Properties are normalized to The properties for both of these will be normalized to be all lower
* case, dashses are replaces with periods, and environment variable underscores are replaces with
* periods.
*
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
final class DefaultConfigProperties implements ConfigProperties {
public final class DefaultConfigProperties implements ConfigProperties {

private final Map<String, String> config;

static DefaultConfigProperties get(Map<String, String> defaultProperties) {
/**
* Creates a {@link DefaultConfigProperties} by merging system properties, environment variables,
* and the {@code defaultProperties}.
*
* <p>Environment variables take priority over {@code defaultProperties}. System properties take
* priority over system properties.
*/
public static DefaultConfigProperties create(Map<String, String> defaultProperties) {
return new DefaultConfigProperties(System.getProperties(), System.getenv(), defaultProperties);
}

static DefaultConfigProperties customize(
DefaultConfigProperties previousProperties, Map<String, String> overrides) {
return new DefaultConfigProperties(previousProperties, overrides);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted this to be an instance method called withOverrides. Also renamed static DefaultConfigProperties get to create, so we now have consistently named factory methods for creating instances.


// Visible for testing
static ConfigProperties createForTest(Map<String, String> properties) {
/**
* Create a {@link DefaultConfigProperties} from the {@code properties}, ignoring system
* properties and environment variables.
*/
public static DefaultConfigProperties createForTest(Map<String, String> properties) {
return new DefaultConfigProperties(properties, Collections.emptyMap(), Collections.emptyMap());
}

Expand Down Expand Up @@ -180,7 +187,7 @@ public List<String> getList(String name) {
*
* @throws ConfigurationException if {@code name} contains duplicate entries
*/
static Set<String> getSet(ConfigProperties config, String name) {
public static Set<String> getSet(ConfigProperties config, String name) {
List<String> list = config.getList(normalize(name));
Set<String> set = new HashSet<>(list);
if (set.size() != list.size()) {
Expand Down Expand Up @@ -217,6 +224,14 @@ public Map<String, String> getMap(String name) {
Map.Entry::getKey, Map.Entry::getValue, (first, next) -> next, LinkedHashMap::new));
}

/**
* Return a new {@link DefaultConfigProperties} by overriding the {@code previousProperties} with
* the {@code overrides}.
*/
public DefaultConfigProperties withOverrides(Map<String, String> overrides) {
return new DefaultConfigProperties(this, overrides);
}

private static ConfigurationException newInvalidPropertyException(
String name, String value, String type) {
throw new ConfigurationException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizer;
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.logs.SdkLoggerProvider;
import io.opentelemetry.sdk.logs.SdkLoggerProviderBuilder;
Expand Down Expand Up @@ -424,10 +425,10 @@ private ConfigProperties getConfig() {
}

private ConfigProperties computeConfigProperties() {
DefaultConfigProperties properties = DefaultConfigProperties.get(propertiesSupplier.get());
DefaultConfigProperties properties = DefaultConfigProperties.create(propertiesSupplier.get());
for (Function<ConfigProperties, Map<String, String>> customizer : propertiesCustomizers) {
Map<String, String> overrides = customizer.apply(properties);
properties = DefaultConfigProperties.customize(properties, overrides);
properties = properties.withOverrides(overrides);
}
return properties;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporterBuilder;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.logs.ConfigurableLogRecordExporterProvider;
import io.opentelemetry.sdk.logs.export.LogRecordExporter;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder;
import io.opentelemetry.sdk.metrics.export.MetricExporter;
import io.opentelemetry.sdk.metrics.export.MetricReader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider;
import io.opentelemetry.sdk.trace.export.SpanExporter;
import java.time.Duration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import java.time.Duration;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -236,7 +237,7 @@ void defaultMethodsDelegate() {
expectedMap.put("bear", "growl");

Map<String, String> map = makeTestProps();
ConfigProperties properties = DefaultConfigProperties.get(map);
ConfigProperties properties = DefaultConfigProperties.create(map);
assertThat(properties.getBoolean("test.boolean", false)).isTrue();
assertThat(properties.getString("test.string", "nah")).isEqualTo("str");
assertThat(properties.getDouble("test.double", 65.535)).isEqualTo(5.4);
Expand All @@ -250,7 +251,7 @@ void defaultMethodsDelegate() {

@Test
void defaultMethodsFallBack() {
ConfigProperties properties = DefaultConfigProperties.get(emptyMap());
ConfigProperties properties = DefaultConfigProperties.create(emptyMap());
assertThat(properties.getBoolean("foo", true)).isTrue();
assertThat(properties.getString("foo", "bar")).isEqualTo("bar");
assertThat(properties.getDouble("foo", 65.535)).isEqualTo(65.535);
Expand All @@ -261,7 +262,7 @@ void defaultMethodsFallBack() {

@Test
void defaultCollectionTypes() {
ConfigProperties properties = DefaultConfigProperties.get(emptyMap());
ConfigProperties properties = DefaultConfigProperties.create(emptyMap());
assertThat(properties.getList("foo", Arrays.asList("1", "2", "3")))
.containsExactly("1", "2", "3");
assertThat(properties.getList("foo")).isEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.opentelemetry.api.metrics.MeterProvider;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import org.junit.jupiter.api.Test;

class LogRecordExporterConfigurationTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.google.common.collect.ImmutableMap;
import io.opentelemetry.api.metrics.MeterProvider;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import io.opentelemetry.sdk.logs.LogLimits;
import io.opentelemetry.sdk.logs.LogRecordProcessor;
import io.opentelemetry.sdk.logs.SdkLoggerProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.opentelemetry.api.metrics.MeterProvider;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import java.util.Collections;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static org.assertj.core.api.Assertions.assertThat;

import io.opentelemetry.context.propagation.ContextPropagators;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import java.util.Collections;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import edu.berkeley.cs.jqf.fuzz.random.NoGuidance;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.internal.PercentEscaper;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import org.junit.jupiter.api.Test;
import org.junit.runner.Result;
import org.junit.runner.RunWith;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.semconv.resource.attributes.ResourceAttributes;
import java.util.HashMap;
Expand All @@ -34,7 +35,7 @@ void customConfigResource() {

assertThat(
ResourceConfiguration.configureResource(
DefaultConfigProperties.get(props),
DefaultConfigProperties.create(props),
ResourceConfigurationTest.class.getClassLoader(),
(r, c) -> r))
.isEqualTo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import java.util.Collections;
import java.util.List;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.opentelemetry.api.metrics.MeterProvider;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.trace.SdkTracerProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.opentelemetry.api.metrics.MeterProvider;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import io.opentelemetry.sdk.logs.export.LogRecordExporter;
import java.net.URL;
import java.net.URLClassLoader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.opentelemetry.exporter.prometheus.PrometheusHttpServer;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import io.opentelemetry.sdk.metrics.export.MetricExporter;
import io.opentelemetry.sdk.metrics.export.PeriodicMetricReader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.google.common.collect.ImmutableMap;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import io.opentelemetry.sdk.trace.samplers.Sampler;
import java.net.URL;
import java.net.URLClassLoader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.opentelemetry.exporter.zipkin.ZipkinSpanExporter;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import io.opentelemetry.sdk.trace.export.BatchSpanProcessor;
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
import io.opentelemetry.sdk.trace.export.SpanExporter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.opentelemetry.api.metrics.MeterProvider;
import io.opentelemetry.exporter.logging.SystemOutLogRecordExporter;
import io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporter;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import io.opentelemetry.sdk.logs.SdkLoggerProvider;
import io.opentelemetry.sdk.logs.SdkLoggerProviderBuilder;
import io.opentelemetry.sdk.logs.export.BatchLogRecordProcessor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import com.google.common.collect.ImmutableMap;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import org.junit.jupiter.api.Test;

public class MetricExporterConfigurationTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import com.google.common.collect.ImmutableMap;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import io.opentelemetry.sdk.metrics.InstrumentType;
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
import io.opentelemetry.sdk.metrics.export.AggregationTemporalitySelector;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Collections;
Expand All @@ -22,7 +23,7 @@ class ResourceConfigurationTest {
void configureResource() {
Attributes attributes =
ResourceConfiguration.configureResource(
DefaultConfigProperties.get(Collections.emptyMap()),
DefaultConfigProperties.create(Collections.emptyMap()),
ResourceConfigurationTest.class.getClassLoader(),
(r, c) -> r)
.getAttributes();
Expand All @@ -35,7 +36,7 @@ void configureResource() {
void configureResource_EmptyClassLoader() {
Attributes attributes =
ResourceConfiguration.configureResource(
DefaultConfigProperties.get(Collections.emptyMap()),
DefaultConfigProperties.create(Collections.emptyMap()),
new URLClassLoader(new URL[0], null),
(r, c) -> r)
.getAttributes();
Expand All @@ -52,7 +53,7 @@ void configureResource_OnlyEnabled() {
"io.opentelemetry.sdk.autoconfigure.TestAnimalResourceProvider");
Attributes attributes =
ResourceConfiguration.configureResource(
DefaultConfigProperties.get(customConfigs),
DefaultConfigProperties.create(customConfigs),
ResourceConfigurationTest.class.getClassLoader(),
(r, c) -> r)
.getAttributes();
Expand All @@ -72,7 +73,7 @@ void configureResource_EnabledAndDisabled() {
"io.opentelemetry.sdk.extension.resources.TestColorResourceProvider");
Attributes attributes =
ResourceConfiguration.configureResource(
DefaultConfigProperties.get(customConfigs),
DefaultConfigProperties.create(customConfigs),
ResourceConfigurationTest.class.getClassLoader(),
(r, c) -> r)
.getAttributes();
Expand All @@ -89,7 +90,7 @@ void configureResource_OnlyDisabled() {
"io.opentelemetry.sdk.autoconfigure.TestColorResourceProvider");
Attributes attributes =
ResourceConfiguration.configureResource(
DefaultConfigProperties.get(customConfigs),
DefaultConfigProperties.create(customConfigs),
ResourceConfigurationTest.class.getClassLoader(),
(r, c) -> r)
.getAttributes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import io.opentelemetry.sdk.trace.export.SpanExporter;
import java.util.Collections;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingMetricExporter;
import io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingSpanExporter;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import io.opentelemetry.sdk.logs.export.LogRecordExporter;
import io.opentelemetry.sdk.metrics.InstrumentType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.opentelemetry.exporter.internal.retry.RetryPolicy;
import io.opentelemetry.exporter.internal.retry.RetryUtil;
import io.opentelemetry.internal.testing.slf4j.SuppressLogger;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import io.opentelemetry.sdk.logs.export.LogRecordExporter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.opentelemetry.api.metrics.MeterProvider;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import io.opentelemetry.sdk.logs.export.LogRecordExporter;
import io.opentelemetry.sdk.metrics.InstrumentType;
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.opentelemetry.exporter.internal.retry.RetryPolicy;
import io.opentelemetry.exporter.internal.retry.RetryUtil;
import io.opentelemetry.internal.testing.slf4j.SuppressLogger;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import io.opentelemetry.sdk.logs.export.LogRecordExporter;
Expand Down