Run smoke tests on different java versions (#948)
* Run smoke tests on different java versions * Cleaner Docker images names
This commit is contained in:
parent
a222676a3e
commit
51e06100ca
|
|
@ -8,7 +8,7 @@ on:
|
|||
branches: 'master'
|
||||
|
||||
jobs:
|
||||
test:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
|
@ -20,10 +20,11 @@ jobs:
|
|||
- name: Cache gradle dependencies
|
||||
uses: burrunan/gradle-cache-action@v1
|
||||
with:
|
||||
job-id: jdk11
|
||||
|
||||
- name: Login to GitHub Package Registry
|
||||
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login docker.pkg.github.com -u ${{ github.repository }} --password-stdin
|
||||
job-id: play-smoke
|
||||
|
||||
- name: Build Docker Image
|
||||
run: cd smoke-tests/play && ./gradlew jib
|
||||
run: |
|
||||
./gradlew jib -PtargetJDK=8 -Djib.httpTimeout=120000 -Djib.console=plain
|
||||
./gradlew jib -PtargetJDK=11 -Djib.httpTimeout=120000 -Djib.console=plain
|
||||
./gradlew jib -PtargetJDK=14 -Djib.httpTimeout=120000 -Djib.console=plain
|
||||
working-directory: smoke-tests/play
|
||||
|
|
@ -8,7 +8,7 @@ on:
|
|||
branches: 'master'
|
||||
|
||||
jobs:
|
||||
test:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
|
@ -20,10 +20,11 @@ jobs:
|
|||
- name: Cache gradle dependencies
|
||||
uses: burrunan/gradle-cache-action@v1
|
||||
with:
|
||||
job-id: jdk11
|
||||
|
||||
- name: Login to GitHub Package Registry
|
||||
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login docker.pkg.github.com -u ${{ github.repository }} --password-stdin
|
||||
job-id: springboot-smoke
|
||||
|
||||
- name: Build Docker Image
|
||||
run: cd smoke-tests/springboot && ./gradlew jib
|
||||
run: |
|
||||
./gradlew jib -PtargetJDK=8 -Djib.httpTimeout=120000 -Djib.console=plain
|
||||
./gradlew jib -PtargetJDK=11 -Djib.httpTimeout=120000 -Djib.console=plain
|
||||
./gradlew jib -PtargetJDK=14 -Djib.httpTimeout=120000 -Djib.console=plain
|
||||
working-directory: smoke-tests/springboot
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
plugins {
|
||||
id "org.gradle.playframework" version "0.9"
|
||||
id 'com.google.cloud.tools.jib' version '2.4.0'
|
||||
id 'com.google.cloud.tools.jib' version '2.5.0'
|
||||
}
|
||||
|
||||
ext {
|
||||
|
|
@ -35,8 +35,10 @@ dependencies {
|
|||
implementation "com.typesafe.play:filters-helpers_$scalaVersion:$playVersion"
|
||||
}
|
||||
|
||||
def targetJDK = project.hasProperty("targetJDK") ? project.targetJDK : 11
|
||||
|
||||
jib {
|
||||
from.image = "bellsoft/liberica-openjdk-alpine:11"
|
||||
to.image = "docker.pkg.github.com/open-telemetry/opentelemetry-java-instrumentation/smoke-play"
|
||||
from.image = "bellsoft/liberica-openjdk-alpine:$targetJDK"
|
||||
to.image = "docker.pkg.github.com/open-telemetry/opentelemetry-java-instrumentation/smoke-play-jdk$targetJDK"
|
||||
container.mainClass = "play.core.server.ProdServerStart"
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
|
|
|||
|
|
@ -1,67 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.opentelemetry.smoketest
|
||||
|
||||
import okhttp3.Request
|
||||
import spock.lang.Shared
|
||||
|
||||
class PlaySmokeTest extends AbstractServerSmokeTest {
|
||||
|
||||
static final HTTP_REQUEST_SPAN = 'LOGGED_SPAN GET /welcome'
|
||||
|
||||
@Shared
|
||||
File playDirectory = new File("${buildDirectory}/stage/main")
|
||||
|
||||
@Override
|
||||
ProcessBuilder createProcessBuilder() {
|
||||
String ext = System.getProperty("os.name").startsWith("Windows") ? ".bat" : ""
|
||||
ProcessBuilder processBuilder =
|
||||
new ProcessBuilder("${playDirectory}/bin/main" + ext)
|
||||
processBuilder.directory(playDirectory)
|
||||
|
||||
processBuilder.environment().put("JAVA_OPTS",
|
||||
defaultJavaProperties.join(" ")
|
||||
+ " -Dotel.exporter.jar=${exporterPath}"
|
||||
+ " -Dotel.exporter.logging.prefix=LOGGED_SPAN"
|
||||
+ " -Dconfig.file=${workingDirectory}/conf/application.conf -Dhttp.port=${httpPort}"
|
||||
+ " -Dhttp.address=127.0.0.1")
|
||||
return processBuilder
|
||||
}
|
||||
|
||||
def "welcome endpoint #n th time"() {
|
||||
setup:
|
||||
def spanCounter = new SpanCounter(logfile, [
|
||||
(HTTP_REQUEST_SPAN): 2,
|
||||
], 10000)
|
||||
String url = "http://localhost:$httpPort/welcome?id=$n"
|
||||
def request = new Request.Builder().url(url).get().build()
|
||||
|
||||
when:
|
||||
def response = client.newCall(request).execute()
|
||||
def spans = spanCounter.countSpans()
|
||||
|
||||
then:
|
||||
def responseBodyStr = response.body().string()
|
||||
responseBodyStr == "Welcome $n."
|
||||
response.code() == 200
|
||||
// A 'play-action' span and an 'akka-http-server' span
|
||||
spans[HTTP_REQUEST_SPAN] == 2
|
||||
|
||||
where:
|
||||
n << (1..200)
|
||||
}
|
||||
}
|
||||
|
|
@ -2,12 +2,11 @@ plugins {
|
|||
id 'org.springframework.boot' version '2.3.2.RELEASE'
|
||||
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
|
||||
id 'java'
|
||||
id 'com.google.cloud.tools.jib' version '2.4.0'
|
||||
id 'com.google.cloud.tools.jib' version '2.5.0'
|
||||
}
|
||||
|
||||
group = 'io.opentelemetry'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
sourceCompatibility = '8'
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
|
|
@ -15,9 +14,16 @@ repositories {
|
|||
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
implementation 'io.opentelemetry:opentelemetry-extension-auto-annotations:0.7.0'
|
||||
}
|
||||
|
||||
compileJava {
|
||||
options.release = 8
|
||||
}
|
||||
|
||||
def targetJDK = project.hasProperty("targetJDK") ? project.targetJDK : 11
|
||||
|
||||
jib {
|
||||
from.image = "bellsoft/liberica-openjdk-alpine:11"
|
||||
to.image = "docker.pkg.github.com/open-telemetry/opentelemetry-java-instrumentation/smoke-springboot"
|
||||
from.image = "bellsoft/liberica-openjdk-alpine:$targetJDK"
|
||||
to.image = "docker.pkg.github.com/open-telemetry/opentelemetry-java-instrumentation/smoke-springboot-jdk$targetJDK"
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
|
|
|||
|
|
@ -1,66 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.opentelemetry.smoketest
|
||||
|
||||
import okhttp3.Request
|
||||
|
||||
class SpringBootSmokeTest extends AbstractServerSmokeTest {
|
||||
|
||||
static final SERVLET_SPAN = "LOGGED_SPAN /greeting"
|
||||
static final HANDLER_SPAN = "LOGGED_SPAN WebController.greeting"
|
||||
static final WITH_SPAN = "LOGGED_SPAN WebController.withSpan"
|
||||
|
||||
@Override
|
||||
ProcessBuilder createProcessBuilder() {
|
||||
String springBootShadowJar = System.getProperty("io.opentelemetry.smoketest.springboot.shadowJar.path")
|
||||
|
||||
List<String> command = new ArrayList<>()
|
||||
command.add(javaPath())
|
||||
command.addAll(defaultJavaProperties)
|
||||
command.addAll((String[]) ["-Dotel.exporter.jar=${exporterPath}", "-Dotel.exporter.logging.prefix=LOGGED_SPAN", "-jar", springBootShadowJar, "--server.port=${httpPort}"])
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(command)
|
||||
processBuilder.directory(new File(buildDirectory))
|
||||
}
|
||||
|
||||
def "default home page #n th time"() {
|
||||
setup:
|
||||
def spanCounter = new SpanCounter(logfile, [
|
||||
(SERVLET_SPAN): 1,
|
||||
(HANDLER_SPAN): 1,
|
||||
(WITH_SPAN) : 1
|
||||
], 10000)
|
||||
String url = "http://localhost:${httpPort}/greeting"
|
||||
def request = new Request.Builder().url(url).get().build()
|
||||
|
||||
when:
|
||||
def response = client.newCall(request).execute()
|
||||
def spans = spanCounter.countSpans()
|
||||
|
||||
then:
|
||||
def responseBodyStr = response.body().string()
|
||||
responseBodyStr != null
|
||||
responseBodyStr.contains("Hi!")
|
||||
response.body().contentType().toString().contains("text/plain")
|
||||
response.code() == 200
|
||||
spans[SERVLET_SPAN] == 1
|
||||
spans[HANDLER_SPAN] == 1
|
||||
spans[WITH_SPAN] == 1
|
||||
|
||||
where:
|
||||
n << (1..200)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.opentelemetry.smoketest
|
||||
|
||||
import okhttp3.Request
|
||||
|
||||
/**
|
||||
* This is almost an exact copy of {@link SpringBootSmokeTest}.
|
||||
* The only difference is that this test does not use external exporter jar.
|
||||
* It thus verifies that agent has embedded exporter and can use it.
|
||||
*/
|
||||
class SpringBootSmokeWithEmbeddedExporterTest extends AbstractServerSmokeTest {
|
||||
|
||||
static final SERVLET_SPAN = "LOGGED_SPAN /greeting"
|
||||
static final HANDLER_SPAN = "LOGGED_SPAN WebController.greeting"
|
||||
static final WITH_SPAN = "LOGGED_SPAN WebController.withSpan"
|
||||
|
||||
@Override
|
||||
ProcessBuilder createProcessBuilder() {
|
||||
String springBootShadowJar = System.getProperty("io.opentelemetry.smoketest.springboot.shadowJar.path")
|
||||
|
||||
List<String> command = new ArrayList<>()
|
||||
command.add(javaPath())
|
||||
command.addAll(defaultJavaProperties)
|
||||
command.addAll((String[]) ["-Dotel.exporter=logging", "-Dotel.exporter.logging.prefix=LOGGED_SPAN", "-jar", springBootShadowJar, "--server.port=${httpPort}"])
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(command)
|
||||
processBuilder.directory(new File(buildDirectory))
|
||||
}
|
||||
|
||||
def "can monitor default home page"() {
|
||||
setup:
|
||||
def spanCounter = new SpanCounter(logfile, [
|
||||
(SERVLET_SPAN): 1,
|
||||
(HANDLER_SPAN): 1,
|
||||
(WITH_SPAN) : 1
|
||||
], 10000)
|
||||
String url = "http://localhost:${httpPort}/greeting"
|
||||
def request = new Request.Builder().url(url).get().build()
|
||||
|
||||
when:
|
||||
def response = client.newCall(request).execute()
|
||||
def spans = spanCounter.countSpans()
|
||||
|
||||
then:
|
||||
def responseBodyStr = response.body().string()
|
||||
responseBodyStr != null
|
||||
responseBodyStr.contains("Hi!")
|
||||
response.body().contentType().toString().contains("text/plain")
|
||||
response.code() == 200
|
||||
spans[SERVLET_SPAN] == 1
|
||||
spans[HANDLER_SPAN] == 1
|
||||
spans[WITH_SPAN] == 1
|
||||
}
|
||||
}
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.opentelemetry.smoketest
|
||||
|
||||
import okhttp3.Request
|
||||
|
||||
class SpringBootWithSamplingSmokeTest extends AbstractServerSmokeTest {
|
||||
|
||||
static final SERVLET_SPAN = "LOGGED_SPAN /greeting"
|
||||
static final HANDLER_SPAN = "LOGGED_SPAN WebController.greeting"
|
||||
static final WITH_SPAN = "LOGGED_SPAN WebController.withSpan"
|
||||
|
||||
static final double SAMPLER_PROBABILITY = 0.2
|
||||
static final int NUM_TRIES = 1000
|
||||
static final int ALLOWED_DEVIATION = 0.1 * NUM_TRIES
|
||||
|
||||
@Override
|
||||
ProcessBuilder createProcessBuilder() {
|
||||
String springBootShadowJar = System.getProperty("io.opentelemetry.smoketest.springboot.shadowJar.path")
|
||||
|
||||
List<String> command = new ArrayList<>()
|
||||
command.add(javaPath())
|
||||
command.addAll(defaultJavaProperties)
|
||||
command.addAll((String[]) ["-Dotel.exporter.jar=${exporterPath}", "-Dotel.exporter.logging.prefix=LOGGED_SPAN", "-jar", springBootShadowJar, "--server.port=${httpPort}"])
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(command)
|
||||
processBuilder.environment().put("OTEL_CONFIG_SAMPLER_PROBABILITY", "${SAMPLER_PROBABILITY}")
|
||||
processBuilder.directory(new File(buildDirectory))
|
||||
}
|
||||
|
||||
def "default home page with probability sampling enabled"() {
|
||||
setup:
|
||||
// since sampling is enabled, not really expecting to receive NUM_TRIES spans,
|
||||
// instead giving it 10 seconds and then checking below how many spans were received
|
||||
def spanCounter = new SpanCounter(logfile, [
|
||||
(SERVLET_SPAN): NUM_TRIES,
|
||||
(HANDLER_SPAN): NUM_TRIES,
|
||||
(WITH_SPAN) : NUM_TRIES
|
||||
], 10000)
|
||||
String url = "http://localhost:${httpPort}/greeting"
|
||||
def request = new Request.Builder().url(url).get().build()
|
||||
|
||||
when:
|
||||
for (int i = 1; i <= NUM_TRIES; i++) {
|
||||
client.newCall(request).execute()
|
||||
}
|
||||
def spans = spanCounter.countSpans()
|
||||
|
||||
then:
|
||||
Math.abs(spans[SERVLET_SPAN] - (SAMPLER_PROBABILITY * NUM_TRIES)) <= ALLOWED_DEVIATION
|
||||
Math.abs(spans[HANDLER_SPAN] - (SAMPLER_PROBABILITY * NUM_TRIES)) <= ALLOWED_DEVIATION
|
||||
Math.abs(spans[WITH_SPAN] - (SAMPLER_PROBABILITY * NUM_TRIES)) <= ALLOWED_DEVIATION
|
||||
}
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.opentelemetry.smoketest
|
||||
|
||||
|
||||
import io.opentelemetry.auto.test.utils.OkHttpUtils
|
||||
import io.opentelemetry.auto.test.utils.PortUtils
|
||||
import okhttp3.OkHttpClient
|
||||
import spock.lang.Shared
|
||||
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
abstract class AbstractServerSmokeTest extends AbstractSmokeTest {
|
||||
|
||||
@Shared
|
||||
int httpPort = PortUtils.randomOpenPort()
|
||||
|
||||
|
||||
protected OkHttpClient client = OkHttpUtils.client()
|
||||
|
||||
def setupSpec() {
|
||||
try {
|
||||
PortUtils.waitForPortToOpen(httpPort, 240, TimeUnit.SECONDS, testedProcess)
|
||||
} catch (e) {
|
||||
System.err.println(logfile.text)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.opentelemetry.smoketest
|
||||
|
||||
|
||||
import spock.lang.Shared
|
||||
import spock.lang.Specification
|
||||
|
||||
abstract class AbstractSmokeTest extends Specification {
|
||||
|
||||
@Shared
|
||||
protected String workingDirectory = System.getProperty("user.dir")
|
||||
@Shared
|
||||
protected String buildDirectory = System.getProperty("io.opentelemetry.smoketest.builddir")
|
||||
@Shared
|
||||
protected String shadowJarPath = System.getProperty("io.opentelemetry.smoketest.agent.shadowJar.path")
|
||||
|
||||
@Shared
|
||||
protected String[] defaultJavaProperties
|
||||
@Shared
|
||||
protected Process testedProcess
|
||||
|
||||
@Shared
|
||||
protected String exporterPath = System.getProperty("otel.exporter.jar")
|
||||
|
||||
@Shared
|
||||
protected File logfile
|
||||
|
||||
def countSpans(prefix) {
|
||||
return logfile.text.tokenize('\n').count {
|
||||
it.startsWith prefix
|
||||
}
|
||||
}
|
||||
|
||||
def setupSpec() {
|
||||
if (buildDirectory == null || shadowJarPath == null) {
|
||||
throw new AssertionError("Expected system properties not found. Smoke tests have to be run from Gradle. Please make sure that is the case.")
|
||||
}
|
||||
|
||||
defaultJavaProperties = [
|
||||
"-javaagent:${shadowJarPath}",
|
||||
"-Dio.opentelemetry.auto.slf4j.simpleLogger.defaultLogLevel=debug",
|
||||
"-Dorg.slf4j.simpleLogger.defaultLogLevel=debug"
|
||||
]
|
||||
|
||||
ProcessBuilder processBuilder = createProcessBuilder()
|
||||
|
||||
processBuilder.environment().put("JAVA_HOME", System.getProperty("java.home"))
|
||||
|
||||
// Setting configuration variables of batch span processor through env vars
|
||||
// This config is to immediately flush a batch of 1 span with delay of 10ms
|
||||
processBuilder.environment().put("OTEL_BSP_MAX_EXPORT_BATCH", "1")
|
||||
processBuilder.environment().put("OTEL_BSP_SCHEDULE_DELAY", "10")
|
||||
|
||||
processBuilder.redirectErrorStream(true)
|
||||
logfile = new File("${buildDirectory}/reports/testProcess.${this.getClass().getName()}.log")
|
||||
processBuilder.redirectOutput(ProcessBuilder.Redirect.to(logfile))
|
||||
|
||||
testedProcess = processBuilder.start()
|
||||
}
|
||||
|
||||
String javaPath() {
|
||||
String separator = System.getProperty("file.separator")
|
||||
return System.getProperty("java.home") + separator + "bin" + separator + "java"
|
||||
}
|
||||
|
||||
def cleanupSpec() {
|
||||
testedProcess?.waitForOrKill(1)
|
||||
}
|
||||
|
||||
abstract ProcessBuilder createProcessBuilder()
|
||||
}
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.opentelemetry.smoketest
|
||||
|
||||
class SpanCounter {
|
||||
|
||||
long expiration
|
||||
|
||||
final Map<String, Integer> targets
|
||||
|
||||
int totalTargets = 0
|
||||
|
||||
final Reader reader
|
||||
|
||||
final Map<String, Integer> counters
|
||||
|
||||
SpanCounter(File file, Map<String, Integer> targets, long timeout) {
|
||||
reader = file.newReader()
|
||||
reader.skip(file.length())
|
||||
|
||||
expiration = System.currentTimeMillis() + timeout
|
||||
this.targets = targets
|
||||
counters = new HashMap<>(targets.size())
|
||||
targets.keySet().each({
|
||||
totalTargets += targets[it]
|
||||
counters[it] = 0
|
||||
})
|
||||
}
|
||||
|
||||
Map<String, Integer> countSpans() {
|
||||
try {
|
||||
def line
|
||||
while (System.currentTimeMillis() < expiration) {
|
||||
line = reader.readLine()
|
||||
if (line) {
|
||||
println line
|
||||
for (def key : counters.keySet()) {
|
||||
if (line.startsWith(key)) {
|
||||
counters[key]++
|
||||
if (--totalTargets == 0) {
|
||||
// We hit our total target. We may or may not have gotten the right
|
||||
// number for each tag, but we're letting the caller sort that out!
|
||||
return counters
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Thread.sleep(10)
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
reader?.close()
|
||||
}
|
||||
return counters
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -21,12 +21,13 @@ import okhttp3.Request
|
|||
|
||||
class PlaySmokeTest extends SmokeTest {
|
||||
|
||||
protected String getTargetImage() {
|
||||
"docker.pkg.github.com/open-telemetry/opentelemetry-java-instrumentation/smoke-play:latest"
|
||||
protected String getTargetImage(int jdk) {
|
||||
"docker.pkg.github.com/open-telemetry/opentelemetry-java-instrumentation/smoke-play-jdk$jdk:latest"
|
||||
}
|
||||
|
||||
def "play smoke test"() {
|
||||
def "play smoke test on JDK #jdk"(int jdk) {
|
||||
setup:
|
||||
startTarget(jdk)
|
||||
String url = "http://localhost:${target.getMappedPort(8080)}/welcome?id=1"
|
||||
def request = new Request.Builder().url(url).get().build()
|
||||
|
||||
|
|
@ -39,6 +40,12 @@ class PlaySmokeTest extends SmokeTest {
|
|||
//Both play and akka-http support produce spans with the same name.
|
||||
//One internal, one SERVER
|
||||
countSpansByName(traces, 'GET /welcome') == 2
|
||||
|
||||
cleanup:
|
||||
stopTarget()
|
||||
|
||||
where:
|
||||
jdk << [8, 11, 14]
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,18 +44,9 @@ abstract class SmokeTest extends Specification {
|
|||
protected String agentPath = System.getProperty("io.opentelemetry.smoketest.agent.shadowJar.path")
|
||||
|
||||
@Shared
|
||||
protected GenericContainer target = new GenericContainer<>(getTargetImage())
|
||||
.withExposedPorts(8080)
|
||||
.withNetwork(network)
|
||||
.withLogConsumer(new Slf4jLogConsumer(logger))
|
||||
.withCopyFileToContainer(MountableFile.forHostPath(agentPath), "/opentelemetry-javaagent-all.jar")
|
||||
.withEnv("JAVA_TOOL_OPTIONS", "-javaagent:/opentelemetry-javaagent-all.jar")
|
||||
.withEnv("OTEL_BSP_MAX_EXPORT_BATCH", "1")
|
||||
.withEnv("OTEL_BSP_SCHEDULE_DELAY", "10")
|
||||
.withEnv("OTEL_OTLP_ENDPOINT", "collector:55680")
|
||||
.withEnv(extraEnv)
|
||||
protected GenericContainer target
|
||||
|
||||
protected abstract String getTargetImage()
|
||||
protected abstract String getTargetImage(int jdk)
|
||||
|
||||
/**
|
||||
* Subclasses can override this method to customise target application's environment
|
||||
|
|
@ -65,20 +56,42 @@ abstract class SmokeTest extends Specification {
|
|||
}
|
||||
|
||||
@Shared
|
||||
protected GenericContainer collector = new GenericContainer<>("otel/opentelemetry-collector-dev")
|
||||
.withNetwork(network)
|
||||
.withNetworkAliases("collector")
|
||||
.withLogConsumer(new Slf4jLogConsumer(logger))
|
||||
.withCopyFileToContainer(MountableFile.forClasspathResource("/otel.yaml"), "/etc/otel.yaml")
|
||||
.withCommand("--config /etc/otel.yaml")
|
||||
private GenericContainer collector
|
||||
|
||||
def setupSpec() {
|
||||
def setup() {
|
||||
//We have to recreate collector for every test to wipe exported file with traces
|
||||
collector = new GenericContainer<>("otel/opentelemetry-collector-dev")
|
||||
.withNetwork(network)
|
||||
.withNetworkAliases("collector")
|
||||
.withLogConsumer(new Slf4jLogConsumer(logger))
|
||||
.withCopyFileToContainer(MountableFile.forClasspathResource("/otel.yaml"), "/etc/otel.yaml")
|
||||
.withCommand("--config /etc/otel.yaml")
|
||||
collector.start()
|
||||
}
|
||||
|
||||
def startTarget(int jdk) {
|
||||
target = new GenericContainer<>(getTargetImage(jdk))
|
||||
.withExposedPorts(8080)
|
||||
.withNetwork(network)
|
||||
.withLogConsumer(new Slf4jLogConsumer(logger))
|
||||
.withCopyFileToContainer(MountableFile.forHostPath(agentPath), "/opentelemetry-javaagent-all.jar")
|
||||
.withEnv("JAVA_TOOL_OPTIONS", "-javaagent:/opentelemetry-javaagent-all.jar")
|
||||
.withEnv("OTEL_BSP_MAX_EXPORT_BATCH", "1")
|
||||
.withEnv("OTEL_BSP_SCHEDULE_DELAY", "10")
|
||||
.withEnv("OTEL_OTLP_ENDPOINT", "collector:55680")
|
||||
.withEnv(extraEnv)
|
||||
target.start()
|
||||
}
|
||||
|
||||
def cleanupSpec() {
|
||||
def cleanup() {
|
||||
collector.stop()
|
||||
}
|
||||
|
||||
def stopTarget() {
|
||||
target.stop()
|
||||
}
|
||||
|
||||
def cleanupSpec() {
|
||||
collector.stop()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,12 +21,13 @@ import okhttp3.Request
|
|||
|
||||
class SpringBootSmokeTest extends SmokeTest {
|
||||
|
||||
protected String getTargetImage() {
|
||||
"docker.pkg.github.com/open-telemetry/opentelemetry-java-instrumentation/smoke-springboot:latest"
|
||||
protected String getTargetImage(int jdk) {
|
||||
"docker.pkg.github.com/open-telemetry/opentelemetry-java-instrumentation/smoke-springboot-jdk$jdk:latest"
|
||||
}
|
||||
|
||||
def "spring boot smoke test"() {
|
||||
def "spring boot smoke test on JDK #jdk"(int jdk) {
|
||||
setup:
|
||||
startTarget(jdk)
|
||||
String url = "http://localhost:${target.getMappedPort(8080)}/greeting"
|
||||
def request = new Request.Builder().url(url).get().build()
|
||||
|
||||
|
|
@ -35,9 +36,16 @@ class SpringBootSmokeTest extends SmokeTest {
|
|||
Collection<ExportTraceServiceRequest> traces = waitForTraces()
|
||||
|
||||
then:
|
||||
response.body().string() == "Sup Dawg"
|
||||
response.body().string() == "Hi!"
|
||||
countSpansByName(traces, '/greeting') == 1
|
||||
countSpansByName(traces, 'WebController.greeting') == 1
|
||||
countSpansByName(traces, 'WebController.withSpan') == 1
|
||||
|
||||
cleanup:
|
||||
stopTarget()
|
||||
|
||||
where:
|
||||
jdk << [8, 11, 14]
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ class SpringBootWithSamplingSmokeTest extends SmokeTest {
|
|||
static final int NUM_TRIES = 1000
|
||||
static final int ALLOWED_DEVIATION = 0.1 * NUM_TRIES
|
||||
|
||||
protected String getTargetImage() {
|
||||
"docker.pkg.github.com/open-telemetry/opentelemetry-java-instrumentation/smoke-springboot:latest"
|
||||
protected String getTargetImage(int jdk) {
|
||||
"docker.pkg.github.com/open-telemetry/opentelemetry-java-instrumentation/smoke-springboot-jdk$jdk:latest"
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -34,8 +34,9 @@ class SpringBootWithSamplingSmokeTest extends SmokeTest {
|
|||
return ["OTEL_CONFIG_SAMPLER_PROBABILITY": String.valueOf(SAMPLER_PROBABILITY)]
|
||||
}
|
||||
|
||||
def "default home page with probability sampling enabled"() {
|
||||
def "spring boot with probability sampling enabled on JDK #jdk"(int jdk) {
|
||||
setup:
|
||||
startTarget(jdk)
|
||||
String url = "http://localhost:${target.getMappedPort(8080)}/greeting"
|
||||
def request = new Request.Builder().url(url).get().build()
|
||||
|
||||
|
|
@ -49,5 +50,11 @@ class SpringBootWithSamplingSmokeTest extends SmokeTest {
|
|||
// since sampling is enabled, not really expecting to receive NUM_TRIES spans
|
||||
Math.abs(countSpansByName(traces, 'WebController.greeting') - (SAMPLER_PROBABILITY * NUM_TRIES)) <= ALLOWED_DEVIATION
|
||||
Math.abs(countSpansByName(traces, '/greeting') - (SAMPLER_PROBABILITY * NUM_TRIES)) <= ALLOWED_DEVIATION
|
||||
|
||||
cleanup:
|
||||
stopTarget()
|
||||
|
||||
where:
|
||||
jdk << [8, 11, 14]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import okhttp3.Request
|
|||
|
||||
class WildflySmokeTest extends SmokeTest {
|
||||
|
||||
protected String getTargetImage() {
|
||||
protected String getTargetImage(int jdk) {
|
||||
"jboss/wildfly:latest"
|
||||
}
|
||||
|
||||
|
|
@ -29,6 +29,7 @@ class WildflySmokeTest extends SmokeTest {
|
|||
//So this test just verifies that Wildfly has come up.
|
||||
def "wildfly smoke test"() {
|
||||
setup:
|
||||
startTarget(11) // does not actually matter
|
||||
String url = "http://localhost:${target.getMappedPort(8080)}"
|
||||
def request = new Request.Builder().url(url).get().build()
|
||||
|
||||
|
|
@ -41,6 +42,9 @@ class WildflySmokeTest extends SmokeTest {
|
|||
responseBodyStr.contains("Your WildFly instance is running.")
|
||||
response.body().contentType().toString().contains("text/html")
|
||||
response.code() == 200
|
||||
|
||||
cleanup:
|
||||
stopTarget()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue