k8s reliable log hashing
parent
2e9e9dfb6a
commit
b91e21f29f
|
@ -3939,32 +3939,21 @@ const cloud_runner_system_1 = __nccwpck_require__(4197);
|
|||
const cloud_runner_1 = __importDefault(__nccwpck_require__(79144));
|
||||
const kubernetes_pods_1 = __importDefault(__nccwpck_require__(90740));
|
||||
const follow_log_stream_service_1 = __nccwpck_require__(40266);
|
||||
const remote_client_logger_1 = __nccwpck_require__(59412);
|
||||
class KubernetesTaskRunner {
|
||||
static async runTask(kubeConfig, kubeClient, jobName, podName, containerName, namespace) {
|
||||
let output = '';
|
||||
let shouldReadLogs = true;
|
||||
let shouldCleanup = true;
|
||||
let sinceTime = ``;
|
||||
let retriesAfterFinish = 0;
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
while (true) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 3000));
|
||||
const lastReceivedMessage = KubernetesTaskRunner.lastReceivedTimestamp > 0
|
||||
? `\nLast Log Message "${this.lastReceivedMessage}" ${this.lastReceivedTimestamp}`
|
||||
: ``;
|
||||
cloud_runner_logger_1.default.log(`Streaming logs from pod: ${podName} container: ${containerName} namespace: ${namespace} ${cloud_runner_1.default.buildParameters.kubeVolumeSize}/${cloud_runner_1.default.buildParameters.containerCpu}/${cloud_runner_1.default.buildParameters.containerMemory}\n${lastReceivedMessage}`);
|
||||
if (KubernetesTaskRunner.lastReceivedTimestamp > 0) {
|
||||
cloud_runner_logger_1.default.log(`Last received timestamp was set, including --since-time parameter`);
|
||||
const currentDate = new Date(KubernetesTaskRunner.lastReceivedTimestamp);
|
||||
const dateTimeIsoString = currentDate.toISOString();
|
||||
sinceTime = ` --since-time="${dateTimeIsoString}"`;
|
||||
}
|
||||
cloud_runner_logger_1.default.log(`Streaming logs from pod: ${podName} container: ${containerName} namespace: ${namespace} ${cloud_runner_1.default.buildParameters.kubeVolumeSize}/${cloud_runner_1.default.buildParameters.containerCpu}/${cloud_runner_1.default.buildParameters.containerMemory}`);
|
||||
let extraFlags = ``;
|
||||
extraFlags += (await kubernetes_pods_1.default.IsPodRunning(podName, namespace, kubeClient))
|
||||
? ` -f -c ${containerName}`
|
||||
: ` --previous`;
|
||||
let lastMessageSeenIncludedInChunk = false;
|
||||
let lastMessageSeen = false;
|
||||
let logs;
|
||||
const callback = (outputChunk) => {
|
||||
output += outputChunk;
|
||||
|
@ -3974,7 +3963,7 @@ class KubernetesTaskRunner {
|
|||
}
|
||||
};
|
||||
try {
|
||||
logs = await cloud_runner_system_1.CloudRunnerSystem.Run(`kubectl logs ${podName}${extraFlags} --timestamps${sinceTime}`, false, true, callback);
|
||||
logs = await cloud_runner_system_1.CloudRunnerSystem.Run(`kubectl logs ${podName}${extraFlags}`, false, true, callback);
|
||||
}
|
||||
catch (error) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 3000));
|
||||
|
@ -3991,24 +3980,9 @@ class KubernetesTaskRunner {
|
|||
}
|
||||
const splitLogs = logs.split(`\n`);
|
||||
for (const chunk of splitLogs) {
|
||||
if (chunk.replace(/\s/g, ``) === KubernetesTaskRunner.lastReceivedMessage.replace(/\s/g, ``) &&
|
||||
KubernetesTaskRunner.lastReceivedMessage.replace(/\s/g, ``) !== ``) {
|
||||
cloud_runner_logger_1.default.log(`Previous log message found ${chunk}`);
|
||||
lastMessageSeenIncludedInChunk = true;
|
||||
}
|
||||
}
|
||||
for (const chunk of splitLogs) {
|
||||
const newDate = Date.parse(`${chunk.toString().split(`Z `)[0]}Z`);
|
||||
if (chunk.replace(/\s/g, ``) === KubernetesTaskRunner.lastReceivedMessage.replace(/\s/g, ``)) {
|
||||
lastMessageSeen = true;
|
||||
}
|
||||
if (lastMessageSeenIncludedInChunk && !lastMessageSeen) {
|
||||
continue;
|
||||
}
|
||||
const message = cloud_runner_1.default.buildParameters.cloudRunnerDebug ? chunk : chunk.split(`Z `)[1];
|
||||
KubernetesTaskRunner.lastReceivedMessage = chunk;
|
||||
KubernetesTaskRunner.lastReceivedTimestamp = newDate;
|
||||
({ shouldReadLogs, shouldCleanup, output } = follow_log_stream_service_1.FollowLogStreamService.handleIteration(message, shouldReadLogs, shouldCleanup, output));
|
||||
follow_log_stream_service_1.FollowLogStreamService.DidReceiveEndOfTransmission = remote_client_logger_1.RemoteClientLogger.HandleLogChunkLine(message);
|
||||
}
|
||||
if (follow_log_stream_service_1.FollowLogStreamService.DidReceiveEndOfTransmission) {
|
||||
cloud_runner_logger_1.default.log('end of log stream');
|
||||
|
@ -4054,9 +4028,7 @@ class KubernetesTaskRunner {
|
|||
return waitComplete;
|
||||
}
|
||||
}
|
||||
KubernetesTaskRunner.lastReceivedTimestamp = 0;
|
||||
KubernetesTaskRunner.maxRetry = 3;
|
||||
KubernetesTaskRunner.lastReceivedMessage = ``;
|
||||
exports["default"] = KubernetesTaskRunner;
|
||||
|
||||
|
||||
|
@ -4597,6 +4569,7 @@ const cloud_runner_1 = __importDefault(__nccwpck_require__(79144));
|
|||
const cloud_runner_options_1 = __importDefault(__nccwpck_require__(66965));
|
||||
const cloud_runner_system_1 = __nccwpck_require__(4197);
|
||||
const cloud_runner_folders_1 = __nccwpck_require__(77795);
|
||||
const md5 = __nccwpck_require__(41711);
|
||||
class RemoteClientLogger {
|
||||
static get LogFilePath() {
|
||||
return node_path_1.default.join(`/home`, `job-log.txt`);
|
||||
|
@ -4647,8 +4620,28 @@ class RemoteClientLogger {
|
|||
await new Promise((resolve) => setTimeout(resolve, 15000));
|
||||
}
|
||||
}
|
||||
static HandleLogChunkLine(message) {
|
||||
if (message.includes('LOGHASH: ')) {
|
||||
RemoteClientLogger.md5 = message.split(`LOGHASH: `)[1];
|
||||
cloud_runner_logger_1.default.log(`LOGHASH: ${RemoteClientLogger.md5}`);
|
||||
}
|
||||
else {
|
||||
if (RemoteClientLogger.value !== '') {
|
||||
RemoteClientLogger.value += `\n`;
|
||||
}
|
||||
RemoteClientLogger.value += message;
|
||||
const hashedValue = md5(RemoteClientLogger.value);
|
||||
cloud_runner_logger_1.default.log(`LOG ITERATION \n message:${message} \n target hash:${RemoteClientLogger.md5} \n hash latest value:${hashedValue} \n cache value:${RemoteClientLogger.value}`);
|
||||
if (RemoteClientLogger.md5 === hashedValue) {
|
||||
cloud_runner_logger_1.default.log(`LOG COMPLETE`);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
exports.RemoteClientLogger = RemoteClientLogger;
|
||||
RemoteClientLogger.value = '';
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
@ -218478,6 +218471,46 @@ module.exports.httpify = function (resp, headers) {
|
|||
}
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 50421:
|
||||
/***/ ((module) => {
|
||||
|
||||
var charenc = {
|
||||
// UTF-8 encoding
|
||||
utf8: {
|
||||
// Convert a string to a byte array
|
||||
stringToBytes: function(str) {
|
||||
return charenc.bin.stringToBytes(unescape(encodeURIComponent(str)));
|
||||
},
|
||||
|
||||
// Convert a byte array to a string
|
||||
bytesToString: function(bytes) {
|
||||
return decodeURIComponent(escape(charenc.bin.bytesToString(bytes)));
|
||||
}
|
||||
},
|
||||
|
||||
// Binary encoding
|
||||
bin: {
|
||||
// Convert a string to a byte array
|
||||
stringToBytes: function(str) {
|
||||
for (var bytes = [], i = 0; i < str.length; i++)
|
||||
bytes.push(str.charCodeAt(i) & 0xFF);
|
||||
return bytes;
|
||||
},
|
||||
|
||||
// Convert a byte array to a string
|
||||
bytesToString: function(bytes) {
|
||||
for (var str = [], i = 0; i < bytes.length; i++)
|
||||
str.push(String.fromCharCode(bytes[i]));
|
||||
return str.join('');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = charenc;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 59051:
|
||||
|
@ -220089,6 +220122,109 @@ function resolveCommand(parsed) {
|
|||
module.exports = resolveCommand;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 37935:
|
||||
/***/ ((module) => {
|
||||
|
||||
(function() {
|
||||
var base64map
|
||||
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
|
||||
|
||||
crypt = {
|
||||
// Bit-wise rotation left
|
||||
rotl: function(n, b) {
|
||||
return (n << b) | (n >>> (32 - b));
|
||||
},
|
||||
|
||||
// Bit-wise rotation right
|
||||
rotr: function(n, b) {
|
||||
return (n << (32 - b)) | (n >>> b);
|
||||
},
|
||||
|
||||
// Swap big-endian to little-endian and vice versa
|
||||
endian: function(n) {
|
||||
// If number given, swap endian
|
||||
if (n.constructor == Number) {
|
||||
return crypt.rotl(n, 8) & 0x00FF00FF | crypt.rotl(n, 24) & 0xFF00FF00;
|
||||
}
|
||||
|
||||
// Else, assume array and swap all items
|
||||
for (var i = 0; i < n.length; i++)
|
||||
n[i] = crypt.endian(n[i]);
|
||||
return n;
|
||||
},
|
||||
|
||||
// Generate an array of any length of random bytes
|
||||
randomBytes: function(n) {
|
||||
for (var bytes = []; n > 0; n--)
|
||||
bytes.push(Math.floor(Math.random() * 256));
|
||||
return bytes;
|
||||
},
|
||||
|
||||
// Convert a byte array to big-endian 32-bit words
|
||||
bytesToWords: function(bytes) {
|
||||
for (var words = [], i = 0, b = 0; i < bytes.length; i++, b += 8)
|
||||
words[b >>> 5] |= bytes[i] << (24 - b % 32);
|
||||
return words;
|
||||
},
|
||||
|
||||
// Convert big-endian 32-bit words to a byte array
|
||||
wordsToBytes: function(words) {
|
||||
for (var bytes = [], b = 0; b < words.length * 32; b += 8)
|
||||
bytes.push((words[b >>> 5] >>> (24 - b % 32)) & 0xFF);
|
||||
return bytes;
|
||||
},
|
||||
|
||||
// Convert a byte array to a hex string
|
||||
bytesToHex: function(bytes) {
|
||||
for (var hex = [], i = 0; i < bytes.length; i++) {
|
||||
hex.push((bytes[i] >>> 4).toString(16));
|
||||
hex.push((bytes[i] & 0xF).toString(16));
|
||||
}
|
||||
return hex.join('');
|
||||
},
|
||||
|
||||
// Convert a hex string to a byte array
|
||||
hexToBytes: function(hex) {
|
||||
for (var bytes = [], c = 0; c < hex.length; c += 2)
|
||||
bytes.push(parseInt(hex.substr(c, 2), 16));
|
||||
return bytes;
|
||||
},
|
||||
|
||||
// Convert a byte array to a base-64 string
|
||||
bytesToBase64: function(bytes) {
|
||||
for (var base64 = [], i = 0; i < bytes.length; i += 3) {
|
||||
var triplet = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2];
|
||||
for (var j = 0; j < 4; j++)
|
||||
if (i * 8 + j * 6 <= bytes.length * 8)
|
||||
base64.push(base64map.charAt((triplet >>> 6 * (3 - j)) & 0x3F));
|
||||
else
|
||||
base64.push('=');
|
||||
}
|
||||
return base64.join('');
|
||||
},
|
||||
|
||||
// Convert a base-64 string to a byte array
|
||||
base64ToBytes: function(base64) {
|
||||
// Remove non-base-64 characters
|
||||
base64 = base64.replace(/[^A-Z0-9+\/]/ig, '');
|
||||
|
||||
for (var bytes = [], i = 0, imod4 = 0; i < base64.length;
|
||||
imod4 = ++i % 4) {
|
||||
if (imod4 == 0) continue;
|
||||
bytes.push(((base64map.indexOf(base64.charAt(i - 1))
|
||||
& (Math.pow(2, -2 * imod4 + 8) - 1)) << (imod4 * 2))
|
||||
| (base64map.indexOf(base64.charAt(i)) >>> (6 - imod4 * 2)));
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = crypt;
|
||||
})();
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 18611:
|
||||
|
@ -232411,6 +232547,34 @@ if (typeof Object.create === 'function') {
|
|||
}
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 35625:
|
||||
/***/ ((module) => {
|
||||
|
||||
/*!
|
||||
* Determine if an object is a Buffer
|
||||
*
|
||||
* @author Feross Aboukhadijeh <https://feross.org>
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
// The _isBuffer check is for Safari 5-7 support, because it's missing
|
||||
// Object.prototype.constructor. Remove this eventually
|
||||
module.exports = function (obj) {
|
||||
return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)
|
||||
}
|
||||
|
||||
function isBuffer (obj) {
|
||||
return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
|
||||
}
|
||||
|
||||
// For Node v0.10 support. Remove this eventually.
|
||||
function isSlowBuffer (obj) {
|
||||
return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))
|
||||
}
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 63287:
|
||||
|
@ -242428,6 +242592,173 @@ exports = module.exports = makeError;
|
|||
exports.BaseError = BaseError;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 41711:
|
||||
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
||||
|
||||
(function(){
|
||||
var crypt = __nccwpck_require__(37935),
|
||||
utf8 = (__nccwpck_require__(50421).utf8),
|
||||
isBuffer = __nccwpck_require__(35625),
|
||||
bin = (__nccwpck_require__(50421).bin),
|
||||
|
||||
// The core
|
||||
md5 = function (message, options) {
|
||||
// Convert to byte array
|
||||
if (message.constructor == String)
|
||||
if (options && options.encoding === 'binary')
|
||||
message = bin.stringToBytes(message);
|
||||
else
|
||||
message = utf8.stringToBytes(message);
|
||||
else if (isBuffer(message))
|
||||
message = Array.prototype.slice.call(message, 0);
|
||||
else if (!Array.isArray(message) && message.constructor !== Uint8Array)
|
||||
message = message.toString();
|
||||
// else, assume byte array already
|
||||
|
||||
var m = crypt.bytesToWords(message),
|
||||
l = message.length * 8,
|
||||
a = 1732584193,
|
||||
b = -271733879,
|
||||
c = -1732584194,
|
||||
d = 271733878;
|
||||
|
||||
// Swap endian
|
||||
for (var i = 0; i < m.length; i++) {
|
||||
m[i] = ((m[i] << 8) | (m[i] >>> 24)) & 0x00FF00FF |
|
||||
((m[i] << 24) | (m[i] >>> 8)) & 0xFF00FF00;
|
||||
}
|
||||
|
||||
// Padding
|
||||
m[l >>> 5] |= 0x80 << (l % 32);
|
||||
m[(((l + 64) >>> 9) << 4) + 14] = l;
|
||||
|
||||
// Method shortcuts
|
||||
var FF = md5._ff,
|
||||
GG = md5._gg,
|
||||
HH = md5._hh,
|
||||
II = md5._ii;
|
||||
|
||||
for (var i = 0; i < m.length; i += 16) {
|
||||
|
||||
var aa = a,
|
||||
bb = b,
|
||||
cc = c,
|
||||
dd = d;
|
||||
|
||||
a = FF(a, b, c, d, m[i+ 0], 7, -680876936);
|
||||
d = FF(d, a, b, c, m[i+ 1], 12, -389564586);
|
||||
c = FF(c, d, a, b, m[i+ 2], 17, 606105819);
|
||||
b = FF(b, c, d, a, m[i+ 3], 22, -1044525330);
|
||||
a = FF(a, b, c, d, m[i+ 4], 7, -176418897);
|
||||
d = FF(d, a, b, c, m[i+ 5], 12, 1200080426);
|
||||
c = FF(c, d, a, b, m[i+ 6], 17, -1473231341);
|
||||
b = FF(b, c, d, a, m[i+ 7], 22, -45705983);
|
||||
a = FF(a, b, c, d, m[i+ 8], 7, 1770035416);
|
||||
d = FF(d, a, b, c, m[i+ 9], 12, -1958414417);
|
||||
c = FF(c, d, a, b, m[i+10], 17, -42063);
|
||||
b = FF(b, c, d, a, m[i+11], 22, -1990404162);
|
||||
a = FF(a, b, c, d, m[i+12], 7, 1804603682);
|
||||
d = FF(d, a, b, c, m[i+13], 12, -40341101);
|
||||
c = FF(c, d, a, b, m[i+14], 17, -1502002290);
|
||||
b = FF(b, c, d, a, m[i+15], 22, 1236535329);
|
||||
|
||||
a = GG(a, b, c, d, m[i+ 1], 5, -165796510);
|
||||
d = GG(d, a, b, c, m[i+ 6], 9, -1069501632);
|
||||
c = GG(c, d, a, b, m[i+11], 14, 643717713);
|
||||
b = GG(b, c, d, a, m[i+ 0], 20, -373897302);
|
||||
a = GG(a, b, c, d, m[i+ 5], 5, -701558691);
|
||||
d = GG(d, a, b, c, m[i+10], 9, 38016083);
|
||||
c = GG(c, d, a, b, m[i+15], 14, -660478335);
|
||||
b = GG(b, c, d, a, m[i+ 4], 20, -405537848);
|
||||
a = GG(a, b, c, d, m[i+ 9], 5, 568446438);
|
||||
d = GG(d, a, b, c, m[i+14], 9, -1019803690);
|
||||
c = GG(c, d, a, b, m[i+ 3], 14, -187363961);
|
||||
b = GG(b, c, d, a, m[i+ 8], 20, 1163531501);
|
||||
a = GG(a, b, c, d, m[i+13], 5, -1444681467);
|
||||
d = GG(d, a, b, c, m[i+ 2], 9, -51403784);
|
||||
c = GG(c, d, a, b, m[i+ 7], 14, 1735328473);
|
||||
b = GG(b, c, d, a, m[i+12], 20, -1926607734);
|
||||
|
||||
a = HH(a, b, c, d, m[i+ 5], 4, -378558);
|
||||
d = HH(d, a, b, c, m[i+ 8], 11, -2022574463);
|
||||
c = HH(c, d, a, b, m[i+11], 16, 1839030562);
|
||||
b = HH(b, c, d, a, m[i+14], 23, -35309556);
|
||||
a = HH(a, b, c, d, m[i+ 1], 4, -1530992060);
|
||||
d = HH(d, a, b, c, m[i+ 4], 11, 1272893353);
|
||||
c = HH(c, d, a, b, m[i+ 7], 16, -155497632);
|
||||
b = HH(b, c, d, a, m[i+10], 23, -1094730640);
|
||||
a = HH(a, b, c, d, m[i+13], 4, 681279174);
|
||||
d = HH(d, a, b, c, m[i+ 0], 11, -358537222);
|
||||
c = HH(c, d, a, b, m[i+ 3], 16, -722521979);
|
||||
b = HH(b, c, d, a, m[i+ 6], 23, 76029189);
|
||||
a = HH(a, b, c, d, m[i+ 9], 4, -640364487);
|
||||
d = HH(d, a, b, c, m[i+12], 11, -421815835);
|
||||
c = HH(c, d, a, b, m[i+15], 16, 530742520);
|
||||
b = HH(b, c, d, a, m[i+ 2], 23, -995338651);
|
||||
|
||||
a = II(a, b, c, d, m[i+ 0], 6, -198630844);
|
||||
d = II(d, a, b, c, m[i+ 7], 10, 1126891415);
|
||||
c = II(c, d, a, b, m[i+14], 15, -1416354905);
|
||||
b = II(b, c, d, a, m[i+ 5], 21, -57434055);
|
||||
a = II(a, b, c, d, m[i+12], 6, 1700485571);
|
||||
d = II(d, a, b, c, m[i+ 3], 10, -1894986606);
|
||||
c = II(c, d, a, b, m[i+10], 15, -1051523);
|
||||
b = II(b, c, d, a, m[i+ 1], 21, -2054922799);
|
||||
a = II(a, b, c, d, m[i+ 8], 6, 1873313359);
|
||||
d = II(d, a, b, c, m[i+15], 10, -30611744);
|
||||
c = II(c, d, a, b, m[i+ 6], 15, -1560198380);
|
||||
b = II(b, c, d, a, m[i+13], 21, 1309151649);
|
||||
a = II(a, b, c, d, m[i+ 4], 6, -145523070);
|
||||
d = II(d, a, b, c, m[i+11], 10, -1120210379);
|
||||
c = II(c, d, a, b, m[i+ 2], 15, 718787259);
|
||||
b = II(b, c, d, a, m[i+ 9], 21, -343485551);
|
||||
|
||||
a = (a + aa) >>> 0;
|
||||
b = (b + bb) >>> 0;
|
||||
c = (c + cc) >>> 0;
|
||||
d = (d + dd) >>> 0;
|
||||
}
|
||||
|
||||
return crypt.endian([a, b, c, d]);
|
||||
};
|
||||
|
||||
// Auxiliary functions
|
||||
md5._ff = function (a, b, c, d, x, s, t) {
|
||||
var n = a + (b & c | ~b & d) + (x >>> 0) + t;
|
||||
return ((n << s) | (n >>> (32 - s))) + b;
|
||||
};
|
||||
md5._gg = function (a, b, c, d, x, s, t) {
|
||||
var n = a + (b & d | c & ~d) + (x >>> 0) + t;
|
||||
return ((n << s) | (n >>> (32 - s))) + b;
|
||||
};
|
||||
md5._hh = function (a, b, c, d, x, s, t) {
|
||||
var n = a + (b ^ c ^ d) + (x >>> 0) + t;
|
||||
return ((n << s) | (n >>> (32 - s))) + b;
|
||||
};
|
||||
md5._ii = function (a, b, c, d, x, s, t) {
|
||||
var n = a + (c ^ (b | ~d)) + (x >>> 0) + t;
|
||||
return ((n << s) | (n >>> (32 - s))) + b;
|
||||
};
|
||||
|
||||
// Package private blocksize
|
||||
md5._blocksize = 16;
|
||||
md5._digestsize = 16;
|
||||
|
||||
module.exports = function (message, options) {
|
||||
if (message === undefined || message === null)
|
||||
throw new Error('Illegal argument ' + message);
|
||||
|
||||
var digestbytes = crypt.wordsToBytes(md5(message, options));
|
||||
return options && options.asBytes ? digestbytes :
|
||||
options && options.asString ? bin.bytesToString(digestbytes) :
|
||||
crypt.bytesToHex(digestbytes);
|
||||
};
|
||||
|
||||
})();
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2621:
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1844,6 +1844,37 @@ If the Work includes a "NOTICE" text file as part of its distribution, then any
|
|||
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
charenc
|
||||
BSD-3-Clause
|
||||
Copyright © 2011, Paul Vorbach. All rights reserved.
|
||||
Copyright © 2009, Jeff Mott. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
* Neither the name Crypto-JS nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific prior
|
||||
written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
chownr
|
||||
ISC
|
||||
The ISC License
|
||||
|
@ -2039,6 +2070,37 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|||
THE SOFTWARE.
|
||||
|
||||
|
||||
crypt
|
||||
BSD-3-Clause
|
||||
Copyright © 2011, Paul Vorbach. All rights reserved.
|
||||
Copyright © 2009, Jeff Mott. All rights reserved.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
* Neither the name Crypto-JS nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific prior
|
||||
written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
decompress-response
|
||||
MIT
|
||||
MIT License
|
||||
|
@ -2825,6 +2887,31 @@ PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
|
||||
|
||||
is-buffer
|
||||
MIT
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Feross Aboukhadijeh
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
is-plain-object
|
||||
MIT
|
||||
The MIT License (MIT)
|
||||
|
@ -3392,6 +3479,37 @@ Permission to use, copy, modify, and/or distribute this software for any purpose
|
|||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
|
||||
md5
|
||||
BSD-3-Clause
|
||||
Copyright © 2011-2012, Paul Vorbach.
|
||||
Copyright © 2009, Jeff Mott.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
* Neither the name Crypto-JS nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific prior
|
||||
written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
merge-stream
|
||||
MIT
|
||||
The MIT License (MIT)
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
"commander": "^9.0.0",
|
||||
"commander-ts": "^0.2.0",
|
||||
"kubernetes-client": "^9.0.0",
|
||||
"md5": "^2.3.0",
|
||||
"nanoid": "^3.3.1",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"semver": "^7.5.2",
|
||||
|
|
|
@ -5,11 +5,10 @@ import { CloudRunnerSystem } from '../../services/core/cloud-runner-system';
|
|||
import CloudRunner from '../../cloud-runner';
|
||||
import KubernetesPods from './kubernetes-pods';
|
||||
import { FollowLogStreamService } from '../../services/core/follow-log-stream-service';
|
||||
import { RemoteClientLogger } from '../../remote-client/remote-client-logger';
|
||||
|
||||
class KubernetesTaskRunner {
|
||||
static lastReceivedTimestamp: number = 0;
|
||||
static readonly maxRetry: number = 3;
|
||||
static lastReceivedMessage: string = ``;
|
||||
static async runTask(
|
||||
kubeConfig: KubeConfig,
|
||||
kubeClient: CoreV1Api,
|
||||
|
@ -21,30 +20,17 @@ class KubernetesTaskRunner {
|
|||
let output = '';
|
||||
let shouldReadLogs = true;
|
||||
let shouldCleanup = true;
|
||||
let sinceTime = ``;
|
||||
let retriesAfterFinish = 0;
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
while (true) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 3000));
|
||||
const lastReceivedMessage =
|
||||
KubernetesTaskRunner.lastReceivedTimestamp > 0
|
||||
? `\nLast Log Message "${this.lastReceivedMessage}" ${this.lastReceivedTimestamp}`
|
||||
: ``;
|
||||
CloudRunnerLogger.log(
|
||||
`Streaming logs from pod: ${podName} container: ${containerName} namespace: ${namespace} ${CloudRunner.buildParameters.kubeVolumeSize}/${CloudRunner.buildParameters.containerCpu}/${CloudRunner.buildParameters.containerMemory}\n${lastReceivedMessage}`,
|
||||
`Streaming logs from pod: ${podName} container: ${containerName} namespace: ${namespace} ${CloudRunner.buildParameters.kubeVolumeSize}/${CloudRunner.buildParameters.containerCpu}/${CloudRunner.buildParameters.containerMemory}`,
|
||||
);
|
||||
if (KubernetesTaskRunner.lastReceivedTimestamp > 0) {
|
||||
CloudRunnerLogger.log(`Last received timestamp was set, including --since-time parameter`);
|
||||
const currentDate = new Date(KubernetesTaskRunner.lastReceivedTimestamp);
|
||||
const dateTimeIsoString = currentDate.toISOString();
|
||||
sinceTime = ` --since-time="${dateTimeIsoString}"`;
|
||||
}
|
||||
let extraFlags = ``;
|
||||
extraFlags += (await KubernetesPods.IsPodRunning(podName, namespace, kubeClient))
|
||||
? ` -f -c ${containerName}`
|
||||
: ` --previous`;
|
||||
let lastMessageSeenIncludedInChunk = false;
|
||||
let lastMessageSeen = false;
|
||||
|
||||
let logs;
|
||||
const callback = (outputChunk: string) => {
|
||||
|
@ -56,12 +42,7 @@ class KubernetesTaskRunner {
|
|||
}
|
||||
};
|
||||
try {
|
||||
logs = await CloudRunnerSystem.Run(
|
||||
`kubectl logs ${podName}${extraFlags} --timestamps${sinceTime}`,
|
||||
false,
|
||||
true,
|
||||
callback,
|
||||
);
|
||||
logs = await CloudRunnerSystem.Run(`kubectl logs ${podName}${extraFlags}`, false, true, callback);
|
||||
} catch (error: any) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 3000));
|
||||
const continueStreaming = await KubernetesPods.IsPodRunning(podName, namespace, kubeClient);
|
||||
|
@ -78,31 +59,14 @@ class KubernetesTaskRunner {
|
|||
}
|
||||
const splitLogs = logs.split(`\n`);
|
||||
for (const chunk of splitLogs) {
|
||||
if (
|
||||
chunk.replace(/\s/g, ``) === KubernetesTaskRunner.lastReceivedMessage.replace(/\s/g, ``) &&
|
||||
KubernetesTaskRunner.lastReceivedMessage.replace(/\s/g, ``) !== ``
|
||||
) {
|
||||
CloudRunnerLogger.log(`Previous log message found ${chunk}`);
|
||||
lastMessageSeenIncludedInChunk = true;
|
||||
}
|
||||
}
|
||||
for (const chunk of splitLogs) {
|
||||
const newDate = Date.parse(`${chunk.toString().split(`Z `)[0]}Z`);
|
||||
if (chunk.replace(/\s/g, ``) === KubernetesTaskRunner.lastReceivedMessage.replace(/\s/g, ``)) {
|
||||
lastMessageSeen = true;
|
||||
}
|
||||
if (lastMessageSeenIncludedInChunk && !lastMessageSeen) {
|
||||
continue;
|
||||
}
|
||||
const message = CloudRunner.buildParameters.cloudRunnerDebug ? chunk : chunk.split(`Z `)[1];
|
||||
KubernetesTaskRunner.lastReceivedMessage = chunk;
|
||||
KubernetesTaskRunner.lastReceivedTimestamp = newDate;
|
||||
({ shouldReadLogs, shouldCleanup, output } = FollowLogStreamService.handleIteration(
|
||||
message,
|
||||
shouldReadLogs,
|
||||
shouldCleanup,
|
||||
output,
|
||||
));
|
||||
FollowLogStreamService.DidReceiveEndOfTransmission = RemoteClientLogger.HandleLogChunkLine(message);
|
||||
}
|
||||
if (FollowLogStreamService.DidReceiveEndOfTransmission) {
|
||||
CloudRunnerLogger.log('end of log stream');
|
||||
|
|
|
@ -5,6 +5,7 @@ import CloudRunner from '../cloud-runner';
|
|||
import CloudRunnerOptions from '../options/cloud-runner-options';
|
||||
import { CloudRunnerSystem } from '../services/core/cloud-runner-system';
|
||||
import { CloudRunnerFolders } from '../options/cloud-runner-folders';
|
||||
const md5 = require('md5');
|
||||
|
||||
export class RemoteClientLogger {
|
||||
private static get LogFilePath() {
|
||||
|
@ -71,4 +72,29 @@ export class RemoteClientLogger {
|
|||
await new Promise((resolve) => setTimeout(resolve, 15000));
|
||||
}
|
||||
}
|
||||
public static HandleLogChunkLine(message: string): boolean {
|
||||
if (message.includes('LOGHASH: ')) {
|
||||
RemoteClientLogger.md5 = message.split(`LOGHASH: `)[1];
|
||||
CloudRunnerLogger.log(`LOGHASH: ${RemoteClientLogger.md5}`);
|
||||
} else {
|
||||
if (RemoteClientLogger.value !== '') {
|
||||
RemoteClientLogger.value += `\n`;
|
||||
}
|
||||
|
||||
RemoteClientLogger.value += message;
|
||||
const hashedValue = md5(RemoteClientLogger.value);
|
||||
CloudRunnerLogger.log(
|
||||
`LOG ITERATION \n message:${message} \n target hash:${RemoteClientLogger.md5} \n hash latest value:${hashedValue} \n cache value:${RemoteClientLogger.value}`,
|
||||
);
|
||||
if (RemoteClientLogger.md5 === hashedValue) {
|
||||
CloudRunnerLogger.log(`LOG COMPLETE`);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
static value: string = '';
|
||||
static md5: any;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
import { RemoteClientLogger } from '../../remote-client/remote-client-logger';
|
||||
import setups from '../cloud-runner-suite.test';
|
||||
const md5 = require('md5');
|
||||
|
||||
describe('Cloud Runner Remote Client', () => {
|
||||
it('Responds', () => {});
|
||||
setups();
|
||||
it('Run one build it using K8s without error', async () => {
|
||||
const testLogStream = 'Test \n Log \n Stream';
|
||||
|
||||
const splitLogStream = testLogStream.split('\n');
|
||||
RemoteClientLogger.HandleLogChunkLine(`LOGHASH: ${md5(testLogStream)}`);
|
||||
let completed = false;
|
||||
for (const element of splitLogStream) {
|
||||
completed = RemoteClientLogger.HandleLogChunkLine(element);
|
||||
}
|
||||
expect(completed).toBeTruthy();
|
||||
}, 1_000_000_000);
|
||||
// eslint-disable-next-line unicorn/consistent-function-scoping, no-unused-vars
|
||||
function CreateLogWatcher(callback: (finalMessage: string) => void) {
|
||||
return (message: string) => {
|
||||
callback(message);
|
||||
};
|
||||
}
|
||||
});
|
24
yarn.lock
24
yarn.lock
|
@ -1972,6 +1972,11 @@ char-regex@^1.0.2:
|
|||
resolved "https://registry.npmjs.org/char-regex/-/char-regex-1.0.2.tgz"
|
||||
integrity sha512-kWWXztvZ5SBQV+eRgKFeh8q5sLuZY2+8WUIzlxWVTg+oGwY14qylx1KbKzHd8P6ZYkAg0xyIDU9JMHhyJMZ1jw==
|
||||
|
||||
charenc@0.0.2:
|
||||
version "0.0.2"
|
||||
resolved "https://registry.yarnpkg.com/charenc/-/charenc-0.0.2.tgz#c0a1d2f3a7092e03774bfa83f14c0fc5790a8667"
|
||||
integrity sha512-yrLQ/yVUFXkzg7EDQsPieE/53+0RlaWTs+wBrvW36cyilJ2SaDWfl4Yj7MtLTXleV9uEKefbAGUPv2/iWSooRA==
|
||||
|
||||
chownr@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz"
|
||||
|
@ -2155,6 +2160,11 @@ cross-spawn@^7.0.1, cross-spawn@^7.0.2, cross-spawn@^7.0.3:
|
|||
shebang-command "^2.0.0"
|
||||
which "^2.0.1"
|
||||
|
||||
crypt@0.0.2:
|
||||
version "0.0.2"
|
||||
resolved "https://registry.yarnpkg.com/crypt/-/crypt-0.0.2.tgz#88d7ff7ec0dfb86f713dc87bbb42d044d3e6c41b"
|
||||
integrity sha512-mCxBlsHFYh9C+HVpiEacem8FEBnMXgU9gy4zmNC+SXAZNB/1idgp/aulFJ4FgCi7GPEVbfyng092GqL2k2rmow==
|
||||
|
||||
cssom@^0.4.4:
|
||||
version "0.4.4"
|
||||
resolved "https://registry.npmjs.org/cssom/-/cssom-0.4.4.tgz"
|
||||
|
@ -3301,6 +3311,11 @@ is-boolean-object@^1.1.0:
|
|||
dependencies:
|
||||
call-bind "^1.0.0"
|
||||
|
||||
is-buffer@~1.1.6:
|
||||
version "1.1.6"
|
||||
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be"
|
||||
integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==
|
||||
|
||||
is-callable@^1.1.4, is-callable@^1.2.3:
|
||||
version "1.2.3"
|
||||
resolved "https://registry.npmjs.org/is-callable/-/is-callable-1.2.3.tgz"
|
||||
|
@ -4224,6 +4239,15 @@ makeerror@1.0.x:
|
|||
dependencies:
|
||||
tmpl "1.0.x"
|
||||
|
||||
md5@^2.3.0:
|
||||
version "2.3.0"
|
||||
resolved "https://registry.yarnpkg.com/md5/-/md5-2.3.0.tgz#c3da9a6aae3a30b46b7b0c349b87b110dc3bda4f"
|
||||
integrity sha512-T1GITYmFaKuO91vxyoQMFETst+O71VUPEU3ze5GNzDm0OWdP8v1ziTaAEPUr/3kLsY3Sftgz242A1SetQiDL7g==
|
||||
dependencies:
|
||||
charenc "0.0.2"
|
||||
crypt "0.0.2"
|
||||
is-buffer "~1.1.6"
|
||||
|
||||
merge-stream@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz"
|
||||
|
|
Loading…
Reference in New Issue