blob: 5d1905646d822e7f8eb70e5444deee08b63f3292 [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
sourabh_sourabh175d12d2024-08-30 16:25:04 +010021import http from 'k6/http';
danielhanrahanc0b6f3a2024-04-29 16:16:42 +010022export const NCMP_BASE_URL = 'http://localhost:8883';
23export const DMI_PLUGIN_URL = 'http://ncmp-dmi-plugin-demo-and-csit-stub:8092';
danielhanrahan4e9f68c2024-06-28 13:43:35 +010024export const TOTAL_CM_HANDLES = 20000;
25export const REGISTRATION_BATCH_SIZE = 100;
danielhanrahandbe7b662024-07-16 11:47:24 +010026export const READ_DATA_FOR_CM_HANDLE_DELAY_MS = 300; // must have same value as in docker-compose.yml
27export const WRITE_DATA_FOR_CM_HANDLE_DELAY_MS = 670; // must have same value as in docker-compose.yml
sourabh_sourabh175d12d2024-08-30 16:25:04 +010028export const CONTENT_TYPE_JSON_PARAM = {'Content-Type': 'application/json'};
halil.cakalfc499102024-08-28 10:19:26 +010029export const LEGACY_BATCH_THROUGHPUT_TEST_BATCH_SIZE = 200;
30export const LEGACY_BATCH_THROUGHPUT_TEST_NUMBER_OF_REQUESTS = 1000;
31export const LEGACY_BATCH_TOPIC_NAME = 'legacy_batch_topic';
halil.cakal65b870b2024-07-25 11:12:29 +010032export const KAFKA_BOOTSTRAP_SERVERS = ['localhost:9092'];
emacleef11aad92024-08-14 14:25:33 +010033export const MODULE_SET_TAGS = ['tagA','tagB','tagC',' tagD']
danielhanrahan4e9f68c2024-06-28 13:43:35 +010034
danielhanrahanc0b6f3a2024-04-29 16:16:42 +010035
danielhanrahanf66694a2024-06-10 21:32:12 +010036/**
37 * Generates a batch of CM-handle IDs based on batch size and number.
38 * @param {number} batchSize - Size of each batch.
39 * @param {number} batchNumber - Number of the batch.
40 * @returns {string[]} Array of CM-handle IDs, for example ['ch-201', 'ch-202' ... 'ch-300']
danielhanrahanc0b6f3a2024-04-29 16:16:42 +010041 */
42export function makeBatchOfCmHandleIds(batchSize, batchNumber) {
danielhanrahanc0b6f3a2024-04-29 16:16:42 +010043 const startIndex = 1 + batchNumber * batchSize;
danielhanrahanf2e1e252024-08-25 21:35:19 +010044 return Array.from({ length: batchSize }, (_, i) => `ch-${startIndex + i}`);
danielhanrahanc0b6f3a2024-04-29 16:16:42 +010045}
halil.cakal0613fbd2024-05-27 16:06:59 +010046
sourabh_sourabh175d12d2024-08-30 16:25:04 +010047/**
48 * Helper function to perform POST requests with JSON payload and content type.
49 * @param {string} url - The URL to send the POST request to.
50 * @param {Object} payload - The JSON payload to send in the POST request.
51 * @param {string} metricTag - A tag for the metric endpoint.
52 * @returns {Object} The response from the HTTP POST request.
53 */
54export function performPostRequest(url, payload, metricTag) {
55 const metricTags = {
56 endpoint: metricTag
57 };
58
59 return http.post(url, payload, {
60 headers: CONTENT_TYPE_JSON_PARAM,
61 tags: metricTags
62 });
63}
64
65/**
66 * Helper function to perform GET requests with metric tags.
67 *
68 * This function sends an HTTP GET request to the specified URL and attaches
69 * a metric tag to the request, which is useful for monitoring and analytics.
70 *
71 * @param {string} url - The URL to which the GET request will be sent.
72 * @param {string} metricTag - A string representing the metric tag to associate with the request.
73 * This tag is used for monitoring and tracking the request.
74 * @returns {Object} The response from the HTTP GET request. The response includes the status code,
75 * headers, body, and other related information.
76 */
77export function performGetRequest(url, metricTag) {
78 const metricTags = {
79 endpoint: metricTag
80 };
81 return http.get(url, {tags: metricTags});
82}
83
halil.cakal0613fbd2024-05-27 16:06:59 +010084export function makeCustomSummaryReport(data, options) {
danielhanrahandbe7b662024-07-16 11:47:24 +010085 const summaryCsvLines = [
86 '#,Test Name,Unit,Limit,Actual',
danielhanrahan4cb62392024-08-27 17:57:26 +010087 makeSummaryCsvLine('0', 'HTTP request failures for all tests', 'rate of failed requests', 'http_req_failed', data, options),
danielhanrahandbe7b662024-07-16 11:47:24 +010088 makeSummaryCsvLine('1', 'Registration of CM-handles', 'CM-handles/second', 'cmhandles_created_per_second', data, options),
89 makeSummaryCsvLine('2', 'De-registration of CM-handles', 'CM-handles/second', 'cmhandles_deleted_per_second', data, options),
danielhanrahan406a7422024-09-05 12:06:30 +010090 makeSummaryCsvLine('3', 'CM-handle ID search with Module and Property filter', 'milliseconds', 'id_search_duration', data, options),
91 makeSummaryCsvLine('4', 'CM-handle search with Module and Property filter', 'milliseconds', 'cm_search_duration', data, options),
danielhanrahana1cdf732024-08-16 11:09:25 +010092 makeSummaryCsvLine('5a', 'NCMP overhead for Synchronous single CM-handle pass-through read', 'milliseconds', 'ncmp_overhead_passthrough_read', data, options),
93 makeSummaryCsvLine('5b', 'NCMP overhead for Synchronous single CM-handle pass-through read with alternate id', 'milliseconds', 'ncmp_overhead_passthrough_read_alt_id', data, options),
danielhanrahanf2e1e252024-08-25 21:35:19 +010094 makeSummaryCsvLine('6a', 'NCMP overhead for Synchronous single CM-handle pass-through write', 'milliseconds', 'ncmp_overhead_passthrough_write', data, options),
95 makeSummaryCsvLine('6b', 'NCMP overhead for Synchronous single CM-handle pass-through write with alternate id', 'milliseconds', 'ncmp_overhead_passthrough_write_alt_id', data, options),
halil.cakalfc499102024-08-28 10:19:26 +010096 makeSummaryCsvLine('7', 'Legacy batch read operation', 'events/second', 'legacy_batch_read_cmhandles_per_second', data, options),
danielhanrahandbe7b662024-07-16 11:47:24 +010097 ];
98 return summaryCsvLines.join('\n') + '\n';
halil.cakal0613fbd2024-05-27 16:06:59 +010099}
100
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100101function makeSummaryCsvLine(testCase, testName, unit, thresholdInK6, data, options) {
102 const thresholdArray = JSON.parse(JSON.stringify(options.thresholds[thresholdInK6]));
103 const thresholdString = thresholdArray[0];
104 const [thresholdKey, thresholdOperator, thresholdValue] = thresholdString.split(/\s+/);
105 const actualValue = data.metrics[thresholdInK6].values[thresholdKey].toFixed(3);
danielhanrahandbe7b662024-07-16 11:47:24 +0100106 return `${testCase},${testName},${unit},${thresholdValue},${actualValue}`;
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100107}