Skip to content

Commit dce6264

Browse files
authored
Remove SLF4J Profiler (#1002)
This was useful while we were working to optimise performance, but now I feel it's just clutter and can be safely removed.
1 parent 3ad8d80 commit dce6264

File tree

12 files changed

+15
-115
lines changed

12 files changed

+15
-115
lines changed

core/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ project.tasks.check.dependsOn(jarFileTest)
7373
dependencies {
7474
compile 'junit:junit:4.12'
7575
compile 'org.slf4j:slf4j-api:1.7.25'
76-
compile 'org.slf4j:slf4j-ext:1.7.25'
7776
compile 'org.jetbrains:annotations:15.0'
7877
compile 'javax.annotation:javax.annotation-api:1.3.1'
7978
compile 'org.apache.commons:commons-compress:1.18'

core/src/main/java/org/testcontainers/containers/DockerComposeContainer.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.junit.runners.model.Statement;
1414
import org.slf4j.Logger;
1515
import org.slf4j.LoggerFactory;
16-
import org.slf4j.profiler.Profiler;
1716
import org.testcontainers.DockerClientFactory;
1817
import org.testcontainers.containers.output.OutputFrame;
1918
import org.testcontainers.containers.output.Slf4jLogConsumer;
@@ -140,10 +139,6 @@ public void finished(Description description) {
140139

141140
@Override
142141
public void start() {
143-
final Profiler profiler = new Profiler("Docker Compose container rule");
144-
profiler.setLogger(logger());
145-
profiler.start("Docker Compose container startup");
146-
147142
synchronized (MUTEX) {
148143
registerContainersForShutdown();
149144
if (pull) {
@@ -155,7 +150,7 @@ public void start() {
155150
}
156151
applyScaling(); // scale before up, so that all scaled instances are available first for linking
157152
createServices();
158-
startAmbassadorContainers(profiler);
153+
startAmbassadorContainers();
159154
waitUntilServiceStarted();
160155
}
161156
}
@@ -243,10 +238,8 @@ private List<Container> listChildContainers() {
243238
.collect(toList());
244239
}
245240

246-
private void startAmbassadorContainers(Profiler profiler) {
247-
profiler.start("Ambassador container startup");
241+
private void startAmbassadorContainers() {
248242
ambassadorContainer.start();
249-
profiler.stop().log();
250243
}
251244

252245
private Logger logger() {

core/src/main/java/org/testcontainers/containers/GenericContainer.java

Lines changed: 8 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,9 @@
33
import com.github.dockerjava.api.DockerClient;
44
import com.github.dockerjava.api.command.CreateContainerCmd;
55
import com.github.dockerjava.api.command.InspectContainerResponse;
6-
import com.github.dockerjava.api.model.Bind;
7-
import com.github.dockerjava.api.model.ContainerNetwork;
8-
import com.github.dockerjava.api.model.ExposedPort;
9-
import com.github.dockerjava.api.model.HostConfig;
10-
import com.github.dockerjava.api.model.Info;
11-
import com.github.dockerjava.api.model.Link;
12-
import com.github.dockerjava.api.model.PortBinding;
13-
import com.github.dockerjava.api.model.Volume;
14-
import com.github.dockerjava.api.model.VolumesFrom;
6+
import com.github.dockerjava.api.model.*;
157
import com.google.common.base.Strings;
16-
import lombok.AccessLevel;
17-
import lombok.Data;
18-
import lombok.EqualsAndHashCode;
19-
import lombok.NonNull;
20-
import lombok.Setter;
21-
import lombok.SneakyThrows;
8+
import lombok.*;
229
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
2310
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
2411
import org.apache.commons.compress.utils.IOUtils;
@@ -32,7 +19,6 @@
3219
import org.rnorth.ducttape.unreliables.Unreliables;
3320
import org.rnorth.visibleassertions.VisibleAssertions;
3421
import org.slf4j.Logger;
35-
import org.slf4j.profiler.Profiler;
3622
import org.testcontainers.DockerClientFactory;
3723
import org.testcontainers.containers.output.FrameConsumerResultCallback;
3824
import org.testcontainers.containers.output.OutputFrame;
@@ -51,25 +37,11 @@
5137
import org.testcontainers.lifecycle.TestLifecycleAware;
5238
import org.testcontainers.utility.*;
5339

54-
import java.io.ByteArrayInputStream;
55-
import java.io.ByteArrayOutputStream;
56-
import java.io.File;
57-
import java.io.FileOutputStream;
58-
import java.io.IOException;
59-
import java.io.InputStream;
40+
import java.io.*;
6041
import java.nio.charset.Charset;
6142
import java.nio.file.Path;
6243
import java.time.Duration;
63-
import java.util.ArrayList;
64-
import java.util.Arrays;
65-
import java.util.Collections;
66-
import java.util.HashMap;
67-
import java.util.HashSet;
68-
import java.util.LinkedHashSet;
69-
import java.util.List;
70-
import java.util.Map;
71-
import java.util.Optional;
72-
import java.util.Set;
44+
import java.util.*;
7345
import java.util.concurrent.Future;
7446
import java.util.concurrent.TimeUnit;
7547
import java.util.concurrent.atomic.AtomicInteger;
@@ -229,11 +201,7 @@ public void start() {
229201
}
230202

231203
protected void doStart() {
232-
Profiler profiler = new Profiler("Container startup");
233-
profiler.setLogger(logger());
234-
235204
try {
236-
profiler.start("Prepare container configuration and host configuration");
237205
configure();
238206

239207
logger().debug("Starting container: {}", getDockerImageName());
@@ -242,24 +210,21 @@ protected void doStart() {
242210
AtomicInteger attempt = new AtomicInteger(0);
243211
Unreliables.retryUntilSuccess(startupAttempts, () -> {
244212
logger().debug("Trying to start container: {} (attempt {}/{})", image.get(), attempt.incrementAndGet(), startupAttempts);
245-
tryStart(profiler.startNested("Container startup attempt"));
213+
tryStart();
246214
return true;
247215
});
248216

249217
} catch (Exception e) {
250218
throw new ContainerLaunchException("Container startup failed", e);
251-
} finally {
252-
profiler.stop().log();
253219
}
254220
}
255221

256-
private void tryStart(Profiler profiler) {
222+
private void tryStart() {
257223
try {
258224
String dockerImageName = image.get();
259225
logger().debug("Starting container: {}", dockerImageName);
260226

261227
logger().info("Creating container for image: {}", dockerImageName);
262-
profiler.start("Create container");
263228
CreateContainerCmd createCommand = dockerClient.createContainerCmd(dockerImageName);
264229
applyConfiguration(createCommand);
265230

@@ -272,7 +237,6 @@ private void tryStart(Profiler profiler) {
272237
containerIsCreated(containerId);
273238

274239
logger().info("Starting container with ID: {}", containerId);
275-
profiler.start("Start container");
276240
dockerClient.startContainerCmd(containerId).exec();
277241

278242
// For all registered output consumers, start following as close to container startup as possible
@@ -281,22 +245,18 @@ private void tryStart(Profiler profiler) {
281245
logger().info("Container {} is starting: {}", dockerImageName, containerId);
282246

283247
// Tell subclasses that we're starting
284-
profiler.start("Inspecting container");
285248
containerInfo = dockerClient.inspectContainerCmd(containerId).exec();
286249
containerName = containerInfo.getName();
287-
profiler.start("Call containerIsStarting on subclasses");
288250
containerIsStarting(containerInfo);
289251

290252
// Wait until the container is running (may not be fully started)
291-
profiler.start("Wait until container has started properly, or there's evidence it failed to start.");
292253

293254
if (!this.startupCheckStrategy.waitUntilStartupSuccessful(dockerClient, containerId)) {
294255
// Bail out, don't wait for the port to start listening.
295256
// (Exception thrown here will be caught below and wrapped)
296257
throw new IllegalStateException("Container did not start correctly.");
297258
}
298259

299-
profiler.start("Wait until container started properly");
300260
waitUntilContainerStarted();
301261

302262
logger().info("Container {} started", dockerImageName);
@@ -321,8 +281,6 @@ private void tryStart(Profiler profiler) {
321281
}
322282

323283
throw new ContainerLaunchException("Could not create/start container", e);
324-
} finally {
325-
profiler.stop();
326284
}
327285
}
328286

@@ -455,7 +413,7 @@ public Set<Integer> getLivenessCheckPortNumbers() {
455413
private void applyConfiguration(CreateContainerCmd createCommand) {
456414
HostConfig hostConfig = buildHostConfig();
457415
createCommand.withHostConfig(hostConfig);
458-
416+
459417
// Set up exposed ports (where there are no host port bindings defined)
460418
ExposedPort[] portArray = exposedPorts.stream()
461419
.map(ExposedPort::new)
@@ -1166,7 +1124,7 @@ public SELF withStartupAttempts(int attempts) {
11661124
}
11671125

11681126
/**
1169-
* Allow low level modifications of {@link CreateContainerCmd} after it was pre-configured in {@link #tryStart(Profiler)}.
1127+
* Allow low level modifications of {@link CreateContainerCmd} after it was pre-configured in {@link #tryStart()}.
11701128
* Invocation happens eagerly on a moment when container is created.
11711129
* Warning: this does expose the underlying docker-java API so might change outside of our control.
11721130
*

core/src/main/java/org/testcontainers/images/RemoteDockerImage.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import lombok.NonNull;
99
import lombok.ToString;
1010
import org.slf4j.Logger;
11-
import org.slf4j.profiler.Profiler;
1211
import org.testcontainers.DockerClientFactory;
1312
import org.testcontainers.containers.ContainerFetchException;
1413
import org.testcontainers.utility.DockerImageName;
@@ -39,17 +38,10 @@ public RemoteDockerImage(@NonNull String repository, @NonNull String tag) {
3938

4039
@Override
4140
protected final String resolve() {
42-
Profiler profiler = new Profiler("Rule creation - prefetch image");
4341
Logger logger = DockerLoggerFactory.getLogger(imageName.toString());
44-
profiler.setLogger(logger);
4542

46-
Profiler nested = profiler.startNested("Obtaining client");
4743
DockerClient dockerClient = DockerClientFactory.instance().client();
4844
try {
49-
nested.stop();
50-
51-
profiler.start("Check local images");
52-
5345
int attempts = 0;
5446
Exception lastException = null;
5547
while (true) {
@@ -83,7 +75,6 @@ protected final String resolve() {
8375
// Log only on first attempt
8476
if (attempts == 0) {
8577
logger.info("Pulling docker image: {}. Please be patient; this may take some time but only needs to be done once.", imageName);
86-
profiler.start("Pull image");
8778
}
8879

8980
if (attempts++ >= 3) {
@@ -109,8 +100,6 @@ protected final String resolve() {
109100
return imageName.toString();
110101
} catch (DockerClientException e) {
111102
throw new ContainerFetchException("Failed to get Docker client for " + imageName, e);
112-
} finally {
113-
profiler.stop().log();
114103
}
115104
}
116105
}

core/src/main/java/org/testcontainers/images/builder/ImageFromDockerfile.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
1313
import org.apache.commons.lang.StringUtils;
1414
import org.slf4j.Logger;
15-
import org.slf4j.profiler.Profiler;
1615
import org.testcontainers.DockerClientFactory;
1716
import org.testcontainers.images.builder.traits.*;
1817
import org.testcontainers.utility.Base58;
@@ -90,9 +89,6 @@ public ImageFromDockerfile withFileFromTransferable(String path, Transferable tr
9089
protected final String resolve() {
9190
Logger logger = DockerLoggerFactory.getLogger(dockerImageName);
9291

93-
Profiler profiler = new Profiler("Rule creation - build image");
94-
profiler.setLogger(logger);
95-
9692
DockerClient dockerClient = DockerClientFactory.instance().client();
9793
try {
9894
if (deleteOnExit) {
@@ -116,16 +112,12 @@ public void onNext(BuildResponseItem item) {
116112
@Cleanup PipedInputStream in = new PipedInputStream();
117113
@Cleanup PipedOutputStream out = new PipedOutputStream(in);
118114

119-
profiler.start("Configure image");
120115
BuildImageCmd buildImageCmd = dockerClient.buildImageCmd(in);
121116
configure(buildImageCmd);
122117

123-
profiler.start("Build image");
124118
BuildImageResultCallback exec = buildImageCmd.exec(resultCallback);
125119

126120
// To build an image, we have to send the context to Docker in TAR archive format
127-
profiler.start("Send context as TAR");
128-
129121
try (TarArchiveOutputStream tarArchive = new TarArchiveOutputStream(new GZIPOutputStream(out))) {
130122
tarArchive.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
131123

@@ -137,14 +129,11 @@ public void onNext(BuildResponseItem item) {
137129
tarArchive.finish();
138130
}
139131

140-
profiler.start("Wait for an image id");
141132
exec.awaitImageId();
142133

143134
return dockerImageName;
144135
} catch(IOException e) {
145136
throw new RuntimeException("Can't close DockerClient", e);
146-
} finally {
147-
profiler.stop().log();
148137
}
149138
}
150139

core/src/test/resources/logback-test.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,4 @@
2020
<logger name="io.netty" level="WARN" />
2121
<logger name="org.testcontainers.shaded" level="WARN"/>
2222

23-
<turboFilter class="ch.qos.logback.classic.turbo.MarkerFilter">
24-
<Marker>PROFILER</Marker>
25-
<OnMatch>DENY</OnMatch>
26-
</turboFilter>
2723
</configuration>

modules/couchbase/src/test/resources/logback-test.xml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,4 @@
2222
<logger name="org.testcontainers.shaded" level="WARN"/>
2323
<logger name="com.zaxxer.hikari" level="INFO"/>
2424

25-
<turboFilter class="ch.qos.logback.classic.turbo.MarkerFilter">
26-
<Marker>PROFILER</Marker>
27-
<OnMatch>DENY</OnMatch>
28-
</turboFilter>
29-
</configuration>
25+
</configuration>

modules/elasticsearch/src/test/resources/logback-test.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,4 @@
1414

1515
<logger name="org.testcontainers.shaded" level="WARN"/>
1616

17-
<turboFilter class="ch.qos.logback.classic.turbo.MarkerFilter">
18-
<Marker>PROFILER</Marker>
19-
<OnMatch>DENY</OnMatch>
20-
</turboFilter>
2117
</configuration>

modules/jdbc-test/src/test/resources/logback-test.xml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,4 @@
2222
<logger name="org.testcontainers.shaded" level="WARN"/>
2323
<logger name="com.zaxxer.hikari" level="INFO"/>
2424

25-
<turboFilter class="ch.qos.logback.classic.turbo.MarkerFilter">
26-
<Marker>PROFILER</Marker>
27-
<OnMatch>DENY</OnMatch>
28-
</turboFilter>
29-
</configuration>
25+
</configuration>

modules/nginx/src/test/resources/logback-test.xml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,4 @@
2222
<logger name="org.testcontainers.shaded" level="WARN"/>
2323
<logger name="com.zaxxer.hikari" level="INFO"/>
2424

25-
<turboFilter class="ch.qos.logback.classic.turbo.MarkerFilter">
26-
<Marker>PROFILER</Marker>
27-
<OnMatch>DENY</OnMatch>
28-
</turboFilter>
29-
</configuration>
25+
</configuration>

0 commit comments

Comments
 (0)