Skip to content

Commit

Permalink
fix(tools): fabric AIO image log access in CI #643
Browse files Browse the repository at this point in the history
This commit is meant to make it much easier to debug
issues with the Fabric 2.x AIO container image in the
future when new bugs (inevitably) arise.

Meaning that the logs of the child processess such as
the fabric network creator script or the docker daemon will
all be piped through to the logs of the container itself
instead of just being dumped into log files under
/var/log/... which has the upside of not having to
shell into the container when something goes wrong
and one wishes to debug what happened. Instead the
logs of the container will show all the information
right away.

In addition to the above change a flag was added to
the FabricTestLedger class' constructor options so
that one  can tell the class to dump the continer's
log stream straight onto it's own logger meaning
that now if you are debugging a test case you will
be able to see all the logs that are being output
straight in the logs of the test case itself.
This can be very spammy at times, hence the flag
that can be used to turn it on or off depending on
what is needed more.

One more small change that we made to help debugging:
The supervisord config file now specifies the loglevel
of supervisord as debug instead of info.

Fixes #643

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
  • Loading branch information
petermetz committed Mar 11, 2021
1 parent 6bb0cf9 commit 9d9f805
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
Logger,
LogLevelDesc,
LoggerProvider,
Bools,
} from "@hyperledger/cactus-common";

/*
Expand All @@ -34,6 +35,7 @@ export interface IFabricTestLedgerV1ConstructorOptions {
imageName?: string;
envVars?: Map<string, string>;
logLevel?: LogLevelDesc;
emitContainerLogs?: boolean;
}

/*
Expand Down Expand Up @@ -70,14 +72,15 @@ export class FabricTestLedgerV1 implements ITestLedger {
public readonly imageVersion: string;
public readonly imageName: string;
public readonly publishAllPorts: boolean;
public readonly emitContainerLogs: boolean;
public readonly envVars: Map<string, string>;

private readonly log: Logger;

private container: Container | undefined;
private containerId: string | undefined;

public get className() {
public get className(): string {
return FabricTestLedgerV1.CLASS_NAME;
}

Expand All @@ -92,6 +95,9 @@ export class FabricTestLedgerV1 implements ITestLedger {
this.imageVersion = options.imageVersion || DEFAULT_OPTS.imageVersion;
this.imageName = options.imageName || DEFAULT_OPTS.imageName;
this.publishAllPorts = options.publishAllPorts;
this.emitContainerLogs = Bools.isBooleanStrict(options.emitContainerLogs)
? (options.emitContainerLogs as boolean)
: true;
this.envVars = options.envVars || DEFAULT_OPTS.envVars;

if (compareVersions.compare(this.getFabricVersion(), "1.4", "<"))
Expand Down Expand Up @@ -420,6 +426,16 @@ export class FabricTestLedgerV1 implements ITestLedger {
eventEmitter.once("start", async (container: Container) => {
this.container = container;
this.containerId = container.id;

if (this.emitContainerLogs) {
const logOptions = { follow: true, stderr: true, stdout: true };
const logStream = await container.logs(logOptions);
logStream.on("data", (data: Buffer) => {
const fnTag = `[${this.getContainerImageName()}]`;
this.log.debug(`${fnTag} %o`, data.toString("utf-8"));
});
}

try {
await this.waitForHealthCheck();
resolve(container);
Expand Down
22 changes: 14 additions & 8 deletions tools/docker/fabric-all-in-one/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,34 @@
logfile = /var/log/supervisord.log
logfile_maxbytes = 50MB
logfile_backups=10
loglevel = info
loglevel = debug

[program:sshd]
command=/usr/sbin/sshd -D
command=/usr/sbin/sshd -D -dd
autostart=true
autorestart=true
stderr_logfile=/var/log/sshd.err.log
stdout_logfile=/var/log/sshd.out.log
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0

[program:dockerd]
command=dockerd-entrypoint.sh
autostart=true
autorestart=true
stderr_logfile=/var/log/dockerd.err.log
stdout_logfile=/var/log/dockerd.out.log
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0

[program:fabric-network]
command=/run-fabric-network.sh
autostart=true
autorestart=unexpected
stderr_logfile=/var/log/fabric-network.err.log
stdout_logfile=/var/log/fabric-network.out.log
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0

[inet_http_server]
port = 0.0.0.0:9001
Expand Down

0 comments on commit 9d9f805

Please sign in to comment.