Skip to content

Commit 7f4bc67

Browse files
SAAS-7852 (#51)
1 parent 497b7b7 commit 7f4bc67

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

lib/ContainerLogger.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,10 @@ class ContainerLogger extends EventEmitter {
9696
_getLogsStrategyStream() {
9797
return Q.all([
9898
Q.ninvoke(this.containerInterface, 'logs', {
99-
follow: 1,
100-
stdout: 1,
101-
stderr: 1
99+
follow: true,
100+
stdout: true,
101+
stderr: true,
102+
tail: 1000
102103
})
103104
]);
104105
}

lib/logger.js

+22-5
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class Logger {
180180
* @param docker
181181
* @param newContainer
182182
*/
183-
async _handleContainer(container) { // jshint ignore:line
183+
async _handleContainer(container, loggerStrategy) { // jshint ignore:line
184184
const containerId = container.Id || container.id;
185185
const containerStatus = container.Status || container.status;
186186
const receivedLoggerId = _.get(container, 'Labels', _.get(container, 'Actor.Attributes'))['io.codefresh.logger.id'];
@@ -189,7 +189,13 @@ class Logger {
189189
const receivedLogSizeLimit = _.get(container,
190190
'Labels',
191191
_.get(container, 'Actor.Attributes'))['io.codefresh.logger.logSizeLimit'];
192-
const loggerStrategy = _.get(container, 'Labels', _.get(container, 'Actor.Attributes'))['io.codefresh.logger.strategy'];
192+
const maxRetryAttempts = 10;
193+
const retryInterval = 1000;
194+
var retryCount = 0;
195+
196+
if (!loggerStrategy) {
197+
loggerStrategy = _.get(container, 'Labels', _.get(container, 'Actor.Attributes'))['io.codefresh.logger.strategy'];
198+
}
193199

194200
if (!containerId) {
195201
logger.error(`Not handling container because id is missing`);
@@ -256,16 +262,27 @@ class Logger {
256262
containerLogger.once('end', this._handleContainerStreamEnd.bind(this));
257263

258264
containerLogger.start()
259-
.done(() => {
260-
this.state.containers[containerId] = { status: ContainerHandlingStatus.LISTENING };
265+
.then(() => {
266+
this.state[containerId] = { status: ContainerHandlingStatus.LISTENING };
261267
this._writeNewState();
262-
}, (err) => {
268+
})
269+
.catch(async (err) => {
263270
const error = new CFError({
264271
cause: err,
265272
message: `Failed to start logging for container:${containerId}`,
266273
containerId
267274
});
268275
logger.error(error.toString());
276+
277+
if (retryCount !== maxRetryAttempts) {
278+
retryCount++;
279+
logger.warn(`Making another attempt switching to the "${LoggerStrategy.LOGS}" logging strategy`);
280+
281+
await new Promise(r => setTimeout(r, retryInterval));
282+
283+
delete this.state.containers[containerId];
284+
await this._handleContainer(container, LoggerStrategy.LOGS);
285+
}
269286
});
270287
}
271288

0 commit comments

Comments
 (0)