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

Adding model as suffix to generated classes. #6721

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 @@ -551,7 +551,7 @@ private static AutoConfiguredOpenTelemetrySdk maybeConfigureFromFile(ConfigPrope
Object model = parse.invoke(null, fis);
Class<?> openTelemetryConfiguration =
Class.forName(
"io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OpenTelemetryConfiguration");
"io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OpenTelemetryConfigurationModel");
Method create = configurationFactory.getMethod("create", openTelemetryConfiguration);
OpenTelemetrySdk sdk = (OpenTelemetrySdk) create.invoke(null, model);
Method toConfigProperties =
Expand Down
3 changes: 3 additions & 0 deletions sdk-extensions/incubator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ jsonSchema2Pojo {
// Force java 9+ @Generated annotation, since java 8 @Generated annotation isn't detected by
// jsonSchema2Pojo and annotation is skipped altogether
targetVersion = "1.9"

// Append Model as suffix to the generated classes.
classNameSuffix = "Model"
}

val generateJsonSchema2Pojo = tasks.getByName("generateJsonSchema2Pojo")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.Aggregation;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.Base2ExponentialBucketHistogram;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.ExplicitBucketHistogram;
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 java.io.Closeable;
import java.util.List;

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

private static final AggregationFactory INSTANCE = new AggregationFactory();

