diff --git a/src/index.ts b/src/index.ts index d073f703..56b9ac9a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,7 +11,9 @@ const pj = require("../package.json"); module.exports = class CustomWorkerService { private _statsUsageId: string | null = null; - config: any; + + public config: any; + /** * `serviceOptions` contains all options specific to the service * e.g. if defined as follows: diff --git a/src/scripts/hooks/onComplete.ts b/src/scripts/hooks/onComplete.ts index 2b5eed97..661bc03b 100644 --- a/src/scripts/hooks/onComplete.ts +++ b/src/scripts/hooks/onComplete.ts @@ -12,12 +12,11 @@ import { updateUsageRequests } from "../stats/stats"; export default async function (exitCode: any, config: any, capabilities: any, results: any, statsUsageId: string | null) { await dataExchangeCommands.writeExportData(); - if (statsUsageId !== null) { if (config.params && config.params.qmateStatsOptions) { if (!config.params.qmateStatsOptions.optOut) { - if (exitCode === 0){ - updateUsageRequests(statsUsageId, 'success'); + if (exitCode === 0) { + updateUsageRequests(statsUsageId, 'success'); } else if (exitCode === 1) { updateUsageRequests(statsUsageId, 'fail'); } diff --git a/src/scripts/hooks/onPrepare.ts b/src/scripts/hooks/onPrepare.ts index 691e5fc9..61eadaeb 100644 --- a/src/scripts/hooks/onPrepare.ts +++ b/src/scripts/hooks/onPrepare.ts @@ -13,11 +13,13 @@ export default async function (config: any, capabilities: Array, callbac process.env.CONFIG_PATH = path.dirname(config._[0]); } + const specCounter = config.specs ? countNestedArrayElements(config.specs) : 0; + // Send usage requests if (config.params && config.params.qmateStatsOptions) { if (!config.params.qmateStatsOptions.optOut) { try { - sendUsageRequests().then((res) => { + sendUsageRequests(specCounter).then((res) => { if (res != null) { callbackStatsUsageId(res); } @@ -32,9 +34,22 @@ export default async function (config: any, capabilities: Array, callbac if (config.params && config.params.qmateCustomTimeout) { process.env.QMATE_CUSTOM_TIMEOUT = config.params.qmateCustomTimeout; process.env.LOAD_PROPERTY_TIMEOUT = config.params.loadPropertyTimeout; - } // Create a temporary data folder await dataExchangeCommands.createTmpDataFolder(); -}; \ No newline at end of file +} + +function countNestedArrayElements(arr: any[]): number { + let count = 0; + + for (const element of arr) { + if (Array.isArray(element)) { + count += countNestedArrayElements(element); + } else { + count++; + } + } + + return count; +} diff --git a/src/scripts/stats/createUsage.ts b/src/scripts/stats/createUsage.ts index e8d6cc42..e59925d8 100644 --- a/src/scripts/stats/createUsage.ts +++ b/src/scripts/stats/createUsage.ts @@ -9,6 +9,7 @@ export async function createUsage(usageData: { environment: string[]; configHash: string; repoHash: string | null; + specCounter: number; }): Promise { const urlUsage = "https://stats.qmate.proc.only.sap/api/usage/qmate"; try { @@ -21,7 +22,6 @@ export async function createUsage(usageData: { dispatcher: new Agent({ connect: { rejectUnauthorized: false, - // ca: process.env.SAP_GLOBAL_ROOT_CA } }) }); diff --git a/src/scripts/stats/getUserId.ts b/src/scripts/stats/getUserId.ts index 52dccea0..d598d4a0 100644 --- a/src/scripts/stats/getUserId.ts +++ b/src/scripts/stats/getUserId.ts @@ -16,7 +16,6 @@ export async function getUserId(): Promise { dispatcher: new Agent({ connect: { rejectUnauthorized: false, - // ca: process.env.SAP_GLOBAL_ROOT_CA } }) }); diff --git a/src/scripts/stats/stats.ts b/src/scripts/stats/stats.ts index b4145665..a557b888 100644 --- a/src/scripts/stats/stats.ts +++ b/src/scripts/stats/stats.ts @@ -7,7 +7,7 @@ import { getUserId } from './getUserId'; import { getVersion } from './getVersion'; import { updateQmateUsage } from './updateUsage'; -export async function sendUsageRequests(): Promise { +export async function sendUsageRequests(specCounter: number): Promise { const user = await getUserId(); if (user === null) { return null; @@ -22,6 +22,7 @@ export async function sendUsageRequests(): Promise { "environment": getEnvironmentVariables(), "configHash": getConfigurationHash(), "repoHash": getCwdGitRemoteUrlHash(), + "specCounter": specCounter, }; const usageId = await createUsage(usageData); @@ -33,10 +34,10 @@ export async function sendUsageRequests(): Promise { export async function updateUsageRequests(usageId: string, result: string) { const usageData = { - "result": result + result } - updateQmateUsage(usageId, usageData); + void updateQmateUsage(usageId, usageData); } diff --git a/src/scripts/stats/updateUsage.ts b/src/scripts/stats/updateUsage.ts index e81b5220..cf14b888 100644 --- a/src/scripts/stats/updateUsage.ts +++ b/src/scripts/stats/updateUsage.ts @@ -12,7 +12,6 @@ export async function updateQmateUsage(id: string, usageData: { result: string } dispatcher: new Agent({ connect: { rejectUnauthorized: false, - // ca: process.env.SAP_GLOBAL_ROOT_CA } }) }); @@ -21,6 +20,6 @@ export async function updateQmateUsage(id: string, usageData: { result: string } // Intentionally ignore } } catch (error) { - // Intentionally ignore + // Intentionally ignore } } \ No newline at end of file