Skip to content

Commit

Permalink
[Tests] Improve integration test logging to improve readability and e…
Browse files Browse the repository at this point in the history
…fficiency (apache#10320)

* Use simple docker log tailing

* Refactor DockerUtils

* Improve "tail -f logfile" efficiency in integration tests
  • Loading branch information
lhotari authored Apr 26, 2021
1 parent 8fed161 commit 7eff07c
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 202 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public class BrokerContainer extends PulsarContainer<BrokerContainer> {
public BrokerContainer(String clusterName, String hostName) {
super(
clusterName, hostName, hostName, "bin/run-broker.sh", BROKER_PORT, BROKER_HTTP_PORT);
tailContainerLog();
}

@Override
protected void afterStart() {
this.tailContainerLog();
DockerUtils.runCommandAsync(this.dockerClient, this.getContainerId(),
DockerUtils.runCommandAsyncWithLogging(this.dockerClient, this.getContainerId(),
"tail", "-f", "/var/log/pulsar/broker.log");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,43 +64,8 @@ public void stop() {
super.stop();
}

public void tailContainerLog() {
CompletableFuture.runAsync(() -> {
while (null == getContainerId()) {
try {
TimeUnit.MILLISECONDS.sleep(100);
} catch (InterruptedException e) {
return;
}
}

LogContainerCmd logContainerCmd = this.dockerClient.logContainerCmd(getContainerId());
logContainerCmd.withStdOut(true).withStdErr(true).withFollowStream(true);
logContainerCmd.exec(new LogContainerResultCallback() {
@Override
public void onNext(Frame item) {
log.info(new String(item.getPayload(), UTF_8));
}
});
});
}

public String getContainerLog() {
StringBuilder sb = new StringBuilder();

LogContainerCmd logContainerCmd = this.dockerClient.logContainerCmd(getContainerId());
logContainerCmd.withStdOut(true).withStdErr(true);
try {
logContainerCmd.exec(new LogContainerResultCallback() {
@Override
public void onNext(Frame item) {
sb.append(new String(item.getPayload(), UTF_8));
}
}).awaitCompletion();
} catch (InterruptedException e) {

}
return sb.toString();
protected void tailContainerLog() {
withLogConsumer(item -> log.info(item.getUtf8String()));
}

public void putFile(String path, byte[] contents) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@ public PrestoWorkerContainer(String clusterName, String hostname) {
-1,
PRESTO_HTTP_PORT,
"/v1/info/state");

tailContainerLog();
}

@Override
protected void afterStart() {
this.tailContainerLog();
DockerUtils.runCommandAsync(this.dockerClient, this.getContainerId(),
DockerUtils.runCommandAsyncWithLogging(this.dockerClient, this.getContainerId(),
"tail", "-f", "/var/log/pulsar/presto_worker.log");
DockerUtils.runCommandAsync(this.dockerClient, this.getContainerId(),
DockerUtils.runCommandAsyncWithLogging(this.dockerClient, this.getContainerId(),
"tail", "-f", "/pulsar/lib/presto/var/log/server.log");
}

Expand Down
Loading

0 comments on commit 7eff07c

Please sign in to comment.