-
Notifications
You must be signed in to change notification settings - Fork 1k
convert groovy smoke tests to java, part 1 #14648
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
Changes from 14 commits
0e913af
a7c48f6
d6d7322
80278bd
b83306a
e357f58
959f4a5
301ce8e
5300d52
6999a3d
2c9ac75
2ed4ddb
5e8f1d2
745bab1
8cb9615
0fcfaff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.smoketest; | ||
|
|
||
| import java.time.Duration; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.condition.DisabledIf; | ||
|
|
||
| @DisabledIf("io.opentelemetry.smoketest.TestContainerManager#useWindowsContainers") | ||
| class AgentDebugLoggingTest extends JavaSmokeTest { | ||
| @Override | ||
| protected String getTargetImage(String jdk) { | ||
| return "ghcr.io/open-telemetry/opentelemetry-java-instrumentation/smoke-test-spring-boot:jdk" | ||
| + jdk | ||
| + "-20211213.1570880324"; | ||
| } | ||
|
|
||
| @Override | ||
| protected TargetWaitStrategy getWaitStrategy() { | ||
| return new TargetWaitStrategy.Log( | ||
| Duration.ofMinutes(1), ".*DEBUG io.opentelemetry.javaagent.tooling.VersionLogger.*"); | ||
| } | ||
|
|
||
| @DisplayName("verifies that debug logging is working by checking for a debug log on startup") | ||
| @Test | ||
| void verifyLogging() throws Exception { | ||
| withTarget(8, () -> {}); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.smoketest; | ||
|
|
||
| import static java.util.Collections.emptyList; | ||
| import static java.util.Collections.emptyMap; | ||
|
|
||
| import io.opentelemetry.sdk.logs.data.LogRecordData; | ||
| import io.opentelemetry.sdk.metrics.data.MetricData; | ||
| import io.opentelemetry.sdk.trace.data.SpanData; | ||
| import io.opentelemetry.smoketest.windows.WindowsTestContainerManager; | ||
| import io.opentelemetry.testing.internal.armeria.client.WebClient; | ||
| import java.util.Collection; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.function.Consumer; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.testcontainers.containers.output.OutputFrame; | ||
|
|
||
| public abstract class JavaSmokeTest { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not really a fan of using the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, waiting for ideas here - cound also rename the groovy classes to have a "Legacy" prefix |
||
| protected static final TestContainerManager containerManager = createContainerManager(); | ||
| private JavaTelemetryRetriever telemetryRetriever; | ||
|
|
||
| protected String agentPath = | ||
| System.getProperty("io.opentelemetry.smoketest.agent.shadowJar.path"); | ||
|
|
||
| protected WebClient client() { | ||
| return WebClient.of("h1c://localhost:" + containerManager.getTargetMappedPort(8080)); | ||
| } | ||
|
|
||
| /** Subclasses can override this method to pass jvm arguments in another environment variable */ | ||
| protected String getJvmArgsEnvVarName() { | ||
| return "JAVA_TOOL_OPTIONS"; | ||
| } | ||
|
|
||
| /** Subclasses can override this method to customise target application's environment */ | ||
| protected Map<String, String> getExtraEnv() { | ||
| return emptyMap(); | ||
| } | ||
|
|
||
| /** Subclasses can override this method to disable setting default service name */ | ||
| protected boolean getSetServiceName() { | ||
| return true; | ||
| } | ||
|
|
||
| /** Subclasses can override this method to provide additional files to copy to target container */ | ||
| protected List<ResourceMapping> getExtraResources() { | ||
| return emptyList(); | ||
| } | ||
|
|
||
| /** | ||
| * Subclasses can override this method to provide additional ports that should be exposed from the | ||
| * target container | ||
| */ | ||
| protected List<Integer> getExtraPorts() { | ||
| return emptyList(); | ||
| } | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| containerManager.startEnvironmentOnce(); | ||
| telemetryRetriever = new JavaTelemetryRetriever(containerManager.getBackendMappedPort()); | ||
| } | ||
|
|
||
| public void withTarget(int jdk, TargetRunner runner) throws Exception { | ||
| startTarget(jdk); | ||
| try { | ||
| runner.runInTarget(); | ||
| } finally { | ||
| stopTarget(); | ||
| } | ||
| } | ||
|
|
||
| public Consumer<OutputFrame> startTarget(int jdk) { | ||
| return startTarget(String.valueOf(jdk), null, false); | ||
| } | ||
|
|
||
| public Consumer<OutputFrame> startTarget(String jdk, String serverVersion, boolean windows) { | ||
| String targetImage = getTargetImage(jdk, serverVersion, windows); | ||
| return containerManager.startTarget( | ||
| targetImage, | ||
| agentPath, | ||
| getJvmArgsEnvVarName(), | ||
| getExtraEnv(), | ||
| getSetServiceName(), | ||
| getExtraResources(), | ||
| getExtraPorts(), | ||
| getWaitStrategy(), | ||
| getCommand()); | ||
| } | ||
|
|
||
| protected abstract String getTargetImage(String jdk); | ||
|
|
||
| protected String getTargetImage(String jdk, String serverVersion, boolean windows) { | ||
| return getTargetImage(jdk); | ||
| } | ||
|
|
||
| protected TargetWaitStrategy getWaitStrategy() { | ||
| return null; | ||
| } | ||
|
|
||
| protected String[] getCommand() { | ||
| return null; | ||
| } | ||
|
|
||
| public void cleanup() { | ||
| telemetryRetriever.clearTelemetry(); | ||
| } | ||
|
|
||
| public void stopTarget() { | ||
| containerManager.stopTarget(); | ||
| cleanup(); | ||
| } | ||
|
|
||
| protected List<SpanData> waitForTraces() { | ||
| return telemetryRetriever.waitForTraces(); | ||
| } | ||
|
|
||
| protected Collection<MetricData> waitForMetrics() { | ||
| return telemetryRetriever.waitForMetrics(); | ||
| } | ||
|
|
||
| protected Collection<LogRecordData> waitForLogs() { | ||
| return telemetryRetriever.waitForLogs(); | ||
| } | ||
|
|
||
| private static TestContainerManager createContainerManager() { | ||
| return TestContainerManager.useWindowsContainers() | ||
| ? new WindowsTestContainerManager() | ||
| : new LinuxTestContainerManager(); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you think about taking this opportunity to pull in a newer one of these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should better be a renovate rule then - I'd suggest to do that as a follow-up.
An idea would be to have the same tag for all images to make it easier to create a rule.
The tag is set here:
opentelemetry-java-instrumentation/.github/workflows/reusable-publish-smoke-test-images.yml
Line 61 in 98072b9
If we change it to
GITHUB_SHAthen it would be the same for all artfacts.@trask wdyt?