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

Request response payload capture verify by smoke test #273

Merged
6 changes: 6 additions & 0 deletions smoke-tests/matrix/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ def targets = [
"9.0.40" : ["8", "11"],
"10.0.0" : ["8", "11"]
],
"tomee": [
[version: ["7.0.0"], vm: ["hotspot"], jdk: ["8"]],
[version: ["8.0.6"], vm: ["hotspot"], jdk: ["8", "11"]],
[version: ["7.0.0"], vm: ["openj9"], jdk: ["8"], dockerfile: "tomee-custom"],
[version: ["8.0.6"], vm: ["openj9"], jdk: ["8", "11"], dockerfile: "tomee-custom"]
],
"payara" : [
"5.2020.6" : ["8"],
"5.2020.6-jdk11": ["11"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

package org.hypertrace.agent.smoketest

import okhttp3.MediaType
import okhttp3.RequestBody

import static org.junit.Assume.assumeTrue

import io.opentelemetry.proto.trace.v1.Span
import java.util.jar.Attributes
import java.util.jar.JarFile
import okhttp3.Request
import org.junit.runner.RunWith
import spock.lang.Shared
Expand Down Expand Up @@ -56,17 +57,13 @@ abstract class AppServerTest extends SmokeTest {

String url = "http://localhost:${target.getMappedPort(8080)}/app/greeting"
def request = new Request.Builder().url(url).get().build()
//def currentAgentVersion = new JarFile(agentPath).getManifest().getMainAttributes().get(Attributes.Name
//.IMPLEMENTATION_VERSION)

when:
def response = CLIENT.newCall(request).execute()
TraceInspector traces = new TraceInspector(waitForTraces())
Set<String> traceIds = traces.traceIds
String responseBody = response.body().string()

println traces.getSpanStream().forEach({ span -> "************** " + span.toString() + " *******************************" });

then: "There is one trace"
traceIds.size() == 1

Expand All @@ -93,12 +90,64 @@ abstract class AppServerTest extends SmokeTest {
[appServer, jdk] << getTestParams()
}

@Unroll
def "#appServer request response capture test smoke test on JDK #jdk"(String appServer, String jdk) {
assumeTrue(testSmoke())

String url = "http://localhost:${target.getMappedPort(8080)}/app/echo"
MediaType JSON = MediaType.parse("application/json; charset=utf-8")
String requestData = "{\"greeting\" : \"Hello\",\"name\" : \"John\"}"
RequestBody requestBody = RequestBody.create(requestData, JSON);
def request = new Request.Builder().url(url).post(requestBody).build();

when:
def response = CLIENT.newCall(request).execute()
TraceInspector traces = new TraceInspector(waitForTraces())
Set<String> traceIds = traces.traceIds
String headerValue = new String(Base64.getDecoder().decode(response.header("Header-Dump")));

then: "There is one trace"
traceIds.size() == 1

and: "trace id is present in the HTTP headers as reported by the called endpoint"
headerValue.contains(traceIds.find())

and: "Server spans in the distributed trace"
traces.countSpansByKind(Span.SpanKind.SPAN_KIND_SERVER) == 2

and: "Expected span names"
traces.countSpansByName(getSpanName('/app/echo')) == 1
traces.countSpansByName(getSpanName('/app/headers')) == 1

and: "The span for the initial web request"
traces.countFilteredAttributes("http.url", url) == 1

and: "Client and server spans for the remote call"
traces.countFilteredAttributes("http.url", "http://localhost:8080/app/headers") == 2

and: "response body attribute should be present"
traces.countFilteredAttributes("http.response.body") == 1

and: "request body attribute should be present"
traces.countFilteredAttributes("http.request.body") == 1

and: "Request body should be same as sent content"
traces.getFilteredAttributeValue("http.request.body") == requestData

and: "Response body should be same as sent content"
traces.getFilteredAttributeValue("http.response.body") == requestData

cleanup:
response?.close()

where:
[appServer, jdk] << getTestParams()
}

@Unroll
def "#appServer test static file found on JDK #jdk"(String appServer, String jdk) {
String url = "http://localhost:${target.getMappedPort(8080)}/app/hello.txt"
def request = new Request.Builder().url(url).get().build()
//def currentAgentVersion = new JarFile(agentPath).getManifest().getMainAttributes().get(Attributes.Name
//.IMPLEMENTATION_VERSION)

when:
def response = CLIENT.newCall(request).execute()
Expand Down Expand Up @@ -132,8 +181,6 @@ abstract class AppServerTest extends SmokeTest {
def "#appServer test static file not found on JDK #jdk"(String appServer, String jdk) {
String url = "http://localhost:${target.getMappedPort(8080)}/app/file-that-does-not-exist"
def request = new Request.Builder().url(url).get().build()
//def currentAgentVersion = new JarFile(agentPath).getManifest().getMainAttributes().get(Attributes.Name
//.IMPLEMENTATION_VERSION)

when:
def response = CLIENT.newCall(request).execute()
Expand Down Expand Up @@ -168,8 +215,6 @@ abstract class AppServerTest extends SmokeTest {

String url = "http://localhost:${target.getMappedPort(8080)}/app/WEB-INF/web.xml"
def request = new Request.Builder().url(url).get().build()
//def currentAgentVersion = new JarFile(agentPath).getManifest().getMainAttributes().get(Attributes.Name
//.IMPLEMENTATION_VERSION)

when:
def response = CLIENT.newCall(request).execute()
Expand Down Expand Up @@ -204,8 +249,6 @@ abstract class AppServerTest extends SmokeTest {

String url = "http://localhost:${target.getMappedPort(8080)}/app/exception"
def request = new Request.Builder().url(url).get().build()
//def currentAgentVersion = new JarFile(agentPath).getManifest().getMainAttributes().get(Attributes.Name
//.IMPLEMENTATION_VERSION)

when:
def response = CLIENT.newCall(request).execute()
Expand Down Expand Up @@ -241,8 +284,6 @@ abstract class AppServerTest extends SmokeTest {
def "#appServer test request outside deployed application JDK #jdk"(String appServer, String jdk) {
String url = "http://localhost:${target.getMappedPort(8080)}/this-is-definitely-not-there-but-there-should-be-a-trace-nevertheless"
def request = new Request.Builder().url(url).get().build()
//def currentAgentVersion = new JarFile(agentPath).getManifest().getMainAttributes().get(Attributes.Name
//.IMPLEMENTATION_VERSION)

when:
def response = CLIENT.newCall(request).execute()
Expand Down Expand Up @@ -277,8 +318,6 @@ abstract class AppServerTest extends SmokeTest {

String url = "http://localhost:${target.getMappedPort(8080)}/app/asyncgreeting"
def request = new Request.Builder().url(url).get().build()
//def currentAgentVersion = new JarFile(agentPath).getManifest().getMainAttributes().get(Attributes.Name
//.IMPLEMENTATION_VERSION)

when:
def response = CLIENT.newCall(request).execute()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,45 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package org.hypertrace.agent.smoketest

class GlassfishSmokeTest {
import spock.lang.Ignore

import java.time.Duration
import org.testcontainers.containers.wait.strategy.Wait
import org.testcontainers.containers.wait.strategy.WaitStrategy

@Ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please create an issue and add a link here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

link to glassfish startup issues: #276

@AppServer(version = "5.2020.6", jdk = "8")
@AppServer(version = "5.2020.6-jdk11", jdk = "11")
class GlassFishSmokeTest extends AppServerTest {

protected String getTargetImage(String jdk, String serverVersion) {
"hypertrace/java-agent-test-containers:payara-${serverVersion}-jdk$jdk-20210224.596496007"
}

@Override
protected Map<String, String> getExtraEnv() {
return ["HZ_PHONE_HOME_ENABLED": "false"]
}

@Override
protected WaitStrategy getWaitStrategy() {
return Wait
.forLogMessage(".*app was successfully deployed.*", 1)
.withStartupTimeout(Duration.ofMinutes(3))
}

@Override
protected String getSpanName(String path) {
return path
}

@Override
boolean testRequestWebInfWebXml() {
false
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ package org.hypertrace.agent.smoketest
class JettySmokeTest extends AppServerTest {

protected String getTargetImage(String jdk, String serverVersion) {
"ghcr.io/open-telemetry/java-test-containers:jetty-${serverVersion}-jdk$jdk-20201215.422527843"
"hypertrace/java-agent-test-containers:jetty-${serverVersion}-jdk$jdk-20210224.596496007"
}

def getJettySpanName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import org.testcontainers.containers.wait.strategy.WaitStrategy
class LibertySmokeTest extends AppServerTest {

protected String getTargetImage(String jdk, String serverVersion) {
"ghcr.io/open-telemetry/java-test-containers:liberty-${serverVersion}-jdk$jdk-20201215.422527843"
"hypertrace/java-agent-test-containers:liberty-${serverVersion}-jdk$jdk-20210224.596496007"
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ abstract class SmokeTest extends Specification {
.withNetwork(network)
.withLogConsumer(output)
.withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger("smoke.tests.target")))
//.withCopyFileToContainer(MountableFile.forHostPath("/Users/samarth/Downloads/hypertrace-agent-all.jar"""),
//"""/opentelemetry-javaagent-all.jar")
.withCopyFileToContainer(MountableFile.forHostPath(agentPath), "/hypertrace-agent-all.jar")
.withEnv("JAVA_TOOL_OPTIONS", "-javaagent:/hypertrace-agent-all.jar -Dorg.hypertrace.agent.slf4j.simpleLogger.log.muzzleMatcher=true")
.withEnv("OTEL_BSP_MAX_EXPORT_BATCH_SIZE", "1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ package org.hypertrace.agent.smoketest
class TomcatSmokeTest extends AppServerTest {

protected String getTargetImage(String jdk, String serverVersion) {
"ghcr.io/open-telemetry/java-test-containers:tomcat-${serverVersion}-jdk$jdk-20201215.422527843"
"hypertrace/java-agent-test-containers:tomcat-${serverVersion}-jdk$jdk-20210224.596496007"
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@

package org.hypertrace.agent.smoketest

import spock.lang.Ignore

import java.time.Duration
import org.testcontainers.containers.wait.strategy.Wait
import org.testcontainers.containers.wait.strategy.WaitStrategy

@Ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is tomee also failing? If so create an issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the v.15.0 release did not have test for tomee . However it is present in latest code.
The the image matrix that is currently published is based on v.15.0 release so tomee test container images are missing in docker hub.
if you look for changes in current PR in file: smoke-tests/matrix/build.gradle
I have added config to publish the same.
Once this PR is merged, images will be published and I will create a follow up PR to enable this with new image tags.

@AppServer(version = "7.0.0", jdk = "8")
@AppServer(version = "8.0.6", jdk = "8")
@AppServer(version = "8.0.6", jdk = "11")
class TomeeSmokeTest extends AppServerTest {

protected String getTargetImage(String jdk, String serverVersion) {
"ghcr.io/open-telemetry/java-test-containers:tomee-${serverVersion}-jdk$jdk-20210202.531569197"
"hypertrace/java-agent-test-containers:tomee-${serverVersion}-jdk$jdk-20210224.596496007"
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ public long countFilteredAttributes(String attributeName, Object attributeValue)
.count();
}

public long countFilteredAttributes(String attributeName) {
return getSpanStream()
.flatMap(s -> s.getAttributesList().stream())
.filter(a -> a.getKey().equals(attributeName))
.map(a -> a.getValue().getStringValue())
.count();
}

public String getFilteredAttributeValue(String attributeName) {
return getSpanStream()
.flatMap(s -> s.getAttributesList().stream())
.filter(a -> a.getKey().equals(attributeName))
.map(a -> a.getValue().getStringValue())
.collect(Collectors.joining(","));
}

public long countFilteredEventAttributes(String attributeName, Object attributeValue) {
return getSpanStream()
.flatMap(s -> s.getEventsList().stream())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import spock.lang.Unroll
class WildflySmokeTest extends AppServerTest {

protected String getTargetImage(String jdk, String serverVersion) {
"ghcr.io/open-telemetry/java-test-containers:wildfly-${serverVersion}-jdk$jdk-20201215.422527843"
"hypertrace/java-agent-test-containers:wildfly-${serverVersion}-jdk$jdk-20210224.596496007"
}

@Override
Expand Down