Skip to content
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

Impl spec counter #323

Merged
merged 8 commits into from
Dec 17, 2024
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
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions src/scripts/hooks/onComplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
21 changes: 18 additions & 3 deletions src/scripts/hooks/onPrepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ export default async function (config: any, capabilities: Array<object>, 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);
}
Expand All @@ -32,9 +34,22 @@ export default async function (config: any, capabilities: Array<object>, 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();
};
}

function countNestedArrayElements(arr: any[]): number {
let count = 0;

for (const element of arr) {
if (Array.isArray(element)) {
count += countNestedArrayElements(element);
} else {
count++;
}
}

return count;
}
2 changes: 1 addition & 1 deletion src/scripts/stats/createUsage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export async function createUsage(usageData: {
environment: string[];
configHash: string;
repoHash: string | null;
specCounter: number;
}): Promise<string | null> {
const urlUsage = "https://stats.qmate.proc.only.sap/api/usage/qmate";
try {
Expand All @@ -21,7 +22,6 @@ export async function createUsage(usageData: {
dispatcher: new Agent({
connect: {
rejectUnauthorized: false,
// ca: process.env.SAP_GLOBAL_ROOT_CA
}
})
});
Expand Down
1 change: 0 additions & 1 deletion src/scripts/stats/getUserId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export async function getUserId(): Promise<string | null> {
dispatcher: new Agent({
connect: {
rejectUnauthorized: false,
// ca: process.env.SAP_GLOBAL_ROOT_CA
}
})
});
Expand Down
7 changes: 4 additions & 3 deletions src/scripts/stats/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getUserId } from './getUserId';
import { getVersion } from './getVersion';
import { updateQmateUsage } from './updateUsage';

export async function sendUsageRequests(): Promise<string | null> {
export async function sendUsageRequests(specCounter: number): Promise<string | null> {
const user = await getUserId();
if (user === null) {
return null;
Expand All @@ -22,6 +22,7 @@ export async function sendUsageRequests(): Promise<string | null> {
"environment": getEnvironmentVariables(),
"configHash": getConfigurationHash(),
"repoHash": getCwdGitRemoteUrlHash(),
"specCounter": specCounter,
};

const usageId = await createUsage(usageData);
Expand All @@ -33,10 +34,10 @@ export async function sendUsageRequests(): Promise<string | null> {

export async function updateUsageRequests(usageId: string, result: string) {
const usageData = {
"result": result
result
}

updateQmateUsage(usageId, usageData);
void updateQmateUsage(usageId, usageData);
}


3 changes: 1 addition & 2 deletions src/scripts/stats/updateUsage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
})
});
Expand All @@ -21,6 +20,6 @@ export async function updateQmateUsage(id: string, usageData: { result: string }
// Intentionally ignore
}
} catch (error) {
// Intentionally ignore
// Intentionally ignore
}
}
Loading