Skip to content

Commit fcfe6f2

Browse files
authored
Log image pull and container startup time independently (#7455)
Currently, contianer startup is logged taking into account the image pull. Logging those independently is accurate.
1 parent 3fe42be commit fcfe6f2

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

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

+4-5
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,6 @@ protected void doStart() {
338338
try {
339339
configure();
340340

341-
Instant startedAt = Instant.now();
342-
343341
logger().debug("Starting container: {}", getDockerImageName());
344342

345343
AtomicInteger attempt = new AtomicInteger(0);
@@ -353,7 +351,7 @@ protected void doStart() {
353351
attempt.incrementAndGet(),
354352
startupAttempts
355353
);
356-
tryStart(startedAt);
354+
tryStart();
357355
return true;
358356
}
359357
);
@@ -380,11 +378,12 @@ protected boolean canBeReused() {
380378
return true;
381379
}
382380

383-
private void tryStart(Instant startedAt) {
381+
private void tryStart() {
384382
try {
385383
String dockerImageName = getDockerImageName();
386384
logger().debug("Starting container: {}", dockerImageName);
387385

386+
Instant startedAt = Instant.now();
388387
logger().info("Creating container for image: {}", dockerImageName);
389388
CreateContainerCmd createCommand = dockerClient.createContainerCmd(dockerImageName);
390389
applyConfiguration(createCommand);
@@ -1497,7 +1496,7 @@ public SELF withStartupAttempts(int attempts) {
14971496
}
14981497

14991498
/**
1500-
* Allow low level modifications of {@link CreateContainerCmd} after it was pre-configured in {@link #tryStart(Instant)}.
1499+
* Allow low level modifications of {@link CreateContainerCmd} after it was pre-configured in {@link #tryStart()}.
15011500
* Invocation happens eagerly on a moment when container is created.
15021501
* Warning: this does expose the underlying docker-java API so might change outside of our control.
15031502
*

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ protected final String resolve() {
8080
Exception lastFailure = null;
8181
final Instant lastRetryAllowed = Instant.now().plus(PULL_RETRY_TIME_LIMIT);
8282

83+
Instant startedAt = Instant.now();
8384
while (Instant.now().isBefore(lastRetryAllowed)) {
8485
try {
8586
PullImageCmd pullImageCmd = dockerClient
@@ -95,10 +96,12 @@ protected final String resolve() {
9596
.exec(new TimeLimitedLoggedPullImageResultCallback(logger))
9697
.awaitCompletion();
9798
}
99+
String dockerImageName = imageName.asCanonicalNameString();
100+
logger.info("Image {} pull took {}", dockerImageName, Duration.between(startedAt, Instant.now()));
98101

99102
LocalImagesCache.INSTANCE.refreshCache(imageName);
100103

101-
return imageName.asCanonicalNameString();
104+
return dockerImageName;
102105
} catch (InterruptedException | InternalServerErrorException e) {
103106
// these classes of exception often relate to timeout/connection errors so should be retried
104107
lastFailure = e;
@@ -109,6 +112,7 @@ protected final String resolve() {
109112
);
110113
}
111114
}
115+
112116
logger.error(
113117
"Failed to pull image: {}. Please check output of `docker pull {}`",
114118
imageName,

0 commit comments

Comments
 (0)