diff --git a/bin/ecs-task-runner b/bin/ecs-task-runner index 93181ba..33fb13f 100755 --- a/bin/ecs-task-runner +++ b/bin/ecs-task-runner @@ -61,6 +61,16 @@ const argv = yargs describe: 'Security groups network configuration (awsvpc configuration)', type: 'array' }) + .option('duration-between-polls', { + describe: 'Duration between logs polls', + type: 'number', + default: 1000 + }) + .option('timeout-before-first-logs', { + describe: 'Timeout before first logs', + type: 'number', + default: 300 * 1000 + }) .help() .wrap(yargs.terminalWidth()) .argv; diff --git a/index.js b/index.js index 02d44f8..e59ae9b 100644 --- a/index.js +++ b/index.js @@ -85,7 +85,9 @@ module.exports = function (options, cb) { const logs = new LogStream({ logGroup: logOptions['awslogs-group'], logStream: `${logOptions['awslogs-stream-prefix']}/${options.containerName}/${taskId}`, - endOfStreamIdentifier: endOfStreamIdentifier + endOfStreamIdentifier: endOfStreamIdentifier, + durationBetweenPolls: options.durationBetweenPolls, + timeoutBeforeFirstLogs: options.timeoutBeforeFirstLogs }); const stream = combiner(logs, formatter); diff --git a/lib/log-stream.js b/lib/log-stream.js index be6d830..3bc078b 100644 --- a/lib/log-stream.js +++ b/lib/log-stream.js @@ -33,15 +33,18 @@ class LogStream extends Readable { }; let next = (_err, _data) => { + this.pending = false; setTimeout(this._read.bind(this), this.options.durationBetweenPolls); }; - this.pending = false; this.cloudwatchlogs.getLogEvents(params) .then((data) => { - if (data && data.events.length > 0) { + if (data) { + if (!this.logsReceived) { + this.logsReceived = data.events.length > 0 + } + this.nextToken = data.nextForwardToken; - this.logsReceived = true; data.events.forEach((event) => this.eventBuffer.push(event)); } @@ -76,6 +79,9 @@ class LogStream extends Readable { // Dismiss log stream not found. Log stream won't exist // until container starts logging if (err && 'ResourceNotFoundException' === err.name) return next(); + // Dismiss log stream throttling error. These API calls have a hard limit, + // and they don't qualify for a limit increase + if (err && 'ThrottlingException' === err.name) return next(); if (err) return process.nextTick(() => this.emit('error', err)); }); }