Skip to content

Commit

Permalink
fix(core): reduce log level of docker commands
Browse files Browse the repository at this point in the history
  • Loading branch information
tchiotludo committed Aug 20, 2024
1 parent 41d290a commit dd341cf
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 22 deletions.
25 changes: 15 additions & 10 deletions core/src/main/java/io/kestra/core/runners/FilesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,25 @@ public static Map<String, String> inputFiles(RunContext runContext, Map<String,
}
}));

logger.info("Provided {} input(s).", inputFiles.size());
if (logger.isTraceEnabled()) {
logger.trace("Provided {} input(s).", inputFiles.size());
}

return inputFiles;
}

public static Map<String, URI> outputFiles(RunContext runContext, List<String> outputs) throws Exception {
List<Path> allFilesMatching = runContext.workingDir().findAllFilesMatching(outputs);
var outputFiles = allFilesMatching.stream()
.map(throwFunction(path -> new AbstractMap.SimpleEntry<>(
runContext.workingDir().path().relativize(path).toString(),
runContext.storage().putFile(path.toFile(), resolveUniqueNameForFile(path))
)))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
runContext.logger().info("Captured {} output(s).", allFilesMatching.size());
public static Map<String, URI> outputFiles(RunContext runContext, List<String> outputs) throws Exception {
List<Path> allFilesMatching = runContext.workingDir().findAllFilesMatching(outputs);
var outputFiles = allFilesMatching.stream()
.map(throwFunction(path -> new AbstractMap.SimpleEntry<>(
runContext.workingDir().path().relativize(path).toString(),
runContext.storage().putFile(path.toFile(), resolveUniqueNameForFile(path))
)))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

if (runContext.logger().isTraceEnabled()) {
runContext.logger().trace("Captured {} output(s).", allFilesMatching.size());
}

return outputFiles;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ public RunnerResult run(RunContext runContext, TaskCommands taskCommands, List<S
// create container
CreateContainerCmd container = configure(taskCommands, dockerClient, runContext, additionalVars);
CreateContainerResponse exec = container.exec();
logger.debug("Container created: {}", exec.getId());
if (logger.isTraceEnabled()) {
logger.trace("Container created: {}", exec.getId());
}

List<Path> relativeWorkingDirectoryFilesPaths = taskCommands.relativeWorkingDirectoryFilesPaths(true);
boolean hasFilesToUpload = !ListUtils.isEmpty(relativeWorkingDirectoryFilesPaths);
Expand All @@ -354,7 +356,10 @@ public RunnerResult run(RunContext runContext, TaskCommands taskCommands, List<S
CreateVolumeCmd files = dockerClient.createVolumeCmd()
.withLabels(ScriptService.labels(runContext, "kestra.io/"));
filesVolumeName = files.exec().getName();
logger.debug("Volume created: {}", filesVolumeName);
if (logger.isTraceEnabled()) {
logger.trace("Volume created: {}", filesVolumeName);
}

String remotePath = windowsToUnixPath(taskCommands.getWorkingDirectory().toString());

// first, create an archive
Expand Down Expand Up @@ -398,11 +403,14 @@ public RunnerResult run(RunContext runContext, TaskCommands taskCommands, List<S

// start container
dockerClient.startContainerCmd(exec.getId()).exec();
logger.debug(
"Starting command with container id {} [{}]",
exec.getId(),
String.join(" ", taskCommands.getCommands())
);

if (logger.isDebugEnabled()) {
logger.debug(
"Starting command with container id {} [{}]",
exec.getId(),
String.join(" ", taskCommands.getCommands())
);
}

// register the runnable to be used for killing the container.
onKill(() -> kill(dockerClient, exec.getId(), logger));
Expand Down Expand Up @@ -473,7 +481,7 @@ public void onComplete() {

if (exitCode != 0) {
throw new TaskException(exitCode, defaultLogConsumer.getStdOutCount(), defaultLogConsumer.getStdErrCount());
} else {
} else if (logger.isDebugEnabled()) {
logger.debug("Command succeed with code " + exitCode);
}

Expand Down Expand Up @@ -506,10 +514,16 @@ public void onComplete() {

if (Boolean.TRUE.equals(delete)) {
dockerClient.removeContainerCmd(exec.getId()).exec();
logger.debug("Container deleted: {}", exec.getId());
if (logger.isTraceEnabled()) {
logger.trace("Container deleted: {}", exec.getId());
}

if (needVolume && this.fileHandlingStrategy == FileHandlingStrategy.VOLUME && filesVolumeName != null) {
dockerClient.removeVolumeCmd(filesVolumeName).exec();
logger.debug("Volume deleted: {}", filesVolumeName);

if (logger.isTraceEnabled()) {
logger.trace("Volume deleted: {}", filesVolumeName);
}
}
}
} catch (Exception ignored) {
Expand All @@ -524,7 +538,10 @@ private void kill(final DockerClient dockerClient, final String containerId, fin
InspectContainerResponse inspect = dockerClient.inspectContainerCmd(containerId).exec();
if (Boolean.TRUE.equals(inspect.getState().getRunning())) {
dockerClient.killContainerCmd(containerId).exec();
logger.debug("Container was killed.");

if (logger.isTraceEnabled()) {
logger.trace("Container was killed.");
}
}
} catch (NotFoundException ignore) {
// silently ignore - container does not exist anymore
Expand Down Expand Up @@ -736,7 +753,9 @@ private void pullImage(DockerClient dockerClient, String image, PullPolicy polic
.exec(new PullImageResultCallback())
.awaitCompletion();

logger.debug("Image pulled [{}:{}]", repository, tag);
if (logger.isTraceEnabled()) {
logger.trace("Image pulled [{}:{}]", repository, tag);
}

return true;
}
Expand Down

0 comments on commit dd341cf

Please sign in to comment.