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

Add TestLogData, remove public LogDataImpl and LogDataBuilder from log SDK #4635

Merged
merged 2 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions exporters/logging-otlp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies {
implementation("com.fasterxml.jackson.core:jackson-core")

testImplementation(project(":sdk:testing"))
testImplementation(project(":sdk:logs-testing"))
testImplementation(project(":sdk:logs"))
testImplementation(project(":sdk:metrics"))
testImplementation(project(":sdk:trace"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
import io.opentelemetry.internal.testing.slf4j.SuppressLogger;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.logs.data.LogData;
import io.opentelemetry.sdk.logs.data.LogDataBuilder;
import io.opentelemetry.sdk.logs.data.Severity;
import io.opentelemetry.sdk.logs.export.LogExporter;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.testing.logs.TestLogData;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -37,7 +37,10 @@ class OtlpJsonLoggingLogExporterTest {
Resource.create(Attributes.builder().put("key", "value").build());

private static final LogData LOG1 =
LogDataBuilder.create(RESOURCE, InstrumentationScopeInfo.create("instrumentation", "1", null))
TestLogData.builder()
.setResource(RESOURCE)
.setInstrumentationScopeInfo(
InstrumentationScopeInfo.create("instrumentation", "1", null))
.setBody("body1")
.setSeverity(Severity.INFO)
.setSeverityText("INFO")
Expand All @@ -52,8 +55,10 @@ class OtlpJsonLoggingLogExporterTest {
.build();

private static final LogData LOG2 =
LogDataBuilder.create(
RESOURCE, InstrumentationScopeInfo.create("instrumentation2", "2", null))
TestLogData.builder()
.setResource(RESOURCE)
.setInstrumentationScopeInfo(
InstrumentationScopeInfo.create("instrumentation2", "2", null))
.setBody("body2")
.setSeverity(Severity.INFO)
.setSeverityText("INFO")
Expand Down
1 change: 1 addition & 0 deletions exporters/logging/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ dependencies {
api(project(":sdk:logs"))

testImplementation(project(":sdk:testing"))
testImplementation(project(":sdk:logs-testing"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.logs.data.LogData;
import io.opentelemetry.sdk.logs.data.LogDataBuilder;
import io.opentelemetry.sdk.logs.data.Severity;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.testing.logs.TestLogData;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.ZoneOffset;
Expand Down Expand Up @@ -51,8 +51,9 @@ void format() {
}

private static LogData sampleLog(long timestamp) {
return LogDataBuilder.create(
Resource.empty(), InstrumentationScopeInfo.create("logTest", "1.0", null))
return TestLogData.builder()
.setResource(Resource.empty())
.setInstrumentationScopeInfo(InstrumentationScopeInfo.create("logTest", "1.0", null))
.setAttributes(Attributes.of(stringKey("cheese"), "cheddar", longKey("amount"), 1L))
.setBody("message")
.setSeverity(Severity.ERROR3)
Expand Down
1 change: 1 addition & 0 deletions exporters/otlp/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dependencies {
testImplementation(project(":sdk:trace"))
testImplementation(project(":sdk:logs"))
testImplementation(project(":sdk:testing"))
testImplementation(project(":sdk:logs-testing"))

testImplementation("com.fasterxml.jackson.core:jackson-databind")
testImplementation("com.google.protobuf:protobuf-java-util")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
import io.opentelemetry.proto.logs.v1.ResourceLogs;
import io.opentelemetry.proto.logs.v1.ScopeLogs;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.logs.data.LogDataBuilder;
import io.opentelemetry.sdk.logs.data.Severity;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.testing.logs.TestLogData;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
Expand All @@ -53,8 +53,10 @@ void toProtoResourceLogs() {
ResourceLogsMarshaler[] resourceLogsMarshalers =
ResourceLogsMarshaler.create(
Collections.singleton(
LogDataBuilder.create(
Resource.builder().put("one", 1).setSchemaUrl("http://url").build(),
TestLogData.builder()
.setResource(
Resource.builder().put("one", 1).setSchemaUrl("http://url").build())
.setInstrumentationScopeInfo(
InstrumentationScopeInfo.create("testLib", "1.0", "http://url"))
.setBody(BODY)
.setSeverity(Severity.INFO)
Expand Down Expand Up @@ -84,8 +86,10 @@ void toProtoLogRecord() {
parse(
LogRecord.getDefaultInstance(),
LogMarshaler.create(
LogDataBuilder.create(
Resource.create(Attributes.builder().put("testKey", "testValue").build()),
TestLogData.builder()
.setResource(
Resource.create(Attributes.builder().put("testKey", "testValue").build()))
.setInstrumentationScopeInfo(
InstrumentationScopeInfo.create("instrumentation", "1", null))
.setBody(BODY)
.setSeverity(Severity.INFO)
Expand Down Expand Up @@ -116,8 +120,10 @@ void toProtoLogRecord_MinimalFields() {
parse(
LogRecord.getDefaultInstance(),
LogMarshaler.create(
LogDataBuilder.create(
Resource.create(Attributes.builder().put("testKey", "testValue").build()),
TestLogData.builder()
.setResource(
Resource.create(Attributes.builder().put("testKey", "testValue").build()))
.setInstrumentationScopeInfo(
InstrumentationScopeInfo.create("instrumentation", "1", null))
.setEpoch(12345, TimeUnit.NANOSECONDS)
.build()));
Expand Down
4 changes: 4 additions & 0 deletions exporters/otlp/logs/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies {
compileOnly("io.grpc:grpc-stub")

testImplementation(project(":exporters:otlp:testing-internal"))
testImplementation(project(":sdk:logs-testing"))

testImplementation("com.linecorp.armeria:armeria-junit5")
testImplementation("com.google.api.grpc:proto-google-common-protos")
Expand All @@ -27,6 +28,7 @@ testing {
val testGrpcNetty by registering(JvmTestSuite::class) {
dependencies {
implementation(project(":exporters:otlp:testing-internal"))
implementation(project(":sdk:logs-testing"))

implementation("io.grpc:grpc-netty")
implementation("io.grpc:grpc-stub")
Expand All @@ -35,6 +37,7 @@ testing {
val testGrpcNettyShaded by registering(JvmTestSuite::class) {
dependencies {
implementation(project(":exporters:otlp:testing-internal"))
implementation(project(":sdk:logs-testing"))

implementation("io.grpc:grpc-netty-shaded")
implementation("io.grpc:grpc-stub")
Expand All @@ -43,6 +46,7 @@ testing {
val testGrpcOkhttp by registering(JvmTestSuite::class) {
dependencies {
implementation(project(":exporters:otlp:testing-internal"))
implementation(project(":sdk:logs-testing"))

implementation("io.grpc:grpc-okhttp")
implementation("io.grpc:grpc-stub")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.logs.data.LogData;
import io.opentelemetry.sdk.logs.data.LogDataBuilder;
import io.opentelemetry.sdk.logs.data.Severity;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.testing.logs.TestLogData;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
Expand Down Expand Up @@ -339,8 +339,10 @@ private static <T extends Message> HttpResponse buildResponse(HttpStatus httpSta
}

private static LogData generateFakeLog() {
return LogDataBuilder.create(
Resource.getDefault(), InstrumentationScopeInfo.create("testLib", "1.0", "http://url"))
return TestLogData.builder()
.setResource(Resource.getDefault())
.setInstrumentationScopeInfo(
InstrumentationScopeInfo.create("testLib", "1.0", "http://url"))
.setBody("log body")
.setAttributes(Attributes.builder().put("key", "value").build())
.setSeverity(Severity.INFO)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
import io.opentelemetry.proto.logs.v1.ResourceLogs;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.logs.data.LogData;
import io.opentelemetry.sdk.logs.data.LogDataBuilder;
import io.opentelemetry.sdk.logs.data.Severity;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.testing.logs.TestLogData;
import java.io.Closeable;
import java.time.Instant;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;

class OtlpGrpcLogExporterTest extends AbstractGrpcTelemetryExporterTest<LogData, ResourceLogs> {
Expand Down Expand Up @@ -56,10 +57,10 @@ protected TelemetryExporterBuilder<LogData> exporterBuilder() {

@Override
protected LogData generateFakeTelemetry() {
return LogDataBuilder.create(
Resource.create(Attributes.builder().put("testKey", "testValue").build()),
InstrumentationScopeInfo.create("instrumentation", "1", null))
.setEpoch(Instant.now())
return TestLogData.builder()
.setResource(Resource.create(Attributes.builder().put("testKey", "testValue").build()))
.setInstrumentationScopeInfo(InstrumentationScopeInfo.create("instrumentation", "1", null))
.setEpoch(Instant.now().toEpochMilli(), TimeUnit.MILLISECONDS)
.setSeverity(Severity.ERROR)
.setSeverityText("really severe")
.setBody("message")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
import io.opentelemetry.proto.logs.v1.ResourceLogs;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.logs.data.LogData;
import io.opentelemetry.sdk.logs.data.LogDataBuilder;
import io.opentelemetry.sdk.logs.data.Severity;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.testing.logs.TestLogData;
import java.io.Closeable;
import java.time.Instant;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;

class OtlpGrpcNettyLogExporterTest
Expand Down Expand Up @@ -64,10 +65,10 @@ protected TelemetryExporterBuilder<LogData> exporterBuilder() {

@Override
protected LogData generateFakeTelemetry() {
return LogDataBuilder.create(
Resource.create(Attributes.builder().put("testKey", "testValue").build()),
InstrumentationScopeInfo.create("instrumentation", "1", null))
.setEpoch(Instant.now())
return TestLogData.builder()
.setResource(Resource.create(Attributes.builder().put("testKey", "testValue").build()))
.setInstrumentationScopeInfo(InstrumentationScopeInfo.create("instrumentation", "1", null))
.setEpoch(Instant.now().toEpochMilli(), TimeUnit.MILLISECONDS)
.setSeverity(Severity.ERROR)
.setSeverityText("really severe")
.setBody("message")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
import io.opentelemetry.proto.logs.v1.ResourceLogs;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.logs.data.LogData;
import io.opentelemetry.sdk.logs.data.LogDataBuilder;
import io.opentelemetry.sdk.logs.data.Severity;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.testing.logs.TestLogData;
import java.io.Closeable;
import java.time.Instant;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;

class OtlpGrpcNettyShadedLogExporterTest
Expand Down Expand Up @@ -52,10 +53,10 @@ protected TelemetryExporterBuilder<LogData> exporterBuilder() {

@Override
protected LogData generateFakeTelemetry() {
return LogDataBuilder.create(
Resource.create(Attributes.builder().put("testKey", "testValue").build()),
InstrumentationScopeInfo.create("instrumentation", "1", null))
.setEpoch(Instant.now())
return TestLogData.builder()
.setResource(Resource.create(Attributes.builder().put("testKey", "testValue").build()))
.setInstrumentationScopeInfo(InstrumentationScopeInfo.create("instrumentation", "1", null))
.setEpoch(Instant.now().toEpochMilli(), TimeUnit.MILLISECONDS)
.setSeverity(Severity.ERROR)
.setSeverityText("really severe")
.setBody("message")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
import io.opentelemetry.proto.logs.v1.ResourceLogs;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.logs.data.LogData;
import io.opentelemetry.sdk.logs.data.LogDataBuilder;
import io.opentelemetry.sdk.logs.data.Severity;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.testing.logs.TestLogData;
import java.io.Closeable;
import java.time.Instant;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;

class OtlpGrpcNettyOkHttpLogExporterTest
Expand Down Expand Up @@ -52,10 +53,10 @@ protected TelemetryExporterBuilder<LogData> exporterBuilder() {

@Override
protected LogData generateFakeTelemetry() {
return LogDataBuilder.create(
Resource.create(Attributes.builder().put("testKey", "testValue").build()),
InstrumentationScopeInfo.create("instrumentation", "1", null))
.setEpoch(Instant.now())
return TestLogData.builder()
.setResource(Resource.create(Attributes.builder().put("testKey", "testValue").build()))
.setInstrumentationScopeInfo(InstrumentationScopeInfo.create("instrumentation", "1", null))
.setEpoch(Instant.now().toEpochMilli(), TimeUnit.MILLISECONDS)
.setSeverity(Severity.ERROR)
.setSeverityText("really severe")
.setBody("message")
Expand Down
1 change: 1 addition & 0 deletions sdk-extensions/autoconfigure/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ testing {
implementation(project(":exporters:otlp:logs"))
implementation(project(":exporters:otlp:common"))
implementation(project(":sdk:testing"))
implementation(project(":sdk:logs-testing"))

implementation("io.opentelemetry.proto:opentelemetry-proto")
implementation("com.linecorp.armeria:armeria-junit5")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,21 @@
import io.opentelemetry.proto.collector.trace.v1.TraceServiceGrpc;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.logs.data.LogData;
import io.opentelemetry.sdk.logs.data.LogDataBuilder;
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
import io.opentelemetry.sdk.metrics.data.MetricData;
import io.opentelemetry.sdk.metrics.internal.data.ImmutableLongPointData;
import io.opentelemetry.sdk.metrics.internal.data.ImmutableMetricData;
import io.opentelemetry.sdk.metrics.internal.data.ImmutableSumData;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.testing.logs.TestLogData;
import io.opentelemetry.sdk.testing.trace.TestSpanData;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.sdk.trace.data.StatusData;
import java.time.Instant;
import java.util.ArrayDeque;
import java.util.Collections;
import java.util.Queue;
import java.util.concurrent.TimeUnit;

class OtlpGrpcServerExtension extends ServerExtension {

Expand Down Expand Up @@ -164,8 +165,10 @@ static MetricData generateFakeMetric() {
}

static LogData generateFakeLog() {
return LogDataBuilder.create(Resource.empty(), InstrumentationScopeInfo.empty())
.setEpoch(Instant.now())
return TestLogData.builder()
.setResource(Resource.empty())
.setInstrumentationScopeInfo(InstrumentationScopeInfo.empty())
.setEpoch(Instant.now().toEpochMilli(), TimeUnit.MILLISECONDS)
jack-berg marked this conversation as resolved.
Show resolved Hide resolved
.setBody("log body")
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
import io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.logs.data.LogData;
import io.opentelemetry.sdk.logs.data.LogDataBuilder;
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
import io.opentelemetry.sdk.metrics.data.MetricData;
import io.opentelemetry.sdk.metrics.internal.data.ImmutableLongPointData;
import io.opentelemetry.sdk.metrics.internal.data.ImmutableMetricData;
import io.opentelemetry.sdk.metrics.internal.data.ImmutableSumData;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.testing.logs.TestLogData;
import io.opentelemetry.sdk.testing.trace.TestSpanData;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.sdk.trace.data.StatusData;
Expand Down Expand Up @@ -147,7 +147,9 @@ static MetricData generateFakeMetric() {
}

static LogData generateFakeLog() {
return LogDataBuilder.create(Resource.empty(), InstrumentationScopeInfo.empty())
return TestLogData.builder()
.setResource(Resource.empty())
.setInstrumentationScopeInfo(InstrumentationScopeInfo.empty())
.setEpoch(Instant.now())
.setBody("log body")
.build();
Expand Down
2 changes: 2 additions & 0 deletions sdk/logs-testing/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ dependencies {

annotationProcessor("com.google.auto.value:auto-value")

testImplementation(project(":sdk:logs-testing"))

testImplementation("junit:junit")
}
Loading