Skip to content

Commit

Permalink
Declarative config: more qualified imports (#6930)
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-berg authored Dec 7, 2024
1 parent 3928feb commit aca4ee3
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.AggregationModel;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.Base2ExponentialBucketHistogramModel;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.ExplicitBucketHistogramModel;
import io.opentelemetry.sdk.metrics.Aggregation;
import java.io.Closeable;
import java.util.List;

final class AggregationFactory
implements Factory<AggregationModel, io.opentelemetry.sdk.metrics.Aggregation> {
final class AggregationFactory implements Factory<AggregationModel, Aggregation> {

private static final AggregationFactory INSTANCE = new AggregationFactory();

Expand All @@ -25,16 +25,16 @@ static AggregationFactory getInstance() {
}

@Override
public io.opentelemetry.sdk.metrics.Aggregation create(
public Aggregation create(
AggregationModel model, SpiHelper spiHelper, List<Closeable> closeables) {
if (model.getDrop() != null) {
return io.opentelemetry.sdk.metrics.Aggregation.drop();
return Aggregation.drop();
}
if (model.getSum() != null) {
return io.opentelemetry.sdk.metrics.Aggregation.sum();
return Aggregation.sum();
}
if (model.getLastValue() != null) {
return io.opentelemetry.sdk.metrics.Aggregation.lastValue();
return Aggregation.lastValue();
}
Base2ExponentialBucketHistogramModel exponentialBucketHistogram =
model.getBase2ExponentialBucketHistogram();
Expand All @@ -48,8 +48,7 @@ public io.opentelemetry.sdk.metrics.Aggregation create(
maxSize = 160;
}
try {
return io.opentelemetry.sdk.metrics.Aggregation.base2ExponentialBucketHistogram(
maxSize, maxScale);
return Aggregation.base2ExponentialBucketHistogram(maxSize, maxScale);
} catch (IllegalArgumentException e) {
throw new ConfigurationException("Invalid exponential bucket histogram", e);
}
Expand All @@ -58,15 +57,15 @@ public io.opentelemetry.sdk.metrics.Aggregation create(
if (explicitBucketHistogram != null) {
List<Double> boundaries = explicitBucketHistogram.getBoundaries();
if (boundaries == null) {
return io.opentelemetry.sdk.metrics.Aggregation.explicitBucketHistogram();
return Aggregation.explicitBucketHistogram();
}
try {
return io.opentelemetry.sdk.metrics.Aggregation.explicitBucketHistogram(boundaries);
return Aggregation.explicitBucketHistogram(boundaries);
} catch (IllegalArgumentException e) {
throw new ConfigurationException("Invalid explicit bucket histogram", e);
}
}

return io.opentelemetry.sdk.metrics.Aggregation.defaultAggregation();
return Aggregation.defaultAggregation();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static java.util.stream.Collectors.toList;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
Expand All @@ -16,8 +17,7 @@
import java.util.List;
import javax.annotation.Nullable;

final class AttributeListFactory
implements Factory<List<AttributeNameValueModel>, io.opentelemetry.api.common.Attributes> {
final class AttributeListFactory implements Factory<List<AttributeNameValueModel>, Attributes> {

private static final AttributeListFactory INSTANCE = new AttributeListFactory();

Expand All @@ -28,9 +28,9 @@ static AttributeListFactory getInstance() {
}

@Override
public io.opentelemetry.api.common.Attributes create(
public Attributes create(
List<AttributeNameValueModel> model, SpiHelper spiHelper, List<Closeable> closeables) {
AttributesBuilder builder = io.opentelemetry.api.common.Attributes.builder();
AttributesBuilder builder = Attributes.builder();

for (AttributeNameValueModel nameValueModel : model) {
addToBuilder(nameValueModel, builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OpenTelemetryConfigurationModel;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.SamplerModel;
import io.opentelemetry.sdk.trace.samplers.Sampler;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -183,8 +184,7 @@ static StructuredConfigProperties toConfigProperties(
*/
// TODO(jack-berg): add create methods for all SDK extension components supported by
// ComponentProvider
public static io.opentelemetry.sdk.trace.samplers.Sampler createSampler(
StructuredConfigProperties genericSamplerModel) {
public static Sampler createSampler(StructuredConfigProperties genericSamplerModel) {
YamlStructuredConfigProperties yamlStructuredConfigProperties =
requireYamlStructuredConfigProperties(genericSamplerModel);
SamplerModel samplerModel = convertToModel(yamlStructuredConfigProperties, SamplerModel.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.opentelemetry.sdk.logs.LogRecordProcessor;
import io.opentelemetry.sdk.logs.export.BatchLogRecordProcessor;
import io.opentelemetry.sdk.logs.export.BatchLogRecordProcessorBuilder;
import io.opentelemetry.sdk.logs.export.LogRecordExporter;
import io.opentelemetry.sdk.logs.export.SimpleLogRecordProcessor;
import java.io.Closeable;
import java.time.Duration;
Expand All @@ -42,7 +43,7 @@ public LogRecordProcessor create(
FileConfigUtil.requireNonNull(
batchModel.getExporter(), "batch log record processor exporter");

io.opentelemetry.sdk.logs.export.LogRecordExporter logRecordExporter =
LogRecordExporter logRecordExporter =
LogRecordExporterFactory.getInstance().create(exporterModel, spiHelper, closeables);
BatchLogRecordProcessorBuilder builder = BatchLogRecordProcessor.builder(logRecordExporter);
if (batchModel.getExportTimeout() != null) {
Expand All @@ -65,7 +66,7 @@ public LogRecordProcessor create(
LogRecordExporterModel exporterModel =
FileConfigUtil.requireNonNull(
simpleModel.getExporter(), "simple log record processor exporter");
io.opentelemetry.sdk.logs.export.LogRecordExporter logRecordExporter =
LogRecordExporter logRecordExporter =
LogRecordExporterFactory.getInstance().create(exporterModel, spiHelper, closeables);
return FileConfigUtil.addAndReturn(
closeables, SimpleLogRecordProcessor.create(logRecordExporter));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.ViewModel;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder;
import io.opentelemetry.sdk.metrics.export.MetricReader;
import java.io.Closeable;
import java.util.List;

Expand All @@ -37,7 +38,7 @@ public SdkMeterProviderBuilder create(
if (readerModels != null) {
readerModels.forEach(
readerModel -> {
io.opentelemetry.sdk.metrics.export.MetricReader metricReader =
MetricReader metricReader =
MetricReaderFactory.getInstance().create(readerModel, spiHelper, closeables);
if (metricReader != null) {
builder.registerMetricReader(metricReader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.PullMetricExporterModel;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.PullMetricReaderModel;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.PushMetricExporterModel;
import io.opentelemetry.sdk.metrics.export.MetricExporter;
import io.opentelemetry.sdk.metrics.export.MetricReader;
import io.opentelemetry.sdk.metrics.export.PeriodicMetricReader;
import io.opentelemetry.sdk.metrics.export.PeriodicMetricReaderBuilder;
import java.io.Closeable;
import java.time.Duration;
Expand All @@ -38,11 +40,10 @@ public MetricReader create(
if (periodicModel != null) {
PushMetricExporterModel exporterModel =
requireNonNull(periodicModel.getExporter(), "periodic metric reader exporter");
io.opentelemetry.sdk.metrics.export.MetricExporter metricExporter =
MetricExporter metricExporter =
MetricExporterFactory.getInstance().create(exporterModel, spiHelper, closeables);
PeriodicMetricReaderBuilder builder =
io.opentelemetry.sdk.metrics.export.PeriodicMetricReader.builder(
FileConfigUtil.addAndReturn(closeables, metricExporter));
PeriodicMetricReader.builder(FileConfigUtil.addAndReturn(closeables, metricExporter));
if (periodicModel.getInterval() != null) {
builder.setInterval(Duration.ofMillis(periodicModel.getInterval()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.AttributeNameValueModel;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.DetectorAttributesModel;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.DetectorsModel;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.ResourceModel;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.resources.ResourceBuilder;
import java.io.Closeable;
Expand All @@ -28,10 +29,7 @@
import java.util.stream.Collectors;
import javax.annotation.Nullable;

final class ResourceFactory
implements Factory<
io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.ResourceModel,
Resource> {
final class ResourceFactory implements Factory<ResourceModel, Resource> {

private static final StructuredConfigProperties EMPTY_CONFIG =
FileConfiguration.toConfigProperties(
Expand All @@ -46,10 +44,7 @@ static ResourceFactory getInstance() {
}

@Override
public Resource create(
io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.ResourceModel model,
SpiHelper spiHelper,
List<Closeable> closeables) {
public Resource create(ResourceModel model, SpiHelper spiHelper, List<Closeable> closeables) {
ResourceBuilder builder = Resource.getDefault().toBuilder();

ResourceBuilder detectedResourceBuilder = Resource.builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.AttributeLimitsModel;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.SpanLimitsModel;
import io.opentelemetry.sdk.trace.SpanLimits;
import io.opentelemetry.sdk.trace.SpanLimitsBuilder;
import java.io.Closeable;
import java.util.List;

final class SpanLimitsFactory
implements Factory<SpanLimitsAndAttributeLimits, io.opentelemetry.sdk.trace.SpanLimits> {
final class SpanLimitsFactory implements Factory<SpanLimitsAndAttributeLimits, SpanLimits> {

private static final SpanLimitsFactory INSTANCE = new SpanLimitsFactory();

Expand All @@ -24,9 +24,9 @@ static SpanLimitsFactory getInstance() {
}

@Override
public io.opentelemetry.sdk.trace.SpanLimits create(
public SpanLimits create(
SpanLimitsAndAttributeLimits model, SpiHelper spiHelper, List<Closeable> closeables) {
SpanLimitsBuilder builder = io.opentelemetry.sdk.trace.SpanLimits.builder();
SpanLimitsBuilder builder = SpanLimits.builder();

AttributeLimitsModel attributeLimitsModel = model.getAttributeLimits();
if (attributeLimitsModel != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.opentelemetry.sdk.trace.export.BatchSpanProcessor;
import io.opentelemetry.sdk.trace.export.BatchSpanProcessorBuilder;
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
import io.opentelemetry.sdk.trace.export.SpanExporter;
import java.io.Closeable;
import java.time.Duration;
import java.util.List;
Expand All @@ -39,7 +40,7 @@ public SpanProcessor create(
if (batchModel != null) {
SpanExporterModel exporterModel =
FileConfigUtil.requireNonNull(batchModel.getExporter(), "batch span processor exporter");
io.opentelemetry.sdk.trace.export.SpanExporter spanExporter =
SpanExporter spanExporter =
SpanExporterFactory.getInstance().create(exporterModel, spiHelper, closeables);
BatchSpanProcessorBuilder builder = BatchSpanProcessor.builder(spanExporter);
if (batchModel.getExportTimeout() != null) {
Expand All @@ -62,7 +63,7 @@ public SpanProcessor create(
SpanExporterModel exporterModel =
FileConfigUtil.requireNonNull(
simpleModel.getExporter(), "simple span processor exporter");
io.opentelemetry.sdk.trace.export.SpanExporter spanExporter =
SpanExporter spanExporter =
SpanExporterFactory.getInstance().create(exporterModel, spiHelper, closeables);
return FileConfigUtil.addAndReturn(closeables, SimpleSpanProcessor.create(spanExporter));
}
Expand Down

0 comments on commit aca4ee3

Please sign in to comment.