danielhanrahan | c0b6f3a | 2024-04-29 16:16:42 +0100 | [diff] [blame] | 1 | /* |
| 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_sourabh | 175d12d | 2024-08-30 16:25:04 +0100 | [diff] [blame] | 21 | import http from 'k6/http'; |
danielhanrahan | c0b6f3a | 2024-04-29 16:16:42 +0100 | [diff] [blame] | 22 | export const NCMP_BASE_URL = 'http://localhost:8883'; |
| 23 | export const DMI_PLUGIN_URL = 'http://ncmp-dmi-plugin-demo-and-csit-stub:8092'; |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 24 | export const TOTAL_CM_HANDLES = 20000; |
| 25 | export const REGISTRATION_BATCH_SIZE = 100; |
danielhanrahan | dbe7b66 | 2024-07-16 11:47:24 +0100 | [diff] [blame] | 26 | export const READ_DATA_FOR_CM_HANDLE_DELAY_MS = 300; // must have same value as in docker-compose.yml |
| 27 | export const WRITE_DATA_FOR_CM_HANDLE_DELAY_MS = 670; // must have same value as in docker-compose.yml |
sourabh_sourabh | 175d12d | 2024-08-30 16:25:04 +0100 | [diff] [blame] | 28 | export const CONTENT_TYPE_JSON_PARAM = {'Content-Type': 'application/json'}; |
halil.cakal | 65b870b | 2024-07-25 11:12:29 +0100 | [diff] [blame] | 29 | export const DATA_OPERATION_READ_BATCH_SIZE = 200; |
| 30 | export const TOPIC_DATA_OPERATIONS_BATCH_READ = 'topic-data-operations-batch-read'; |
| 31 | export const KAFKA_BOOTSTRAP_SERVERS = ['localhost:9092']; |
emaclee | f11aad9 | 2024-08-14 14:25:33 +0100 | [diff] [blame] | 32 | export const MODULE_SET_TAGS = ['tagA','tagB','tagC',' tagD'] |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 33 | |
danielhanrahan | c0b6f3a | 2024-04-29 16:16:42 +0100 | [diff] [blame] | 34 | |
danielhanrahan | f66694a | 2024-06-10 21:32:12 +0100 | [diff] [blame] | 35 | /** |
| 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'] |
danielhanrahan | c0b6f3a | 2024-04-29 16:16:42 +0100 | [diff] [blame] | 40 | */ |
| 41 | export function makeBatchOfCmHandleIds(batchSize, batchNumber) { |
danielhanrahan | c0b6f3a | 2024-04-29 16:16:42 +0100 | [diff] [blame] | 42 | const startIndex = 1 + batchNumber * batchSize; |
danielhanrahan | f2e1e25 | 2024-08-25 21:35:19 +0100 | [diff] [blame] | 43 | return Array.from({ length: batchSize }, (_, i) => `ch-${startIndex + i}`); |
danielhanrahan | c0b6f3a | 2024-04-29 16:16:42 +0100 | [diff] [blame] | 44 | } |
halil.cakal | 0613fbd | 2024-05-27 16:06:59 +0100 | [diff] [blame] | 45 | |
sourabh_sourabh | 175d12d | 2024-08-30 16:25:04 +0100 | [diff] [blame] | 46 | /** |
| 47 | * Helper function to perform POST requests with JSON payload and content type. |
| 48 | * @param {string} url - The URL to send the POST request to. |
| 49 | * @param {Object} payload - The JSON payload to send in the POST request. |
| 50 | * @param {string} metricTag - A tag for the metric endpoint. |
| 51 | * @returns {Object} The response from the HTTP POST request. |
| 52 | */ |
| 53 | export function performPostRequest(url, payload, metricTag) { |
| 54 | const metricTags = { |
| 55 | endpoint: metricTag |
| 56 | }; |
| 57 | |
| 58 | return http.post(url, payload, { |
| 59 | headers: CONTENT_TYPE_JSON_PARAM, |
| 60 | tags: metricTags |
| 61 | }); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Helper function to perform GET requests with metric tags. |
| 66 | * |
| 67 | * This function sends an HTTP GET request to the specified URL and attaches |
| 68 | * a metric tag to the request, which is useful for monitoring and analytics. |
| 69 | * |
| 70 | * @param {string} url - The URL to which the GET request will be sent. |
| 71 | * @param {string} metricTag - A string representing the metric tag to associate with the request. |
| 72 | * This tag is used for monitoring and tracking the request. |
| 73 | * @returns {Object} The response from the HTTP GET request. The response includes the status code, |
| 74 | * headers, body, and other related information. |
| 75 | */ |
| 76 | export function performGetRequest(url, metricTag) { |
| 77 | const metricTags = { |
| 78 | endpoint: metricTag |
| 79 | }; |
| 80 | return http.get(url, {tags: metricTags}); |
| 81 | } |
| 82 | |
halil.cakal | 0613fbd | 2024-05-27 16:06:59 +0100 | [diff] [blame] | 83 | export function makeCustomSummaryReport(data, options) { |
danielhanrahan | dbe7b66 | 2024-07-16 11:47:24 +0100 | [diff] [blame] | 84 | const summaryCsvLines = [ |
| 85 | '#,Test Name,Unit,Limit,Actual', |
danielhanrahan | 4cb6239 | 2024-08-27 17:57:26 +0100 | [diff] [blame] | 86 | makeSummaryCsvLine('0', 'HTTP request failures for all tests', 'rate of failed requests', 'http_req_failed', data, options), |
danielhanrahan | dbe7b66 | 2024-07-16 11:47:24 +0100 | [diff] [blame] | 87 | makeSummaryCsvLine('1', 'Registration of CM-handles', 'CM-handles/second', 'cmhandles_created_per_second', data, options), |
| 88 | makeSummaryCsvLine('2', 'De-registration of CM-handles', 'CM-handles/second', 'cmhandles_deleted_per_second', data, options), |
danielhanrahan | 406a742 | 2024-09-05 12:06:30 +0100 | [diff] [blame] | 89 | makeSummaryCsvLine('3', 'CM-handle ID search with Module and Property filter', 'milliseconds', 'id_search_duration', data, options), |
| 90 | makeSummaryCsvLine('4', 'CM-handle search with Module and Property filter', 'milliseconds', 'cm_search_duration', data, options), |
danielhanrahan | a1cdf73 | 2024-08-16 11:09:25 +0100 | [diff] [blame] | 91 | makeSummaryCsvLine('5a', 'NCMP overhead for Synchronous single CM-handle pass-through read', 'milliseconds', 'ncmp_overhead_passthrough_read', data, options), |
| 92 | makeSummaryCsvLine('5b', 'NCMP overhead for Synchronous single CM-handle pass-through read with alternate id', 'milliseconds', 'ncmp_overhead_passthrough_read_alt_id', data, options), |
danielhanrahan | f2e1e25 | 2024-08-25 21:35:19 +0100 | [diff] [blame] | 93 | makeSummaryCsvLine('6a', 'NCMP overhead for Synchronous single CM-handle pass-through write', 'milliseconds', 'ncmp_overhead_passthrough_write', data, options), |
| 94 | 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.cakal | 65b870b | 2024-07-25 11:12:29 +0100 | [diff] [blame] | 95 | makeSummaryCsvLine('7', 'Data operations batch read', 'events/second', 'data_operations_batch_read_cmhandles_per_second', data, options), |
danielhanrahan | dbe7b66 | 2024-07-16 11:47:24 +0100 | [diff] [blame] | 96 | ]; |
| 97 | return summaryCsvLines.join('\n') + '\n'; |
halil.cakal | 0613fbd | 2024-05-27 16:06:59 +0100 | [diff] [blame] | 98 | } |
| 99 | |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 100 | function makeSummaryCsvLine(testCase, testName, unit, thresholdInK6, data, options) { |
| 101 | const thresholdArray = JSON.parse(JSON.stringify(options.thresholds[thresholdInK6])); |
| 102 | const thresholdString = thresholdArray[0]; |
| 103 | const [thresholdKey, thresholdOperator, thresholdValue] = thresholdString.split(/\s+/); |
| 104 | const actualValue = data.metrics[thresholdInK6].values[thresholdKey].toFixed(3); |
danielhanrahan | dbe7b66 | 2024-07-16 11:47:24 +0100 | [diff] [blame] | 105 | return `${testCase},${testName},${unit},${thresholdValue},${actualValue}`; |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 106 | } |