Expand All @@ -26,7 +26,7 @@ static AggregationFactory getInstance() {

@Override
public io.opentelemetry.sdk.metrics.Aggregation create(
Aggregation model, SpiHelper spiHelper, List<Closeable> closeables) {
AggregationModel model, SpiHelper spiHelper, List<Closeable> closeables) {
if (model.getDrop() != null) {
return io.opentelemetry.sdk.metrics.Aggregation.drop();
}
Expand All @@ -36,7 +36,7 @@ public io.opentelemetry.sdk.metrics.Aggregation create(
if (model.getLastValue() != null) {
return io.opentelemetry.sdk.metrics.Aggregation.lastValue();
}
Base2ExponentialBucketHistogram exponentialBucketHistogram =
Base2ExponentialBucketHistogramModel exponentialBucketHistogram =
model.getBase2ExponentialBucketHistogram();
if (exponentialBucketHistogram != null) {
Integer maxScale = exponentialBucketHistogram.getMaxScale();
Expand All @@ -54,7 +54,7 @@ public io.opentelemetry.sdk.metrics.Aggregation create(
throw new ConfigurationException("Invalid exponential bucket histogram", e);
}
}
ExplicitBucketHistogram explicitBucketHistogram = model.getExplicitBucketHistogram();
ExplicitBucketHistogramModel explicitBucketHistogram = model.getExplicitBucketHistogram();
if (explicitBucketHistogram != null) {
List<Double> boundaries = explicitBucketHistogram.getBoundaries();
if (boundaries == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.Attributes;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.AttributesModel;
import java.io.Closeable;
import java.util.List;

final class AttributesFactory
implements Factory<Attributes, io.opentelemetry.api.common.Attributes> {
implements Factory<AttributesModel, io.opentelemetry.api.common.Attributes> {

private static final AttributesFactory INSTANCE = new AttributesFactory();

Expand All @@ -28,7 +28,7 @@ static AttributesFactory getInstance() {

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

String serviceName = model.getServiceName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider;
import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OpenTelemetryConfiguration;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.Sampler;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OpenTelemetryConfigurationModel;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.SamplerModel;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -68,12 +68,12 @@ public final class FileConfiguration {
private FileConfiguration() {}

/**
* Combines {@link #parse(InputStream)} and {@link #create(OpenTelemetryConfiguration)}.
* Combines {@link #parse(InputStream)} and {@link #create(OpenTelemetryConfigurationModel)}.
*
* @throws ConfigurationException if unable to parse or interpret
*/
public static OpenTelemetrySdk parseAndCreate(InputStream inputStream) {
OpenTelemetryConfiguration configurationModel = parse(inputStream);
OpenTelemetryConfigurationModel configurationModel = parse(inputStream);
return create(configurationModel);
}

Expand All @@ -85,22 +85,22 @@ public static OpenTelemetrySdk parseAndCreate(InputStream inputStream) {
* @return the {@link OpenTelemetrySdk}
* @throws ConfigurationException if unable to interpret
*/
public static OpenTelemetrySdk create(OpenTelemetryConfiguration configurationModel) {
public static OpenTelemetrySdk create(OpenTelemetryConfigurationModel configurationModel) {
return createAndMaybeCleanup(
OpenTelemetryConfigurationFactory.getInstance(),
SpiHelper.create(FileConfiguration.class.getClassLoader()),
configurationModel);
}

/**
* Parse the {@code configuration} YAML and return the {@link OpenTelemetryConfiguration}.
* Parse the {@code configuration} YAML and return the {@link OpenTelemetryConfigurationModel}.
*
* <p>Before parsing, environment variable substitution is performed as described in {@link
* EnvSubstitutionConstructor}.
*
* @throws ConfigurationException if unable to parse
*/
public static OpenTelemetryConfiguration parse(InputStream configuration) {
public static OpenTelemetryConfigurationModel parse(InputStream configuration) {
try {
return parse(configuration, System.getenv());
} catch (RuntimeException e) {
Expand All @@ -109,10 +109,10 @@ public static OpenTelemetryConfiguration parse(InputStream configuration) {
}

// Visible for testing
static OpenTelemetryConfiguration parse(
static OpenTelemetryConfigurationModel parse(
InputStream configuration, Map<String, String> environmentVariables) {
Object yamlObj = loadYaml(configuration, environmentVariables);
return MAPPER.convertValue(yamlObj, OpenTelemetryConfiguration.class);
return MAPPER.convertValue(yamlObj, OpenTelemetryConfigurationModel.class);
}

// Visible for testing
Expand All @@ -128,7 +128,8 @@ static Object loadYaml(InputStream inputStream, Map<String, String> environmentV
* @param model the configuration model
* @return a generic {@link StructuredConfigProperties} representation of the model
*/
public static StructuredConfigProperties toConfigProperties(OpenTelemetryConfiguration model) {
public static StructuredConfigProperties toConfigProperties(
OpenTelemetryConfigurationModel model) {
return toConfigProperties((Object) model);
}

Expand All @@ -150,18 +151,18 @@ static StructuredConfigProperties toConfigProperties(Object model) {
}

/**
* Create a {@link Sampler} from the {@code samplerModel} representing the sampler config.
* Create a {@link SamplerModel} from the {@code samplerModel} representing the sampler config.
*
* <p>This is used when samplers are composed, with one sampler accepting one or more additional
* samplers as config properties. The {@link ComponentProvider} implementation can call this to
* configure a delegate {@link Sampler} from the {@link StructuredConfigProperties} corresponding
* to a particular config property.
* configure a delegate {@link SamplerModel} from the {@link StructuredConfigProperties}
* corresponding to a particular config property.
*/
// 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) {
Sampler samplerModel = convertToModel(genericSamplerModel, Sampler.class);
SamplerModel samplerModel = convertToModel(genericSamplerModel, SamplerModel.class);
return createAndMaybeCleanup(
SamplerFactory.getInstance(),
SpiHelper.create(FileConfiguration.class.getClassLoader()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.Selector;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.SelectorModel;
import io.opentelemetry.sdk.metrics.InstrumentSelector;
import io.opentelemetry.sdk.metrics.InstrumentSelectorBuilder;
import io.opentelemetry.sdk.metrics.InstrumentType;
import java.io.Closeable;
import java.util.List;

final class InstrumentSelectorFactory implements Factory<Selector, InstrumentSelector> {
final class InstrumentSelectorFactory implements Factory<SelectorModel, InstrumentSelector> {

private static final InstrumentSelectorFactory INSTANCE = new InstrumentSelectorFactory();

Expand All @@ -26,7 +26,7 @@ static InstrumentSelectorFactory getInstance() {

@Override
public InstrumentSelector create(
Selector model, SpiHelper spiHelper, List<Closeable> closeables) {
SelectorModel model, SpiHelper spiHelper, List<Closeable> closeables) {
InstrumentSelectorBuilder builder = InstrumentSelector.builder();
if (model.getInstrumentName() != null) {
builder.setName(model.getInstrumentName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
package io.opentelemetry.sdk.extension.incubator.fileconfig;

import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.AttributeLimits;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.LogRecordLimits;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.AttributeLimitsModel;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.LogRecordLimitsModel;
import io.opentelemetry.sdk.logs.LogLimits;
import io.opentelemetry.sdk.logs.LogLimitsBuilder;
import java.io.Closeable;
Expand All @@ -28,7 +28,7 @@ public LogLimits create(
LogRecordLimitsAndAttributeLimits model, SpiHelper spiHelper, List<Closeable> closeables) {
LogLimitsBuilder builder = LogLimits.builder();

AttributeLimits attributeLimitsModel = model.getAttributeLimits();
AttributeLimitsModel attributeLimitsModel = model.getAttributeLimits();
if (attributeLimitsModel != null) {
if (attributeLimitsModel.getAttributeCountLimit() != null) {
builder.setMaxNumberOfAttributes(attributeLimitsModel.getAttributeCountLimit());
Expand All @@ -38,7 +38,7 @@ public LogLimits create(
}
}

LogRecordLimits logRecordLimitsModel = model.getLogRecordLimits();
LogRecordLimitsModel logRecordLimitsModel = model.getLogRecordLimits();
if (logRecordLimitsModel != null) {
if (logRecordLimitsModel.getAttributeCountLimit() != null) {
builder.setMaxNumberOfAttributes(logRecordLimitsModel.getAttributeCountLimit());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@

import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.Otlp;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.LogRecordExporterModel;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OtlpModel;
import io.opentelemetry.sdk.logs.export.LogRecordExporter;
import java.io.Closeable;
import java.util.List;
import java.util.Map;

final class LogRecordExporterFactory
implements Factory<
io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.LogRecordExporter,
LogRecordExporter> {
final class LogRecordExporterFactory implements Factory<LogRecordExporterModel, LogRecordExporter> {

private static final LogRecordExporterFactory INSTANCE = new LogRecordExporterFactory();

Expand All @@ -30,10 +28,8 @@ static LogRecordExporterFactory getInstance() {

@Override
public LogRecordExporter create(
io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.LogRecordExporter model,
SpiHelper spiHelper,
List<Closeable> closeables) {
Otlp otlpModel = model.getOtlp();
LogRecordExporterModel model, SpiHelper spiHelper, List<Closeable> closeables) {
OtlpModel otlpModel = model.getOtlp();
if (otlpModel != null) {
model.getAdditionalProperties().put("otlp", otlpModel);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
package io.opentelemetry.sdk.extension.incubator.fileconfig;

import com.google.auto.value.AutoValue;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.AttributeLimits;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.LogRecordLimits;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.AttributeLimitsModel;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.LogRecordLimitsModel;
import javax.annotation.Nullable;

@AutoValue
abstract class LogRecordLimitsAndAttributeLimits {

static LogRecordLimitsAndAttributeLimits create(
@Nullable AttributeLimits attributeLimits, @Nullable LogRecordLimits spanLimits) {
@Nullable AttributeLimitsModel attributeLimits, @Nullable LogRecordLimitsModel spanLimits) {
return new AutoValue_LogRecordLimitsAndAttributeLimits(attributeLimits, spanLimits);
}

@Nullable
abstract AttributeLimits getAttributeLimits();
abstract AttributeLimitsModel getAttributeLimits();

@Nullable
abstract LogRecordLimits getLogRecordLimits();
abstract LogRecordLimitsModel getLogRecordLimits();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@

import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.LogRecordExporter;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.BatchLogRecordProcessorModel;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.LogRecordExporterModel;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.LogRecordProcessorModel;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.SimpleLogRecordProcessorModel;
import io.opentelemetry.sdk.logs.LogRecordProcessor;
import io.opentelemetry.sdk.logs.export.BatchLogRecordProcessor;
import io.opentelemetry.sdk.logs.export.BatchLogRecordProcessorBuilder;
Expand All @@ -20,9 +23,7 @@
import java.util.Map;

final class LogRecordProcessorFactory
implements Factory<
io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.LogRecordProcessor,
LogRecordProcessor> {
implements Factory<LogRecordProcessorModel, LogRecordProcessor> {

private static final LogRecordProcessorFactory INSTANCE = new LogRecordProcessorFactory();

Expand All @@ -34,13 +35,10 @@ static LogRecordProcessorFactory getInstance() {

@Override
public LogRecordProcessor create(
io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.LogRecordProcessor model,
SpiHelper spiHelper,
List<Closeable> closeables) {
io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.BatchLogRecordProcessor
batchModel = model.getBatch();
LogRecordProcessorModel model, SpiHelper spiHelper, List<Closeable> closeables) {
BatchLogRecordProcessorModel batchModel = model.getBatch();
if (batchModel != null) {
LogRecordExporter exporterModel =
LogRecordExporterModel exporterModel =
FileConfigUtil.requireNonNull(
batchModel.getExporter(), "batch log record processor exporter");

Expand All @@ -62,10 +60,9 @@ public LogRecordProcessor create(
return FileConfigUtil.addAndReturn(closeables, builder.build());
}

io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.SimpleLogRecordProcessor
simpleModel = model.getSimple();
SimpleLogRecordProcessorModel simpleModel = model.getSimple();
if (simpleModel != null) {
LogRecordExporter exporterModel =
LogRecordExporterModel exporterModel =
FileConfigUtil.requireNonNull(
simpleModel.getExporter(), "simple log record processor exporter");
io.opentelemetry.sdk.logs.export.LogRecordExporter logRecordExporter =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@
package io.opentelemetry.sdk.extension.incubator.fileconfig;

import com.google.auto.value.AutoValue;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.AttributeLimits;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.LoggerProvider;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.AttributeLimitsModel;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.LoggerProviderModel;
import javax.annotation.Nullable;

@AutoValue
abstract class LoggerProviderAndAttributeLimits {

static LoggerProviderAndAttributeLimits create(
@Nullable AttributeLimits attributeLimits, @Nullable LoggerProvider loggerProvider) {
@Nullable AttributeLimitsModel attributeLimits,
@Nullable LoggerProviderModel loggerProvider) {
return new AutoValue_LoggerProviderAndAttributeLimits(attributeLimits, loggerProvider);
}

@Nullable
abstract AttributeLimits getAttributeLimits();
abstract AttributeLimitsModel getAttributeLimits();

@Nullable
abstract LoggerProvider getLoggerProvider();
abstract LoggerProviderModel getLoggerProvider();
}
Loading
Loading