Declarative configuration missing pieces (#6677)
This commit is contained in:
parent
61a4b46676
commit
00b0e9f87c
|
@ -5,19 +5,29 @@
|
|||
|
||||
package io.opentelemetry.sdk.autoconfigure.spi.internal;
|
||||
|
||||
import io.opentelemetry.context.propagation.TextMapPropagator;
|
||||
import io.opentelemetry.sdk.logs.LogRecordProcessor;
|
||||
import io.opentelemetry.sdk.logs.export.LogRecordExporter;
|
||||
import io.opentelemetry.sdk.metrics.export.MetricExporter;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import io.opentelemetry.sdk.trace.SpanProcessor;
|
||||
import io.opentelemetry.sdk.trace.export.SpanExporter;
|
||||
import io.opentelemetry.sdk.trace.samplers.Sampler;
|
||||
|
||||
/**
|
||||
* Provides configured instances of SDK extension components. {@link ComponentProvider} allows SDK
|
||||
* extension components which are not part of the core SDK to be referenced in file based
|
||||
* configuration.
|
||||
*
|
||||
* <p>NOTE: when {@link #getType()} is {@link Resource}, the {@link #getName()} is not (currently)
|
||||
* used, and {@link #create(StructuredConfigProperties)} is (currently) called with an empty {@link
|
||||
* StructuredConfigProperties}.
|
||||
*
|
||||
* @param <T> the type of the SDK extension component. See {@link #getType()}. Supported values
|
||||
* include: {@link SpanExporter}, {@link MetricExporter}, {@link LogRecordExporter}.
|
||||
* include: {@link SpanExporter}, {@link MetricExporter}, {@link LogRecordExporter}, {@link
|
||||
* SpanProcessor}, {@link LogRecordProcessor}, {@link TextMapPropagator}, {@link Sampler},
|
||||
* {@link Resource}.
|
||||
*/
|
||||
// TODO: add support for Sampler, LogRecordProcessor, SpanProcessor, MetricReader
|
||||
public interface ComponentProvider<T> {
|
||||
|
||||
/**
|
||||
|
@ -31,7 +41,8 @@ public interface ComponentProvider<T> {
|
|||
* instances of a custom span exporter for the "acme" protocol, the name might be "acme".
|
||||
*
|
||||
* <p>This name MUST not be the same as any other component provider name which returns components
|
||||
* of the same {@link #getType() type}.
|
||||
* of the same {@link #getType() type}. In other words, {@link #getType()} and name form a
|
||||
* composite key uniquely identifying the provider.
|
||||
*/
|
||||
String getName();
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ dependencies {
|
|||
|
||||
// io.opentelemetry.sdk.extension.incubator.fileconfig
|
||||
implementation("com.fasterxml.jackson.core:jackson-databind")
|
||||
api("com.fasterxml.jackson.core:jackson-annotations")
|
||||
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml")
|
||||
implementation(project(":sdk-extensions:autoconfigure"))
|
||||
|
||||
|
|
|
@ -123,8 +123,7 @@ public final class FileConfiguration {
|
|||
}
|
||||
|
||||
/**
|
||||
* Convert the {@code model} to a generic {@link StructuredConfigProperties}, which can be used to
|
||||
* read configuration not part of the model.
|
||||
* Convert the {@code model} to a generic {@link StructuredConfigProperties}.
|
||||
*
|
||||
* @param model the configuration model
|
||||
* @return a generic {@link StructuredConfigProperties} representation of the model
|
||||
|
@ -133,6 +132,17 @@ public final class FileConfiguration {
|
|||
return toConfigProperties((Object) model);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the {@code configuration} YAML to a generic {@link StructuredConfigProperties}.
|
||||
*
|
||||
* @param configuration configuration YAML
|
||||
* @return a generic {@link StructuredConfigProperties} representation of the model
|
||||
*/
|
||||
public static StructuredConfigProperties toConfigProperties(InputStream configuration) {
|
||||
Object yamlObj = loadYaml(configuration, System.getenv());
|
||||
return toConfigProperties(yamlObj);
|
||||
}
|
||||
|
||||
static StructuredConfigProperties toConfigProperties(Object model) {
|
||||
Map<String, Object> configurationMap =
|
||||
MAPPER.convertValue(model, new TypeReference<Map<String, Object>>() {});
|
||||
|
|
|
@ -64,7 +64,7 @@ final class YamlStructuredConfigProperties implements StructuredConfigProperties
|
|||
for (Map.Entry<String, Object> entry : properties.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
Object value = entry.getValue();
|
||||
if (isPrimitive(value)) {
|
||||
if (isPrimitive(value) || value == null) {
|
||||
simpleEntries.put(key, value);
|
||||
continue;
|
||||
}
|
||||
|
@ -283,7 +283,7 @@ final class YamlStructuredConfigProperties implements StructuredConfigProperties
|
|||
}
|
||||
|
||||
/** Return a map representation of the data. */
|
||||
Map<String, Object> toMap() {
|
||||
public Map<String, Object> toMap() {
|
||||
Map<String, Object> result = new HashMap<>(simpleEntries);
|
||||
listEntries.forEach(
|
||||
(key, value) ->
|
||||
|
|
|
@ -33,6 +33,7 @@ class YamlStructuredConfigPropertiesTest {
|
|||
+ " int_key: 1\n"
|
||||
+ " float_key: 1.1\n"
|
||||
+ " bool_key: true\n"
|
||||
+ " null_key:\n"
|
||||
+ " str_list_key: [val1, val2]\n"
|
||||
+ " int_list_key: [1, 2]\n"
|
||||
+ " float_list_key: [1.1, 2.2]\n"
|
||||
|
@ -90,6 +91,7 @@ class YamlStructuredConfigPropertiesTest {
|
|||
"int_key",
|
||||
"float_key",
|
||||
"bool_key",
|
||||
"null_key",
|
||||
"str_list_key",
|
||||
"int_list_key",
|
||||
"float_list_key",
|
||||
|
@ -101,7 +103,10 @@ class YamlStructuredConfigPropertiesTest {
|
|||
assertThat(otherProps.getInt("int_key")).isEqualTo(1);
|
||||
assertThat(otherProps.getLong("int_key")).isEqualTo(1);
|
||||
assertThat(otherProps.getDouble("float_key")).isEqualTo(1.1);
|
||||
assertThat(otherProps.getBoolean("bool_key")).isTrue();
|
||||
assertThat(otherProps.getString("null_key")).isNull();
|
||||
assertThat(otherProps.getInt("null_key")).isNull();
|
||||
assertThat(otherProps.getLong("null_key")).isNull();
|
||||
assertThat(otherProps.getBoolean("null_key")).isNull();
|
||||
assertThat(otherProps.getScalarList("str_list_key", String.class))
|
||||
.isEqualTo(Arrays.asList("val1", "val2"));
|
||||
assertThat(otherProps.getScalarList("int_list_key", Long.class))
|
||||
|
|
Loading…
Reference in New Issue