Skip to content

SAAS-7852 #51

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

Merged
merged 1 commit into from
Jul 17, 2020
Merged
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
7 changes: 4 additions & 3 deletions lib/ContainerLogger.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ class ContainerLogger extends EventEmitter {
_getLogsStrategyStream() {
return Q.all([
Q.ninvoke(this.containerInterface, 'logs', {
follow: 1,
stdout: 1,
stderr: 1
follow: true,
stdout: true,
stderr: true,
tail: 1000
})
]);
}
Expand Down
27 changes: 22 additions & 5 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class Logger {
* @param docker
* @param newContainer
*/
async _handleContainer(container) { // jshint ignore:line
async _handleContainer(container, loggerStrategy) { // jshint ignore:line
const containerId = container.Id || container.id;
const containerStatus = container.Status || container.status;
const receivedLoggerId = _.get(container, 'Labels', _.get(container, 'Actor.Attributes'))['io.codefresh.logger.id'];
Expand All @@ -189,7 +189,13 @@ class Logger {
const receivedLogSizeLimit = _.get(container,
'Labels',
_.get(container, 'Actor.Attributes'))['io.codefresh.logger.logSizeLimit'];
const loggerStrategy = _.get(container, 'Labels', _.get(container, 'Actor.Attributes'))['io.codefresh.logger.strategy'];
const maxRetryAttempts = 10;
const retryInterval = 1000;
var retryCount = 0;

if (!loggerStrategy) {
loggerStrategy = _.get(container, 'Labels', _.get(container, 'Actor.Attributes'))['io.codefresh.logger.strategy'];
}

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

containerLogger.start()
.done(() => {
this.state.containers[containerId] = { status: ContainerHandlingStatus.LISTENING };
.then(() => {
this.state[containerId] = { status: ContainerHandlingStatus.LISTENING };
this._writeNewState();
}, (err) => {
})
.catch(async (err) => {
const error = new CFError({
cause: err,
message: `Failed to start logging for container:${containerId}`,
containerId
});
logger.error(error.toString());

if (retryCount !== maxRetryAttempts) {
retryCount++;
logger.warn(`Making another attempt switching to the "${LoggerStrategy.LOGS}" logging strategy`);

await new Promise(r => setTimeout(r, retryInterval));

delete this.state.containers[containerId];
await this._handleContainer(container, LoggerStrategy.LOGS);
}
});
}

Expand Down