Skip to content

Commit 32c0e79

Browse files
committed
javadoc + timeout
1 parent 20e2c49 commit 32c0e79

File tree

4 files changed

+44
-65
lines changed

4 files changed

+44
-65
lines changed

smoke-tests/src/main/java/io/opentelemetry/smoketest/SmokeTestInstrumentationExtension.java

Lines changed: 31 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@
4444
public class SmokeTestInstrumentationExtension extends InstrumentationExtension
4545
implements TelemetryRetrieverProvider {
4646

47-
// todo timeout configuration
48-
// todo move builder docs to builder methods
49-
5047
private final TestContainerManager containerManager = createContainerManager();
5148

5249
private TelemetryRetriever telemetryRetriever;
@@ -70,6 +67,7 @@ public interface GetTargetImage {
7067
private final List<ResourceMapping> extraResources;
7168
private final TargetWaitStrategy waitStrategy;
7269
private final List<Integer> extraPorts;
70+
private final Duration telemetryTimeout;
7371

7472
private SmokeTestInstrumentationExtension(
7573
GetTargetImage getTargetImage,
@@ -79,7 +77,8 @@ private SmokeTestInstrumentationExtension(
7977
Map<String, String> extraEnv,
8078
List<ResourceMapping> extraResources,
8179
TargetWaitStrategy waitStrategy,
82-
List<Integer> extraPorts) {
80+
List<Integer> extraPorts,
81+
Duration telemetryTimeout) {
8382
super(new SmokeTestRunner());
8483
this.getTargetImage = getTargetImage;
8584
this.command = command;
@@ -89,6 +88,7 @@ private SmokeTestInstrumentationExtension(
8988
this.extraResources = extraResources;
9089
this.waitStrategy = waitStrategy;
9190
this.extraPorts = extraPorts;
91+
this.telemetryTimeout = telemetryTimeout;
9292
}
9393

9494
public WebClient client() {
@@ -98,7 +98,8 @@ public WebClient client() {
9898
@Override
9999
public void beforeAll(ExtensionContext context) throws Exception {
100100
containerManager.startEnvironmentOnce();
101-
telemetryRetriever = new TelemetryRetriever(containerManager.getBackendMappedPort());
101+
telemetryRetriever =
102+
new TelemetryRetriever(containerManager.getBackendMappedPort(), telemetryTimeout);
102103
super.beforeAll(context);
103104
}
104105

@@ -124,67 +125,26 @@ public SmokeTestOutput start(int jdk) {
124125
}
125126

126127
public SmokeTestOutput start(String jdk, String serverVersion, boolean windows) {
127-
String targetImage = getTargetImage(jdk, serverVersion, windows);
128128
autoCleanup.deferCleanup(() -> containerManager.stopTarget());
129129

130130
return new SmokeTestOutput(
131131
containerManager.startTarget(
132-
targetImage,
132+
getTargetImage.getTargetImage(jdk, serverVersion, windows),
133133
agentPath,
134-
getJvmArgsEnvVarName(),
135-
getExtraEnv(),
136-
getSetServiceName(),
137-
getExtraResources(),
138-
getExtraPorts(),
139-
getWaitStrategy(),
140-
getCommand()));
134+
jvmArgsEnvVarName,
135+
extraEnv,
136+
setServiceName,
137+
extraResources,
138+
extraPorts,
139+
waitStrategy,
140+
command));
141141
}
142142

143143
@Override
144144
public TelemetryRetriever getTelemetryRetriever() {
145145
return telemetryRetriever;
146146
}
147147

148-
public String getTargetImage(String jdk, String serverVersion, boolean windows) {
149-
return getTargetImage.getTargetImage(jdk, serverVersion, windows);
150-
}
151-
152-
public String[] getCommand() {
153-
return command;
154-
}
155-
156-
/** Subclasses can override this method to pass jvm arguments in another environment variable */
157-
public String getJvmArgsEnvVarName() {
158-
return jvmArgsEnvVarName;
159-
}
160-
161-
/** Subclasses can override this method to customise target application's environment */
162-
public Map<String, String> getExtraEnv() {
163-
return extraEnv;
164-
}
165-
166-
/** Subclasses can override this method to disable setting default service name */
167-
public boolean getSetServiceName() {
168-
return setServiceName;
169-
}
170-
171-
/** Subclasses can override this method to provide additional files to copy to target container */
172-
public List<ResourceMapping> getExtraResources() {
173-
return extraResources;
174-
}
175-
176-
/**
177-
* Subclasses can override this method to provide additional ports that should be exposed from the
178-
* target container
179-
*/
180-
public List<Integer> getExtraPorts() {
181-
return extraPorts;
182-
}
183-
184-
public TargetWaitStrategy getWaitStrategy() {
185-
return waitStrategy;
186-
}
187-
188148
public static Builder builder(Function<String, String> getTargetImage) {
189149
return builder((jdk, serverVersion, windows) -> getTargetImage.apply(jdk));
190150
}
@@ -219,53 +179,68 @@ public static class Builder {
219179
private List<ResourceMapping> extraResources = List.of();
220180
private TargetWaitStrategy waitStrategy;
221181
private List<Integer> extraPorts = List.of();
182+
private Duration telemetryTimeout = Duration.ofSeconds(30);
222183

223184
private Builder(GetTargetImage getTargetImage) {
224185
this.getTargetImage = getTargetImage;
225186
}
226187

188+
/** Sets the command to run in the target container. */
227189
@CanIgnoreReturnValue
228190
public Builder command(String... command) {
229191
this.command = command;
230192
return this;
231193
}
232194

195+
/** Sets the environment variable name used to pass JVM arguments to the target application. */
233196
@CanIgnoreReturnValue
234197
public Builder jvmArgsEnvVarName(String jvmArgsEnvVarName) {
235198
this.jvmArgsEnvVarName = jvmArgsEnvVarName;
236199
return this;
237200
}
238201

202+
/** Enables or disables setting the default service name for the target application. */
239203
@CanIgnoreReturnValue
240204
public Builder setServiceName(boolean setServiceName) {
241205
this.setServiceName = setServiceName;
242206
return this;
243207
}
244208

209+
/** Adds an environment variable to the target application's environment. */
245210
@CanIgnoreReturnValue
246211
public Builder env(String key, String value) {
247212
this.extraEnv.put(key, value);
248213
return this;
249214
}
250215

216+
/** Specifies additional files to copy to the target container. */
251217
@CanIgnoreReturnValue
252218
public Builder extraResources(ResourceMapping... resources) {
253219
this.extraResources = List.of(resources);
254220
return this;
255221
}
256222

223+
/** Sets the wait strategy for the target container startup. */
257224
@CanIgnoreReturnValue
258225
public Builder waitStrategy(@Nullable TargetWaitStrategy waitStrategy) {
259226
this.waitStrategy = waitStrategy;
260227
return this;
261228
}
262229

230+
/** Specifies additional ports to expose from the target container. */
263231
@CanIgnoreReturnValue
264232
public Builder extraPorts(Integer... ports) {
265233
this.extraPorts = List.of(ports);
266234
return this;
267235
}
268236

237+
/** Sets the timeout duration for retrieving telemetry data. */
238+
@CanIgnoreReturnValue
239+
public Builder telemetryTimeout(Duration telemetryTimeout) {
240+
this.telemetryTimeout = telemetryTimeout;
241+
return this;
242+
}
243+
269244
public SmokeTestInstrumentationExtension build() {
270245
return new SmokeTestInstrumentationExtension(
271246
getTargetImage,
@@ -275,7 +250,8 @@ public SmokeTestInstrumentationExtension build() {
275250
extraEnv,
276251
extraResources,
277252
waitStrategy,
278-
extraPorts);
253+
extraPorts,
254+
telemetryTimeout);
279255
}
280256
}
281257
}

smoke-tests/src/main/java/io/opentelemetry/smoketest/TelemetryRetriever.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import io.opentelemetry.testing.internal.protobuf.GeneratedMessage;
1919
import io.opentelemetry.testing.internal.protobuf.InvalidProtocolBufferException;
2020
import io.opentelemetry.testing.internal.protobuf.util.JsonFormat;
21+
import java.time.Duration;
2122
import java.util.Collection;
2223
import java.util.List;
2324
import java.util.concurrent.TimeUnit;
@@ -28,9 +29,11 @@
2829
public class TelemetryRetriever {
2930
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
3031
private final WebClient client;
32+
private final Duration telemetryTimeout;
3133

32-
public TelemetryRetriever(int backendPort) {
34+
public TelemetryRetriever(int backendPort, Duration telemetryTimeout) {
3335
client = WebClient.of("http://localhost:" + backendPort);
36+
this.telemetryTimeout = telemetryTimeout;
3437
}
3538

3639
public void clearTelemetry() {
@@ -91,7 +94,7 @@ Collection<T> waitForTelemetry(String path, Supplier<B> builderConstructor) {
9194
@SuppressWarnings("SystemOut")
9295
private String waitForContent(String path) throws InterruptedException {
9396
long previousSize = 0;
94-
long deadline = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(30);
97+
long deadline = System.currentTimeMillis() + telemetryTimeout.toMillis();
9598
String content = "[]";
9699
while (System.currentTimeMillis() < deadline) {
97100
content = client.get(path).aggregate().join().contentUtf8();

smoke-tests/src/test/java/io/opentelemetry/smoketest/JavaSmokeTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public WebClient client() {
4242
@BeforeAll
4343
static void setUp() {
4444
containerManager.startEnvironmentOnce();
45-
telemetryRetriever = new TelemetryRetriever(containerManager.getBackendMappedPort());
45+
telemetryRetriever =
46+
new TelemetryRetriever(containerManager.getBackendMappedPort(), telemetryTimeout);
4647
}
4748

4849
protected SmokeTestOutput startTarget(int jdk) {

smoke-tests/src/test/java/io/opentelemetry/smoketest/SpringBootSmokeTest.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,23 @@
55

66
package io.opentelemetry.smoketest;
77

8+
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
9+
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
10+
811
import io.opentelemetry.api.common.AttributeKey;
912
import io.opentelemetry.sdk.trace.data.SpanData;
1013
import io.opentelemetry.semconv.ServiceAttributes;
1114
import io.opentelemetry.semconv.incubating.OsIncubatingAttributes;
1215
import io.opentelemetry.semconv.incubating.TelemetryIncubatingAttributes;
1316
import io.opentelemetry.semconv.incubating.ThreadIncubatingAttributes;
14-
import org.junit.jupiter.api.condition.DisabledIf;
15-
import org.junit.jupiter.params.ParameterizedTest;
16-
import org.junit.jupiter.params.provider.ValueSource;
17-
1817
import java.util.List;
1918
import java.util.Set;
2019
import java.util.jar.Attributes;
2120
import java.util.jar.JarFile;
2221
import java.util.stream.Collectors;
23-
24-
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
25-
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
22+
import org.junit.jupiter.api.condition.DisabledIf;
23+
import org.junit.jupiter.params.ParameterizedTest;
24+
import org.junit.jupiter.params.provider.ValueSource;
2625

2726
@DisabledIf("io.opentelemetry.smoketest.TestContainerManager#useWindowsContainers")
2827
class SpringBootSmokeTest extends JavaSmokeTest {

0 commit comments

Comments
 (0)