From f42572a04d711e0b673ec70fd4f436806f7386ae Mon Sep 17 00:00:00 2001 From: Anton Petrov Date: Mon, 4 Nov 2024 16:05:05 +0300 Subject: [PATCH 1/4] Pass more options to log steeam --- bin/ecs-task-runner | 10 ++++++++++ index.js | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) 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); From 1bd2e753c830d355996f034443bb29c04852202b Mon Sep 17 00:00:00 2001 From: Anton Petrov Date: Mon, 4 Nov 2024 16:05:29 +0300 Subject: [PATCH 2/4] Ignore ThrottlingException error --- lib/log-stream.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/log-stream.js b/lib/log-stream.js index be6d830..4813546 100644 --- a/lib/log-stream.js +++ b/lib/log-stream.js @@ -75,7 +75,11 @@ class LogStream extends Readable { .catch((err) => { // Dismiss log stream not found. Log stream won't exist // until container starts logging + console.log("ERROR:", err) 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)); }); } From 8c6917f28be5cb94773c80e90423bae2ae3607b2 Mon Sep 17 00:00:00 2001 From: Anton Petrov Date: Mon, 4 Nov 2024 16:28:35 +0300 Subject: [PATCH 3/4] Remove error log --- lib/log-stream.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/log-stream.js b/lib/log-stream.js index 4813546..c7171da 100644 --- a/lib/log-stream.js +++ b/lib/log-stream.js @@ -75,7 +75,6 @@ class LogStream extends Readable { .catch((err) => { // Dismiss log stream not found. Log stream won't exist // until container starts logging - console.log("ERROR:", err) 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 From c62b10c2298eb113f2415730d4b9306725da690e Mon Sep 17 00:00:00 2001 From: Anton Petrov Date: Mon, 4 Nov 2024 17:56:25 +0300 Subject: [PATCH 4/4] Fix pending logs --- lib/log-stream.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/log-stream.js b/lib/log-stream.js index c7171da..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)); }