Skip to content
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
11 changes: 6 additions & 5 deletions smoke-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ otelJava {

val dockerJavaVersion = "3.6.0"
dependencies {
testCompileOnly("com.google.auto.value:auto-value-annotations")
testAnnotationProcessor("com.google.auto.value:auto-value")
compileOnly("com.google.auto.value:auto-value-annotations")
annotationProcessor("com.google.auto.value:auto-value")

api("org.spockframework:spock-core")
api(project(":testing-common"))
Expand All @@ -34,12 +34,13 @@ dependencies {
implementation("io.grpc:grpc-protobuf")
implementation("io.grpc:grpc-stub")

testImplementation("com.github.docker-java:docker-java-core:$dockerJavaVersion")
testImplementation("com.github.docker-java:docker-java-transport-httpclient5:$dockerJavaVersion")
implementation("com.github.docker-java:docker-java-core:$dockerJavaVersion")
implementation("com.github.docker-java:docker-java-transport-httpclient5:$dockerJavaVersion")

// make IntelliJ see shaded Armeria and protobuf
compileOnly(project(":testing:armeria-shaded-for-testing", configuration = "shadow"))
testCompileOnly(project(":testing:armeria-shaded-for-testing", configuration = "shadow"))
testCompileOnly(project(":testing:proto-shaded-for-testing", configuration = "shadow"))
compileOnly(project(":testing:proto-shaded-for-testing", configuration = "shadow"))
}

tasks {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.smoketest;

import io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceRequest;
import java.util.Collection;

public class MetricsInspector {
final Collection<ExportMetricsServiceRequest> requests;

public MetricsInspector(Collection<ExportMetricsServiceRequest> requests) {
this.requests = requests;
}

public boolean hasMetricsNamed(String metricName) {
return requests.stream()
.flatMap(it -> it.getResourceMetricsList().stream())
.flatMap(it -> it.getScopeMetricsList().stream())
.flatMap(it -> it.getMetricsList().stream())
.anyMatch(it -> metricName.equals(it.getName()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.smoketest;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.protobuf.GeneratedMessage;
import com.google.protobuf.util.JsonFormat;
import io.opentelemetry.proto.collector.logs.v1.ExportLogsServiceRequest;
import io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceRequest;
import io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest;
import io.opentelemetry.testing.internal.armeria.client.WebClient;
import java.util.Collection;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

public class TelemetryRetriever {
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

final WebClient client;

TelemetryRetriever(int backendPort) {
client = WebClient.of("http://localhost:" + backendPort);
}

void clearTelemetry() {
client.get("/clear").aggregate().join();
}

Collection<ExportTraceServiceRequest> waitForTraces() {
return waitForTelemetry("get-traces", ExportTraceServiceRequest::newBuilder);
}

Collection<ExportMetricsServiceRequest> waitForMetrics() {
return waitForTelemetry("get-metrics", ExportMetricsServiceRequest::newBuilder);
}

Collection<ExportLogsServiceRequest> waitForLogs() {
return waitForTelemetry("get-logs", ExportLogsServiceRequest::newBuilder);
}

@SuppressWarnings({"unchecked", "InterruptedExceptionSwallowed"})
private <T extends GeneratedMessage, B extends GeneratedMessage.Builder<?>>
Collection<T> waitForTelemetry(String path, Supplier<B> builderConstructor) {
try {
String content = waitForContent(path);

return StreamSupport.stream(OBJECT_MAPPER.readTree(content).spliterator(), false)
.map(
jsonNode -> {
B builder = builderConstructor.get();
// TODO: Register parser into object mapper to avoid de -> re -> deserialize.
try {
String json = OBJECT_MAPPER.writeValueAsString(jsonNode);
JsonFormat.parser().merge(json, builder);
} catch (Exception e) {
throw new IllegalStateException(e);
}
return (T) builder.build();
})
.collect(Collectors.toList());
} catch (Exception e) {
throw new IllegalStateException(e);
}
}

@SuppressWarnings("SystemOut")
private String waitForContent(String path) throws InterruptedException {
long previousSize = 0;
long deadline = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(30);
String content = "[]";
while (System.currentTimeMillis() < deadline) {
content = client.get(path).aggregate().join().contentUtf8();
if (content.length() > 2 && content.length() == previousSize) {
break;
}
previousSize = content.length();
System.out.println("Current content size $previousSize");
TimeUnit.MILLISECONDS.sleep(500);
}

return content;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public long countFilteredResourceAttributes(String attributeName, Object attribu
}

public long countFilteredAttributes(String attributeName, Object attributeValue) {
final Object value;
Object value;
if (attributeValue instanceof GString) {
value = attributeValue.toString();
} else {
Expand All @@ -67,7 +67,7 @@ public long countFilteredAttributes(String attributeName, Object attributeValue)
}

public long countFilteredArrayAttributes(String attributeName, Object attributeValue) {
final Object value;
Object value;
if (attributeValue instanceof GString) {
value = attributeValue.toString();
} else {
Expand Down

This file was deleted.

This file was deleted.