Skip to content

Commit

Permalink
CR-4891-new (#74)
Browse files Browse the repository at this point in the history
* follow true

* no tests

* with tests

* bump

* bremoved debug-purpose changes

* and now after save...

* without delay

* test fix

* removed redundant logs

* removed redundant comment

* removed comma

* removed redundant comma

* without q.all

* with q.all
  • Loading branch information
elad-codefresh authored Jun 20, 2021
1 parent 3333330 commit 8e5f26e
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 123 deletions.
30 changes: 15 additions & 15 deletions lib/ContainerLogger.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const EventEmitter = require('events');
const Q = require('q');
const logger = require('cf-logs').Logger('codefresh:containerLogger');
const CFError = require('cf-errors');
const EventEmitter = require('events');
const Q = require('q');
const logger = require('cf-logs').Logger('codefresh:containerLogger');
const CFError = require('cf-errors');
const { Transform } = require('stream');
const { LoggerStrategy } = require('./enums');

Expand All @@ -16,15 +16,15 @@ class ContainerLogger extends EventEmitter {
loggerStrategy
}) {
super();
this.containerId = containerId;
this.containerInterface = containerInterface;
this.stepLogger = stepLogger;
this.loggerStrategy = loggerStrategy;
this.tty = false;
this.logSizeLimit = logSizeLimit;
this.logSize = 0;
this.containerId = containerId;
this.containerInterface = containerInterface;
this.stepLogger = stepLogger;
this.loggerStrategy = loggerStrategy;
this.tty = false;
this.logSizeLimit = logSizeLimit;
this.logSize = 0;
this.isWorkflowLogSizeExceeded = isWorkflowLogSizeExceeded;
this.stepFinished = false;
this.stepFinished = false;
this.finishedStreams = 0;
this.handledStreams = 0;
}
Expand Down Expand Up @@ -91,9 +91,9 @@ 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
})
]);
}
Expand Down
60 changes: 30 additions & 30 deletions lib/logger.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
const fs = require('fs');
const { EventEmitter } = require('events');
const _ = require('lodash');
const Q = require('q');
const Docker = require('dockerode');
const DockerEvents = require('docker-events');
const bodyParser = require('body-parser');
const CFError = require('cf-errors');
const logger = require('cf-logs').Logger('codefresh:containerLogger');
const { TaskLogger } = require('@codefresh-io/task-logger');
const express = require('express');
const fs = require('fs');
const { EventEmitter } = require('events');
const _ = require('lodash');
const Q = require('q');
const Docker = require('dockerode');
const DockerEvents = require('docker-events');
const bodyParser = require('body-parser');
const CFError = require('cf-errors');
const logger = require('cf-logs').Logger('codefresh:containerLogger');
const { TaskLogger } = require('@codefresh-io/task-logger');
const express = require('express');
const { ContainerStatus } = require('./enums');
const { LoggerStrategy } = require('./enums');
const { ContainerHandlingStatus } = require('./enums');
const ContainerLogger = require('./ContainerLogger');
const ContainerLogger = require('./ContainerLogger');

const initialState = {
pid: process.pid, status: 'init', lastLogsDate: new Date(), failedHealthChecks: [], restartCounter: 0, containers: {}
Expand All @@ -27,13 +27,13 @@ class Logger {
buildFinishedPromise,
showProgress,
}) {
this.taskLoggerConfig = taskLoggerConfig;
this.loggerId = loggerId;
this.taskLoggerConfig = taskLoggerConfig;
this.loggerId = loggerId;
this.findExistingContainers = findExistingContainers === 'true';
this.logSizeLimit = logSizeLimit;
this.containerLoggers = [];
this.logSize = 0;
this.taskLogger = undefined;
this.logSizeLimit = logSizeLimit;
this.containerLoggers = [];
this.logSize = 0;
this.taskLogger = undefined;
this.buildFinishedPromise = buildFinishedPromise || Q.resolve();
this.finishedContainers = 0;
this.finishedContainersEmitter = new EventEmitter();
Expand All @@ -48,7 +48,7 @@ class Logger {
// console.log('Using /var/run/docker.sock');
}

this.docker = new Docker({
this.docker = new Docker({
socketPath: dockerSockPath,
});
this._readState();
Expand Down Expand Up @@ -131,11 +131,11 @@ class Logger {
this.state = _.omit(JSON.parse(fs.readFileSync(filePath, 'utf8'), ['containers', 'pid']));
this.state.containers = {};
this.state.pid = process.pid;
let restartCounter = _.get(this.state, 'restartCounter', 0);
let restartCounter = _.get(this.state, 'restartCounter', 0);
restartCounter++;
this.state.restartCounter = restartCounter;
} else {
this.state = initialState;
this.state = initialState;
}
}

Expand All @@ -153,7 +153,7 @@ class Logger {
* @param disableLog
*/
_writeNewState(disableLog = false) {
const filePath = `${__dirname}/state.json`;
const filePath = `${__dirname}/state.json`;
const currentState = JSON.stringify(this.state);
fs.writeFile(filePath, currentState, (err) => {
if (err) {
Expand Down Expand Up @@ -187,15 +187,15 @@ class Logger {
* @param newContainer
*/
async _handleContainer(container) { // 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'];
const runCreationLogic = _.get(container, 'Labels', _.get(container, 'Actor.Attributes'))['io.codefresh.runCreationLogic'];
const stepName = _.get(container, 'Labels', _.get(container, 'Actor.Attributes'))['io.codefresh.logger.stepName'];
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'];
const runCreationLogic = _.get(container, 'Labels', _.get(container, 'Actor.Attributes'))['io.codefresh.runCreationLogic'];
const stepName = _.get(container, 'Labels', _.get(container, 'Actor.Attributes'))['io.codefresh.logger.stepName'];
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 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 @@ -248,7 +248,7 @@ class Logger {
const logSizeLimit = receivedLogSizeLimit ? (parseInt(receivedLogSizeLimit, 10) * 1000000) : undefined;

const containerInterface = this.docker.getContainer(containerId);
const containerLogger = new ContainerLogger({
const containerLogger = new ContainerLogger({
containerId,
containerInterface,
stepLogger,
Expand All @@ -275,8 +275,8 @@ class Logger {
}

_updateMissingLogs() {
const resolvedCalls = _.get(this, 'state.logsStatus.resolvedCalls', 0);
const writeCalls = _.get(this, 'state.logsStatus.writeCalls', 0);
const resolvedCalls = _.get(this, 'state.logsStatus.resolvedCalls', 0);
const rejectedCalls = _.get(this, 'state.logsStatus.rejectedCalls', 0);

_.set(this, 'state.logsStatus.missingLogs', writeCalls - resolvedCalls - rejectedCalls);
Expand Down
2 changes: 1 addition & 1 deletion service.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version: 1.4.7
version: 1.4.8
Loading

0 comments on commit 8e5f26e

Please sign in to comment.