blob: 4bf066c840c7fd9542a9c64270956c8a6c1b6882 [file] [log] [blame]
danielhanrahanc0b6f3a2024-04-29 16:16:42 +01001/*
2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2024 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
19 */
20
21export const NCMP_BASE_URL = 'http://localhost:8883';
22export const DMI_PLUGIN_URL = 'http://ncmp-dmi-plugin-demo-and-csit-stub:8092';
danielhanrahan4e9f68c2024-06-28 13:43:35 +010023export const TOTAL_CM_HANDLES = 20000;
24export const REGISTRATION_BATCH_SIZE = 100;
25export const CONTENT_TYPE_JSON_PARAM = { headers: {'Content-Type': 'application/json'} };
26
27export function recordTimeInSeconds(functionToExecute) {
28 const startTimeInMillis = Date.now();
29 functionToExecute();
30 const endTimeInMillis = Date.now();
31 const totalTimeInSeconds = (endTimeInMillis - startTimeInMillis) / 1000.0;
32 return totalTimeInSeconds;
33}
danielhanrahanc0b6f3a2024-04-29 16:16:42 +010034
danielhanrahanf66694a2024-06-10 21:32:12 +010035/**
36 * Generates a batch of CM-handle IDs based on batch size and number.
37 * @param {number} batchSize - Size of each batch.
38 * @param {number} batchNumber - Number of the batch.
39 * @returns {string[]} Array of CM-handle IDs, for example ['ch-201', 'ch-202' ... 'ch-300']
danielhanrahanc0b6f3a2024-04-29 16:16:42 +010040 */
41export function makeBatchOfCmHandleIds(batchSize, batchNumber) {
42 const batchOfIds = [];
43 const startIndex = 1 + batchNumber * batchSize;
44 for (let i = 0; i < batchSize; i++) {
danielhanrahan4e9f68c2024-06-28 13:43:35 +010045 let cmHandleId = `ch-${startIndex + i}`;
danielhanrahanc0b6f3a2024-04-29 16:16:42 +010046 batchOfIds.push(cmHandleId);
47 }
48 return batchOfIds;
49}
50
51export function getRandomCmHandleId() {
danielhanrahanf66694a2024-06-10 21:32:12 +010052 return `ch-${Math.floor(Math.random() * TOTAL_CM_HANDLES) + 1}`;
danielhanrahanc0b6f3a2024-04-29 16:16:42 +010053}
halil.cakal0613fbd2024-05-27 16:06:59 +010054
halil.cakal0613fbd2024-05-27 16:06:59 +010055export function makeCustomSummaryReport(data, options) {
danielhanrahan4e9f68c2024-06-28 13:43:35 +010056 let summaryCsv = '#,Test Name,Unit,Limit,Actual\n';
57 summaryCsv += makeSummaryCsvLine(1, 'Registration of CM-handles', 'CM-handles/second', 'cmhandles_created_per_second', data, options);
58 summaryCsv += makeSummaryCsvLine(2, 'De-registration of CM-handles', 'CM-handles/second', 'cmhandles_deleted_per_second', data, options);
59 summaryCsv += makeSummaryCsvLine(3, 'CM-handle ID search with Module filter', 'milliseconds', 'http_req_duration{scenario:id_search_module}', data, options);
60 summaryCsv += makeSummaryCsvLine(4, 'CM-handle search with Module filter', 'milliseconds', 'http_req_duration{scenario:cm_search_module}', data, options);
halil.cakal90464762024-07-09 17:43:25 +010061 summaryCsv += makeSummaryCsvLine(5, 'Synchronous single CM-handle pass-through read', 'requests/second', 'http_reqs{scenario:passthrough_read}', data, options);
halil.cakalfcc81ee2024-07-11 14:54:57 +010062 summaryCsv += makeSummaryCsvLine(6, 'Synchronous single CM-handle pass-through write', 'requests/second', 'http_reqs{scenario:passthrough_write}', data, options);
danielhanrahan4e9f68c2024-06-28 13:43:35 +010063 return summaryCsv;
halil.cakal0613fbd2024-05-27 16:06:59 +010064}
65
danielhanrahan4e9f68c2024-06-28 13:43:35 +010066function makeSummaryCsvLine(testCase, testName, unit, thresholdInK6, data, options) {
67 const thresholdArray = JSON.parse(JSON.stringify(options.thresholds[thresholdInK6]));
68 const thresholdString = thresholdArray[0];
69 const [thresholdKey, thresholdOperator, thresholdValue] = thresholdString.split(/\s+/);
70 const actualValue = data.metrics[thresholdInK6].values[thresholdKey].toFixed(3);
71 return `${testCase},${testName},${unit},${thresholdValue},${actualValue}\n`;
72}