Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pending state being used incorrectly, ignore ThrottlingException error, accept more options #137

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions bin/ecs-task-runner
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 9 additions & 3 deletions lib/log-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down Expand Up @@ -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));
});
}
Expand Down