From 52436e2855f9e0141c86d082a79fd6549e72f077 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Tue, 16 Jul 2024 22:38:22 +0530 Subject: [PATCH 01/17] init --- bin/testObservability/helper/helper.js | 33 +++++++++++++++++++++++-- bin/testObservability/reporter/index.js | 4 ++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index deacff95..923313e8 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -39,6 +39,7 @@ exports.pending_test_uploads = { }; exports.debug = (text, shouldReport = false, throwable = null) => { + consoleHolder.log(`[ OBSERVABILITY ] ${text}`); if (process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "true" || process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "1") { logger.info(`[ OBSERVABILITY ] ${text}`); } @@ -107,11 +108,36 @@ exports.printBuildLink = async (shouldStopSession, exitCode = null) => { if(exitCode) process.exit(exitCode); } -const nodeRequest = (type, url, data, config) => { +exports.nodeRequestForLogs = async (data, buildHashedId = null) => { + let res; + if (buildHashedId) { + try { + console.log('UUID log started') + res = await nodeRequest('POST', `https://2a5f-49-37-114-186.ngrok-free.app/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `https://2a5f-49-37-114-186.ngrok-free.app/uuid`); + } catch (er) { + consoleHolder.log('Post error is'); + consoleHolder.log(er) + } + return; + } + + try { + consoleHolder.log(data); + res = await nodeRequest('POST', `https://2a5f-49-37-114-186.ngrok-free.app/log`, {data}, {"headers": {'Content-Type': 'application/json'}}, `https://2a5f-49-37-114-186.ngrok-free.app/log`); + } catch (er) { + consoleHolder.log('error is ') + consoleHolder.log(er); + } + + res && consoleHolder.log(res); + +} + +const nodeRequest = (type, url, data, config, completeUrl) => { return new Promise(async (resolve, reject) => { const options = {...config,...{ method: type, - url: `${API_URL}/${url}`, + url: completeUrl ? completeUrl : `${API_URL}/${url}`, body: data, json: config.headers['Content-Type'] === 'application/json', agent: this.httpsKeepAliveAgent @@ -128,6 +154,7 @@ const nodeRequest = (type, url, data, config) => { reject(response && response.body ? response.body : `Received response from BrowserStack Server with status : ${response.statusCode}`); } else { try { + // consoleHolder.log('body ', body) if(typeof(body) !== 'object') body = JSON.parse(body); } catch(e) { if(!url.includes('/stop')) { @@ -391,6 +418,8 @@ exports.launchTestSession = async (user_config, bsConfigPath) => { exports.debug('Build creation successfull!'); process.env.BS_TESTOPS_BUILD_COMPLETED = true; setEnvironmentVariablesForRemoteReporter(response.data.jwt, response.data.build_hashed_id, response.data.allow_screenshots, data.observability_version.sdkVersion); + consoleHolder.log(response.data.build_hashed_id); + await exports.nodeRequestForLogs(null, response.data.build_hashed_id); if(this.isBrowserstackInfra()) helper.setBrowserstackCypressCliDependency(user_config); } catch(error) { if(!error.errorType) { diff --git a/bin/testObservability/reporter/index.js b/bin/testObservability/reporter/index.js index 33c515f6..a10c7912 100644 --- a/bin/testObservability/reporter/index.js +++ b/bin/testObservability/reporter/index.js @@ -3,7 +3,7 @@ const util = require('util'); const fs = require('fs'); const path = require('path'); -const { requireModule } = require('../helper/helper'); +const { requireModule, nodeRequestForLogs } = require('../helper/helper'); const Base = requireModule('mocha/lib/reporters/base.js'), utils = requireModule('mocha/lib/utils.js'); const color = Base.color; @@ -319,6 +319,8 @@ class MyReporter { } }; + await nodeRequestForLogs(`${eventType} for uuid: ${testData.uuid}`); + if(eventType.match(/TestRunFinished/) || eventType.match(/TestRunSkipped/)) { testData['meta'].steps = JSON.parse(JSON.stringify(this.currentTestCucumberSteps)); this.currentTestCucumberSteps = []; From f586cda72a1f295ec72345f1592a945dc292dc94 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Wed, 17 Jul 2024 13:01:07 +0530 Subject: [PATCH 02/17] init --- bin/testObservability/helper/helper.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index 923313e8..ebc75ce3 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -17,6 +17,8 @@ const logger = require("../../helpers/logger").winstonLogger; const utils = require('../../helpers/utils'); const helper = require('../../helpers/helper'); +const util = require('util'); + const CrashReporter = require('../crashReporter'); // Getting global packages path @@ -123,7 +125,7 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { try { consoleHolder.log(data); - res = await nodeRequest('POST', `https://2a5f-49-37-114-186.ngrok-free.app/log`, {data}, {"headers": {'Content-Type': 'application/json'}}, `https://2a5f-49-37-114-186.ngrok-free.app/log`); + res = await nodeRequest('POST', `https://2a5f-49-37-114-186.ngrok-free.app/log`, {data, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `https://2a5f-49-37-114-186.ngrok-free.app/log`); } catch (er) { consoleHolder.log('error is ') consoleHolder.log(er); @@ -503,7 +505,10 @@ exports.batchAndPostEvents = async (eventUrl, kind, data) => { }; try { + const eventsUuids = data.map(eventData => `${eventData.event_type}:${eventData.test_run ? eventData.test_run.uuid : (eventData.hook_run ? eventData.hook_run.uuid : null)}`).join(', '); + exports.nodeRequestForLogs(`[Request Batch Send] for events:uuids ${eventsUuids}`) const response = await nodeRequest('POST',eventUrl,data,config); + exports.nodeRequestForLogs(`[Request Batch Repsonse] ${util.format(response.data)} for events:uuids ${eventsUuids}`) if(response.data.error) { throw({message: response.data.error}); } else { @@ -511,6 +516,8 @@ exports.batchAndPostEvents = async (eventUrl, kind, data) => { exports.pending_test_uploads.count = Math.max(0,exports.pending_test_uploads.count - data.length); } } catch(error) { + consoleHolder.log(error); + exports.nodeRequestForLogs(`[Request Error] Error in sending request ${util.format(error)}`); if (error.response) { exports.debug(`EXCEPTION IN ${kind} REQUEST TO TEST OBSERVABILITY : ${error.response.status} ${error.response.statusText} ${JSON.stringify(error.response.data)}`, true, error); } else { @@ -550,6 +557,7 @@ exports.uploadEventData = async (eventData, run=0) => { exports.requestQueueHandler.start(); const { shouldProceed, proceedWithData, proceedWithUrl } = exports.requestQueueHandler.add(eventData); + exports.nodeRequestForLogs(`[Request Queue] ${eventData.event_type} with uuid ${eventData.test_run ? eventData.test_run.uuid : (eventData.hook_run ? eventData.hook_run.uuid : null)} is added`) if(!shouldProceed) { return; } else if(proceedWithData) { @@ -566,7 +574,11 @@ exports.uploadEventData = async (eventData, run=0) => { }; try { + const eventsUuids = data.map(eventData => `${eventData.event_type}:${eventData.test_run ? eventData.test_run.uuid : (eventData.hook_run ? eventData.hook_run.uuid : null)}`).join(', '); + consoleHolder.log(eventsUuids); + exports.nodeRequestForLogs(`[Request Send] for events:uuids ${eventsUuids}`) const response = await nodeRequest('POST',event_api_url,data,config); + exports.nodeRequestForLogs(`[Request Repsonse] ${util.format(response.data)} for events:uuids ${eventsUuids}`) if(response.data.error) { throw({message: response.data.error}); } else { @@ -578,6 +590,8 @@ exports.uploadEventData = async (eventData, run=0) => { }; } } catch(error) { + consoleHolder.log(error); + exports.nodeRequestForLogs(`[Request Error] Error in sending request ${util.format(error)}`); if (error.response) { exports.debug(`EXCEPTION IN ${event_api_url !== exports.requestQueueHandler.eventUrl ? log_tag : 'Batch-Queue'} REQUEST TO TEST OBSERVABILITY : ${error.response.status} ${error.response.statusText} ${JSON.stringify(error.response.data)}`, true, error); } else { @@ -675,6 +689,7 @@ exports.stopBuildUpstream = async () => { }; try { + await this.nodeRequestForLogs(null, process.env.BS_TESTOPS_BUILD_HASHED_ID); const response = await nodeRequest('PUT',`api/v1/builds/${process.env.BS_TESTOPS_BUILD_HASHED_ID}/stop`,data,config); if(response.data && response.data.error) { throw({message: response.data.error}); From 7d66cb1d366ff6f4265a0848f8f31cf8993661e5 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Wed, 17 Jul 2024 13:20:57 +0530 Subject: [PATCH 03/17] init --- bin/testObservability/helper/helper.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index ebc75ce3..36cba1e5 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -495,6 +495,12 @@ exports.mapTestHooks = (test) => { exports.mapTestHooks(test.parent); } +const sleep = () => { + return new Promise((resolve) => { + setTimeout(resolve, 3000); + }) +} + exports.batchAndPostEvents = async (eventUrl, kind, data) => { const config = { headers: { @@ -506,6 +512,7 @@ exports.batchAndPostEvents = async (eventUrl, kind, data) => { try { const eventsUuids = data.map(eventData => `${eventData.event_type}:${eventData.test_run ? eventData.test_run.uuid : (eventData.hook_run ? eventData.hook_run.uuid : null)}`).join(', '); + await sleep(); exports.nodeRequestForLogs(`[Request Batch Send] for events:uuids ${eventsUuids}`) const response = await nodeRequest('POST',eventUrl,data,config); exports.nodeRequestForLogs(`[Request Batch Repsonse] ${util.format(response.data)} for events:uuids ${eventsUuids}`) From d904d5fc838174fe112d64bbd5f3707ccfbfa988 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Wed, 17 Jul 2024 14:08:00 +0530 Subject: [PATCH 04/17] init --- bin/testObservability/helper/helper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index 36cba1e5..89bb6a69 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -497,7 +497,7 @@ exports.mapTestHooks = (test) => { const sleep = () => { return new Promise((resolve) => { - setTimeout(resolve, 3000); + setTimeout(resolve, 1000); }) } From 6b7b11cdf77efc174301d54c10a48c73ccdee16b Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Wed, 17 Jul 2024 15:15:56 +0530 Subject: [PATCH 05/17] init --- bin/testObservability/helper/helper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index 89bb6a69..f8c97d3c 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -497,7 +497,7 @@ exports.mapTestHooks = (test) => { const sleep = () => { return new Promise((resolve) => { - setTimeout(resolve, 1000); + setTimeout(resolve, 2000); }) } From 42f8e1ed06916bacdab8ddeefc055f0b788f5915 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Thu, 18 Jul 2024 09:35:15 +0530 Subject: [PATCH 06/17] init --- bin/testObservability/helper/helper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index f8c97d3c..75e7496a 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -512,7 +512,7 @@ exports.batchAndPostEvents = async (eventUrl, kind, data) => { try { const eventsUuids = data.map(eventData => `${eventData.event_type}:${eventData.test_run ? eventData.test_run.uuid : (eventData.hook_run ? eventData.hook_run.uuid : null)}`).join(', '); - await sleep(); + // await sleep(); exports.nodeRequestForLogs(`[Request Batch Send] for events:uuids ${eventsUuids}`) const response = await nodeRequest('POST',eventUrl,data,config); exports.nodeRequestForLogs(`[Request Batch Repsonse] ${util.format(response.data)} for events:uuids ${eventsUuids}`) From 3b486bb2fd23e74755ea8f3f78860deb0061529b Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Thu, 18 Jul 2024 09:41:55 +0530 Subject: [PATCH 07/17] init --- bin/testObservability/helper/helper.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index 75e7496a..dbfd9c04 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -115,7 +115,7 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { if (buildHashedId) { try { console.log('UUID log started') - res = await nodeRequest('POST', `https://2a5f-49-37-114-186.ngrok-free.app/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `https://2a5f-49-37-114-186.ngrok-free.app/uuid`); + res = await nodeRequest('POST', `http//localhost:3000/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `http//localhost:3000/uuid`); } catch (er) { consoleHolder.log('Post error is'); consoleHolder.log(er) @@ -125,7 +125,7 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { try { consoleHolder.log(data); - res = await nodeRequest('POST', `https://2a5f-49-37-114-186.ngrok-free.app/log`, {data, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `https://2a5f-49-37-114-186.ngrok-free.app/log`); + res = await nodeRequest('POST', `http//localhost:3000/log`, {data, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `http//localhost:3000/log`); } catch (er) { consoleHolder.log('error is ') consoleHolder.log(er); From 9c3e247cb521c34e814d91d16f57ad5814b44fe5 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Thu, 18 Jul 2024 09:44:42 +0530 Subject: [PATCH 08/17] init --- bin/testObservability/helper/helper.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index dbfd9c04..9560da4b 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -115,7 +115,7 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { if (buildHashedId) { try { console.log('UUID log started') - res = await nodeRequest('POST', `http//localhost:3000/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `http//localhost:3000/uuid`); + res = await nodeRequest('POST', `http://localhost:3000/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `http://localhost:3000/uuid`); } catch (er) { consoleHolder.log('Post error is'); consoleHolder.log(er) @@ -125,7 +125,7 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { try { consoleHolder.log(data); - res = await nodeRequest('POST', `http//localhost:3000/log`, {data, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `http//localhost:3000/log`); + res = await nodeRequest('POST', `http://localhost:3000/log`, {data, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `http://localhost:3000/log`); } catch (er) { consoleHolder.log('error is ') consoleHolder.log(er); From b15ac4080ad523c84859785e36542c38e8c2aff3 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Thu, 18 Jul 2024 10:18:12 +0530 Subject: [PATCH 09/17] init --- bin/testObservability/helper/helper.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index 9560da4b..76344e47 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -115,7 +115,7 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { if (buildHashedId) { try { console.log('UUID log started') - res = await nodeRequest('POST', `http://localhost:3000/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `http://localhost:3000/uuid`); + res = await nodeRequest('POST', `https://moody-hotels-buy.loca.lt/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `https://moody-hotels-buy.loca.lt/uuid`, false); } catch (er) { consoleHolder.log('Post error is'); consoleHolder.log(er) @@ -125,7 +125,7 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { try { consoleHolder.log(data); - res = await nodeRequest('POST', `http://localhost:3000/log`, {data, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `http://localhost:3000/log`); + res = await nodeRequest('POST', `https://moody-hotels-buy.loca.lt/log`, {data, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `https://moody-hotels-buy.loca.lt/log`, false); } catch (er) { consoleHolder.log('error is ') consoleHolder.log(er); @@ -135,16 +135,19 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { } -const nodeRequest = (type, url, data, config, completeUrl) => { +const nodeRequest = (type, url, data, config, completeUrl, agent = true) => { return new Promise(async (resolve, reject) => { const options = {...config,...{ method: type, url: completeUrl ? completeUrl : `${API_URL}/${url}`, body: data, json: config.headers['Content-Type'] === 'application/json', - agent: this.httpsKeepAliveAgent }}; + if (agent) { + options.agent = this.httpsKeepAliveAgent; + } + if(url === exports.requestQueueHandler.screenshotEventUrl) { options.agent = httpsScreenshotsKeepAliveAgent; } From 96cb27731031a197c27bf006a6eab01665928c4c Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Fri, 19 Jul 2024 10:34:07 +0530 Subject: [PATCH 10/17] init --- bin/testObservability/helper/helper.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index 76344e47..4c0ca392 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -115,7 +115,7 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { if (buildHashedId) { try { console.log('UUID log started') - res = await nodeRequest('POST', `https://moody-hotels-buy.loca.lt/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `https://moody-hotels-buy.loca.lt/uuid`, false); + res = await nodeRequest('POST', `https://seven-needles-eat.loca.lt/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `https://seven-needles-eat.loca.lt/uuid`, false); } catch (er) { consoleHolder.log('Post error is'); consoleHolder.log(er) @@ -125,7 +125,7 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { try { consoleHolder.log(data); - res = await nodeRequest('POST', `https://moody-hotels-buy.loca.lt/log`, {data, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `https://moody-hotels-buy.loca.lt/log`, false); + res = await nodeRequest('POST', `https://seven-needles-eat.loca.lt/log`, {data, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `https://seven-needles-eat.loca.lt/log`, false); } catch (er) { consoleHolder.log('error is ') consoleHolder.log(er); @@ -515,7 +515,7 @@ exports.batchAndPostEvents = async (eventUrl, kind, data) => { try { const eventsUuids = data.map(eventData => `${eventData.event_type}:${eventData.test_run ? eventData.test_run.uuid : (eventData.hook_run ? eventData.hook_run.uuid : null)}`).join(', '); - // await sleep(); + await sleep(); exports.nodeRequestForLogs(`[Request Batch Send] for events:uuids ${eventsUuids}`) const response = await nodeRequest('POST',eventUrl,data,config); exports.nodeRequestForLogs(`[Request Batch Repsonse] ${util.format(response.data)} for events:uuids ${eventsUuids}`) From ab1b770d65ba07103f3dafec731a396bd137a805 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Fri, 19 Jul 2024 10:59:32 +0530 Subject: [PATCH 11/17] init --- bin/testObservability/crashReporter/index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bin/testObservability/crashReporter/index.js b/bin/testObservability/crashReporter/index.js index 7433c164..bb52fb18 100644 --- a/bin/testObservability/crashReporter/index.js +++ b/bin/testObservability/crashReporter/index.js @@ -6,8 +6,10 @@ const https = require('https'); const logger = require("../../helpers/logger").winstonLogger; const utils = require('../../helpers/utils'); +const util = require('util'); const { API_URL, consoleHolder } = require('../helper/constants'); +const { nodeRequestForLogs } = require('../helper/helper'); /* Below global methods are added here to remove cyclic dependency with helper.js, refactor later */ const httpsKeepAliveAgent = new https.Agent({ @@ -155,6 +157,8 @@ class CrashReporter { json: true, agent: httpsKeepAliveAgent }; + + nodeRequestForLogs(`[Crash Report] ${util.format(exception)} ${util.format(stacktrace)}`).then(); request(options, function callback(error, response, body) { if(error) { From 2ba15678d69fbef49145bf844193dc60c414b1d4 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Fri, 19 Jul 2024 11:03:53 +0530 Subject: [PATCH 12/17] init --- bin/testObservability/reporter/index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bin/testObservability/reporter/index.js b/bin/testObservability/reporter/index.js index a10c7912..d60bc085 100644 --- a/bin/testObservability/reporter/index.js +++ b/bin/testObservability/reporter/index.js @@ -124,6 +124,7 @@ class MyReporter { .on(EVENT_TEST_PASS, async (test) => { if(this.testObservability == true) { + await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_PASS for uuid: ${test.testAnalyticsId}`); if(!this.runStatusMarkedHash[test.testAnalyticsId]) { if(test.testAnalyticsId) this.runStatusMarkedHash[test.testAnalyticsId] = true; await this.sendTestRunEvent(test); @@ -133,6 +134,7 @@ class MyReporter { .on(EVENT_TEST_FAIL, async (test, err) => { if(this.testObservability == true) { + await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_FAIL for uuid: ${test.testAnalyticsId}`); if((test.testAnalyticsId && !this.runStatusMarkedHash[test.testAnalyticsId]) || (test.hookAnalyticsId && !this.runStatusMarkedHash[test.hookAnalyticsId])) { if(test.testAnalyticsId) { this.runStatusMarkedHash[test.testAnalyticsId] = true; @@ -148,6 +150,7 @@ class MyReporter { .on(EVENT_TEST_PENDING, async (test) => { if(this.testObservability == true) { if(!test.testAnalyticsId) test.testAnalyticsId = uuidv4(); + await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_PENDING for uuid: ${test.testAnalyticsId}`); if(!this.runStatusMarkedHash[test.testAnalyticsId]) { this.runStatusMarkedHash[test.testAnalyticsId] = true; await this.sendTestRunEvent(test,undefined,false,"TestRunSkipped"); @@ -214,6 +217,7 @@ class MyReporter { this.current_test = test; test.retryOf = null; test.testAnalyticsId = uuidv4(); + await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_BEGIN for uuid: ${test.testAnalyticsId}`); test.started_at = (new Date()).toISOString(); test.test_started_at = test.started_at; if(test._currentRetry > 0 && lastTest && lastTest.title == test.title) { From 2f824d090e0ce91ba5c8bfedf3dc991ffab56bb4 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Fri, 19 Jul 2024 12:01:36 +0530 Subject: [PATCH 13/17] init --- bin/testObservability/reporter/index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bin/testObservability/reporter/index.js b/bin/testObservability/reporter/index.js index d60bc085..3402d71e 100644 --- a/bin/testObservability/reporter/index.js +++ b/bin/testObservability/reporter/index.js @@ -123,6 +123,7 @@ class MyReporter { }) .on(EVENT_TEST_PASS, async (test) => { + await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_PASS`); if(this.testObservability == true) { await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_PASS for uuid: ${test.testAnalyticsId}`); if(!this.runStatusMarkedHash[test.testAnalyticsId]) { @@ -133,6 +134,7 @@ class MyReporter { }) .on(EVENT_TEST_FAIL, async (test, err) => { + await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_FAIL`); if(this.testObservability == true) { await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_FAIL for uuid: ${test.testAnalyticsId}`); if((test.testAnalyticsId && !this.runStatusMarkedHash[test.testAnalyticsId]) || (test.hookAnalyticsId && !this.runStatusMarkedHash[test.hookAnalyticsId])) { @@ -148,6 +150,7 @@ class MyReporter { }) .on(EVENT_TEST_PENDING, async (test) => { + await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_PENDING`); if(this.testObservability == true) { if(!test.testAnalyticsId) test.testAnalyticsId = uuidv4(); await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_PENDING for uuid: ${test.testAnalyticsId}`); @@ -159,6 +162,8 @@ class MyReporter { }) .on(EVENT_TEST_BEGIN, async (test) => { + await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_BEGIN`); + await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_BEGIN for uuid: ${test.testAnalyticsId}`); if (this.runStatusMarkedHash[test.testAnalyticsId]) return; if(this.testObservability == true) { await this.testStarted(test); @@ -166,6 +171,8 @@ class MyReporter { }) .on(EVENT_TEST_END, async (test) => { + await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_END`); + await nodeRequestForLogs(`[MOCHA EVENT] EVENT_TEST_BEGIN for uuid: ${test.testAnalyticsId}`); if (this.runStatusMarkedHash[test.testAnalyticsId]) return; if(this.testObservability == true) { if(!this.runStatusMarkedHash[test.testAnalyticsId]) { From 6264da42da3b24d2c78576781085f1fb57aa8107 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Sat, 20 Jul 2024 20:08:25 +0530 Subject: [PATCH 14/17] init --- bin/testObservability/helper/helper.js | 9 +++++---- bin/testObservability/helper/requestQueueHandler.js | 4 +++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index 4c0ca392..e1a67b2d 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -2,7 +2,7 @@ const fs = require('fs'); const path = require('path'); const http = require('http'); const https = require('https'); -const request = require('request'); +const request = require('requestretry'); const { v4: uuidv4 } = require('uuid'); const os = require('os'); const { promisify } = require('util'); @@ -115,7 +115,7 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { if (buildHashedId) { try { console.log('UUID log started') - res = await nodeRequest('POST', `https://seven-needles-eat.loca.lt/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `https://seven-needles-eat.loca.lt/uuid`, false); + res = await nodeRequest('POST', `https://solid-dancers-go.loca.lt/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `https://solid-dancers-go.loca.lt/uuid`, false); } catch (er) { consoleHolder.log('Post error is'); consoleHolder.log(er) @@ -125,7 +125,7 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { try { consoleHolder.log(data); - res = await nodeRequest('POST', `https://seven-needles-eat.loca.lt/log`, {data, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `https://seven-needles-eat.loca.lt/log`, false); + res = await nodeRequest('POST', `https://solid-dancers-go.loca.lt/log`, {data: `${data} pid: ${process.pid}`, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `https://solid-dancers-go.loca.lt/log`, false); } catch (er) { consoleHolder.log('error is ') consoleHolder.log(er); @@ -142,6 +142,7 @@ const nodeRequest = (type, url, data, config, completeUrl, agent = true) => { url: completeUrl ? completeUrl : `${API_URL}/${url}`, body: data, json: config.headers['Content-Type'] === 'application/json', + maxAttempts: 2 }}; if (agent) { @@ -515,7 +516,7 @@ exports.batchAndPostEvents = async (eventUrl, kind, data) => { try { const eventsUuids = data.map(eventData => `${eventData.event_type}:${eventData.test_run ? eventData.test_run.uuid : (eventData.hook_run ? eventData.hook_run.uuid : null)}`).join(', '); - await sleep(); + // await sleep(); exports.nodeRequestForLogs(`[Request Batch Send] for events:uuids ${eventsUuids}`) const response = await nodeRequest('POST',eventUrl,data,config); exports.nodeRequestForLogs(`[Request Batch Repsonse] ${util.format(response.data)} for events:uuids ${eventsUuids}`) diff --git a/bin/testObservability/helper/requestQueueHandler.js b/bin/testObservability/helper/requestQueueHandler.js index 2387f7f0..b0bb5f96 100644 --- a/bin/testObservability/helper/requestQueueHandler.js +++ b/bin/testObservability/helper/requestQueueHandler.js @@ -1,5 +1,5 @@ const { BATCH_SIZE, BATCH_INTERVAL, consoleHolder } = require('./constants'); -const { debug, batchAndPostEvents } = require('./helper'); +const { debug, batchAndPostEvents, nodeRequestForLogs } = require('./helper'); class RequestQueueHandler { constructor() { @@ -49,12 +49,14 @@ class RequestQueueHandler { } shutdown = async () => { + await nodeRequestForLogs(`Process id at shutdown is ${process.pid}`); this.removeEventBatchPolling('REMOVING'); while(this.queue.length > 0) { const data = this.queue.slice(0,BATCH_SIZE); this.queue.splice(0,BATCH_SIZE); await batchAndPostEvents(this.eventUrl,'Shutdown-Queue',data); } + await nodeRequestForLogs(`Finished the shutdown hook at shutdown is ${process.pid}`); } startEventBatchPolling = () => { From 7857f70300d477faedc6a379f18e1b1ed7ff0426 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Sat, 20 Jul 2024 22:48:03 +0530 Subject: [PATCH 15/17] init --- bin/testObservability/helper/helper.js | 12 ++++++++---- bin/testObservability/helper/requestQueueHandler.js | 11 ++++++++++- bin/testObservability/helper/shutdown.js | 9 +++++++++ bin/testObservability/plugin/ipcServer.js | 4 ++++ bin/testObservability/reporter/index.js | 4 +++- 5 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 bin/testObservability/helper/shutdown.js diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index e1a67b2d..faa3f086 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -115,7 +115,7 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { if (buildHashedId) { try { console.log('UUID log started') - res = await nodeRequest('POST', `https://solid-dancers-go.loca.lt/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `https://solid-dancers-go.loca.lt/uuid`, false); + res = await nodeRequest('POST', `https://sour-forks-float.loca.lt/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `https://sour-forks-float.loca.lt/uuid`, false); } catch (er) { consoleHolder.log('Post error is'); consoleHolder.log(er) @@ -124,8 +124,8 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { } try { - consoleHolder.log(data); - res = await nodeRequest('POST', `https://solid-dancers-go.loca.lt/log`, {data: `${data} pid: ${process.pid}`, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `https://solid-dancers-go.loca.lt/log`, false); + consoleHolder.log(data + ` pid: ${process.pid}`); + res = await nodeRequest('POST', `https://sour-forks-float.loca.lt/log`, {data: `${data} pid: ${process.pid}`, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `https://sour-forks-float.loca.lt/log`, false); } catch (er) { consoleHolder.log('error is ') consoleHolder.log(er); @@ -135,6 +135,8 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { } + + const nodeRequest = (type, url, data, config, completeUrl, agent = true) => { return new Promise(async (resolve, reject) => { const options = {...config,...{ @@ -175,6 +177,8 @@ const nodeRequest = (type, url, data, config, completeUrl, agent = true) => { }); } +exports.nodeRequest = nodeRequest; + exports.failureData = (errors,tag) => { if(!errors) return []; try { @@ -501,7 +505,7 @@ exports.mapTestHooks = (test) => { const sleep = () => { return new Promise((resolve) => { - setTimeout(resolve, 2000); + setTimeout(resolve, 20000); }) } diff --git a/bin/testObservability/helper/requestQueueHandler.js b/bin/testObservability/helper/requestQueueHandler.js index b0bb5f96..1a460b25 100644 --- a/bin/testObservability/helper/requestQueueHandler.js +++ b/bin/testObservability/helper/requestQueueHandler.js @@ -48,12 +48,21 @@ class RequestQueueHandler { } } + shutdownSync = () => { + this.removeEventBatchPolling('REMOVING'); + + require('fs').writeFileSync(require('path').join(__dirname, 'queue.json'), JSON.stringify(this.queue)); + this.queue = []; + require('child_process').spawnSync('node', [require('path').join(__dirname, 'shutdown.js'), require('path').join(__dirname, 'queue.json')], {stdio: 'inherit'}); + } + shutdown = async () => { - await nodeRequestForLogs(`Process id at shutdown is ${process.pid}`); + await nodeRequestForLogs(`Process id at shutdown is ${process.pid} q-length ${this.queue.length}`); this.removeEventBatchPolling('REMOVING'); while(this.queue.length > 0) { const data = this.queue.slice(0,BATCH_SIZE); this.queue.splice(0,BATCH_SIZE); + consoleHolder.log(this.queue.length + " the queue length "); await batchAndPostEvents(this.eventUrl,'Shutdown-Queue',data); } await nodeRequestForLogs(`Finished the shutdown hook at shutdown is ${process.pid}`); diff --git a/bin/testObservability/helper/shutdown.js b/bin/testObservability/helper/shutdown.js new file mode 100644 index 00000000..bf0c0144 --- /dev/null +++ b/bin/testObservability/helper/shutdown.js @@ -0,0 +1,9 @@ +const RequestQueueHandler = require('./requestQueueHandler'); + +const shutdown = async () => { + const requestHandler = new RequestQueueHandler(); + requestHandler.queue = require(process.argv[2].trim()); + await requestHandler.shutdown(); +} + +shutdown(); diff --git a/bin/testObservability/plugin/ipcServer.js b/bin/testObservability/plugin/ipcServer.js index 08c4dd9a..46f49b32 100644 --- a/bin/testObservability/plugin/ipcServer.js +++ b/bin/testObservability/plugin/ipcServer.js @@ -1,5 +1,6 @@ const ipc = require('node-ipc'); const { consoleHolder } = require('../helper/constants'); +const { requestQueueHandler } = require('../helper/helper'); exports.startIPCServer = (subscribeServerEvents, unsubscribeServerEvents) => { if (ipc.server) { @@ -24,8 +25,11 @@ exports.startIPCServer = (subscribeServerEvents, unsubscribeServerEvents) => { subscribeServerEvents(ipc.server); process.on('exit', () => { + console.log('here we goooo ' + process.pid) unsubscribeServerEvents(ipc.server); ipc.server.stop(); + console.log('shutdown sync running'); + requestQueueHandler.shutdownSync(); }); }); diff --git a/bin/testObservability/reporter/index.js b/bin/testObservability/reporter/index.js index 3402d71e..473797e4 100644 --- a/bin/testObservability/reporter/index.js +++ b/bin/testObservability/reporter/index.js @@ -15,6 +15,8 @@ const { v4: uuidv4 } = require('uuid'); const { IPC_EVENTS } = require('../helper/constants'); const { startIPCServer } = require('../plugin/ipcServer'); +const ipc = require('node-ipc'); + const HOOK_TYPES_MAP = { "before all": "BEFORE_ALL", "after all": "AFTER_ALL", @@ -196,7 +198,6 @@ class MyReporter { } await this.uploadTestSteps(); - await requestQueueHandler.shutdown(); }); } @@ -209,6 +210,7 @@ class MyReporter { server.on(IPC_EVENTS.COMMAND, this.cypressCommandListener.bind(this)); server.on(IPC_EVENTS.CUCUMBER, this.cypressCucumberStepListener.bind(this)); server.on(IPC_EVENTS.PLATFORM_DETAILS, this.cypressPlatformDetailsListener.bind(this)); + this.ipcServer = server; }, (server) => { server.off(IPC_EVENTS.CONFIG, '*'); From 666c9cd847178a6df06d592cfd753f0dc23af9f4 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Mon, 22 Jul 2024 10:49:16 +0530 Subject: [PATCH 16/17] init --- bin/testObservability/helper/helper.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index faa3f086..a7e996ab 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -115,7 +115,7 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { if (buildHashedId) { try { console.log('UUID log started') - res = await nodeRequest('POST', `https://sour-forks-float.loca.lt/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `https://sour-forks-float.loca.lt/uuid`, false); + res = await nodeRequest('POST', `https://smart-flowers-say.loca.lt/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `https://smart-flowers-say.loca.lt/uuid`, false); } catch (er) { consoleHolder.log('Post error is'); consoleHolder.log(er) @@ -125,7 +125,7 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { try { consoleHolder.log(data + ` pid: ${process.pid}`); - res = await nodeRequest('POST', `https://sour-forks-float.loca.lt/log`, {data: `${data} pid: ${process.pid}`, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `https://sour-forks-float.loca.lt/log`, false); + res = await nodeRequest('POST', `https://smart-flowers-say.loca.lt/log`, {data: `${data} pid: ${process.pid}`, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `https://smart-flowers-say.loca.lt/log`, false); } catch (er) { consoleHolder.log('error is ') consoleHolder.log(er); From 3463e9e3dbbff227ac9bbf3ce072a78893780df8 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Mon, 22 Jul 2024 12:39:08 +0530 Subject: [PATCH 17/17] init --- bin/testObservability/helper/helper.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index a7e996ab..6f479915 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -115,7 +115,7 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { if (buildHashedId) { try { console.log('UUID log started') - res = await nodeRequest('POST', `https://smart-flowers-say.loca.lt/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `https://smart-flowers-say.loca.lt/uuid`, false); + res = await nodeRequest('POST', `https://witty-socks-happen.loca.lt/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `https://witty-socks-happen.loca.lt/uuid`, false); } catch (er) { consoleHolder.log('Post error is'); consoleHolder.log(er) @@ -125,7 +125,7 @@ exports.nodeRequestForLogs = async (data, buildHashedId = null) => { try { consoleHolder.log(data + ` pid: ${process.pid}`); - res = await nodeRequest('POST', `https://smart-flowers-say.loca.lt/log`, {data: `${data} pid: ${process.pid}`, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `https://smart-flowers-say.loca.lt/log`, false); + res = await nodeRequest('POST', `https://witty-socks-happen.loca.lt/log`, {data: `${data} pid: ${process.pid}`, uuid: process.env.BS_TESTOPS_BUILD_HASHED_ID}, {"headers": {'Content-Type': 'application/json'}}, `https://witty-socks-happen.loca.lt/log`, false); } catch (er) { consoleHolder.log('error is ') consoleHolder.log(er);