diff options
Diffstat (limited to 'k6-tests/ncmp/common')
-rw-r--r-- | k6-tests/ncmp/common/cmhandle-crud.js | 67 | ||||
-rw-r--r-- | k6-tests/ncmp/common/passthrough-crud.js | 59 | ||||
-rw-r--r-- | k6-tests/ncmp/common/search-base.js | 48 | ||||
-rw-r--r-- | k6-tests/ncmp/common/utils.js | 62 |
4 files changed, 122 insertions, 114 deletions
diff --git a/k6-tests/ncmp/common/cmhandle-crud.js b/k6-tests/ncmp/common/cmhandle-crud.js index 88ecdb45b8..7fab62abd8 100644 --- a/k6-tests/ncmp/common/cmhandle-crud.js +++ b/k6-tests/ncmp/common/cmhandle-crud.js @@ -18,35 +18,42 @@ * ============LICENSE_END========================================================= */ -import http from 'k6/http'; -import { check, sleep } from 'k6'; -import { NCMP_BASE_URL, DMI_PLUGIN_URL, TOTAL_CM_HANDLES, MODULE_SET_TAGS, REGISTRATION_BATCH_SIZE, CONTENT_TYPE_JSON_PARAM, makeBatchOfCmHandleIds } from './utils.js'; +import { sleep } from 'k6'; +import { performPostRequest, NCMP_BASE_URL, DMI_PLUGIN_URL, TOTAL_CM_HANDLES, MODULE_SET_TAGS +} from './utils.js'; import { executeCmHandleIdSearch } from './search-base.js'; -export function registerAllCmHandles() { - forEachBatchOfCmHandles(createCmHandles); - waitForAllCmHandlesToBeReady(); +export function createCmHandles(cmHandleIds) { + const url = `${NCMP_BASE_URL}/ncmpInventory/v1/ch`; + const payload = JSON.stringify(createCmHandlePayload(cmHandleIds)); + return performPostRequest(url, payload, 'createCmHandles'); } -export function deregisterAllCmHandles() { - forEachBatchOfCmHandles(deleteCmHandles); +export function deleteCmHandles(cmHandleIds) { + const url = `${NCMP_BASE_URL}/ncmpInventory/v1/ch`; + const payload = JSON.stringify({ + "dmiPlugin": DMI_PLUGIN_URL, + "removedCmHandles": cmHandleIds, + }); + return performPostRequest(url, payload, 'deleteCmHandles'); } -function forEachBatchOfCmHandles(functionToExecute) { - const TOTAL_BATCHES = Math.ceil(TOTAL_CM_HANDLES / REGISTRATION_BATCH_SIZE); - for (let batchNumber = 0; batchNumber < TOTAL_BATCHES; batchNumber++) { - const nextBatchOfCmHandleIds = makeBatchOfCmHandleIds(REGISTRATION_BATCH_SIZE, batchNumber); - functionToExecute(nextBatchOfCmHandleIds); - } +export function waitForAllCmHandlesToBeReady() { + const POLLING_INTERVAL_SECONDS = 5; + let cmHandlesReady = 0; + do { + sleep(POLLING_INTERVAL_SECONDS); + cmHandlesReady = getNumberOfReadyCmHandles(); + console.log(`${cmHandlesReady}/${TOTAL_CM_HANDLES} CM handles are READY`); + } while (cmHandlesReady < TOTAL_CM_HANDLES); } -function createCmHandles(cmHandleIds) { - const url = `${NCMP_BASE_URL}/ncmpInventory/v1/ch`; - const payload = { +function createCmHandlePayload(cmHandleIds) { + return { "dmiPlugin": DMI_PLUGIN_URL, "createdCmHandles": cmHandleIds.map((cmHandleId, index) => ({ "cmHandle": cmHandleId, - "alternateId": `alt-${cmHandleId}`, + "alternateId": cmHandleId.replace('ch-', 'alt-'), "moduleSetTag": MODULE_SET_TAGS[index % MODULE_SET_TAGS.length], "cmHandleProperties": {"neType": "RadioNode"}, "publicCmHandleProperties": { @@ -56,30 +63,6 @@ function createCmHandles(cmHandleIds) { } })), }; - const response = http.post(url, JSON.stringify(payload), CONTENT_TYPE_JSON_PARAM); - check(response, { 'create CM-handles status equals 200': (r) => r.status === 200 }); - return response; -} - -function deleteCmHandles(cmHandleIds) { - const url = `${NCMP_BASE_URL}/ncmpInventory/v1/ch`; - const payload = { - "dmiPlugin": DMI_PLUGIN_URL, - "removedCmHandles": cmHandleIds, - }; - const response = http.post(url, JSON.stringify(payload), CONTENT_TYPE_JSON_PARAM); - check(response, { 'delete CM-handles status equals 200': (r) => r.status === 200 }); - return response; -} - -function waitForAllCmHandlesToBeReady() { - const POLLING_INTERVAL_SECONDS = 5; - let cmHandlesReady = 0; - do { - sleep(POLLING_INTERVAL_SECONDS); - cmHandlesReady = getNumberOfReadyCmHandles(); - console.log(`${cmHandlesReady}/${TOTAL_CM_HANDLES} CM handles are READY`); - } while (cmHandlesReady < TOTAL_CM_HANDLES); } function getNumberOfReadyCmHandles() { diff --git a/k6-tests/ncmp/common/passthrough-crud.js b/k6-tests/ncmp/common/passthrough-crud.js index 5617f9d093..0cd96ad64d 100644 --- a/k6-tests/ncmp/common/passthrough-crud.js +++ b/k6-tests/ncmp/common/passthrough-crud.js @@ -18,47 +18,37 @@ * ============LICENSE_END========================================================= */ -import http from 'k6/http'; +import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js'; import { - CONTENT_TYPE_JSON_PARAM, - getRandomCmHandleId, + performPostRequest, + performGetRequest, NCMP_BASE_URL, - TOPIC_DATA_OPERATIONS_BATCH_READ + TOPIC_DATA_OPERATIONS_BATCH_READ, + TOTAL_CM_HANDLES } from './utils.js'; -export function passthroughRead() { - const cmHandleId = getRandomCmHandleId(); +export function passthroughRead(useAlternateId) { + const cmHandleReference = getRandomCmHandleReference(useAlternateId); const resourceIdentifier = 'my-resource-identifier'; - const includeDescendants = true; const datastoreName = 'ncmp-datastore:passthrough-operational'; - const url = `${NCMP_BASE_URL}/ncmp/v1/ch/${cmHandleId}/data/ds/${datastoreName}?resourceIdentifier=${resourceIdentifier}&include-descendants=${includeDescendants}` - const response = http.get(url); - return response; -} - -export function passthroughReadWithAltId() { - const cmHandleId = getRandomCmHandleId(); - const resourceIdentifier = 'my-resource-identifier'; const includeDescendants = true; - const datastoreName = 'ncmp-datastore:passthrough-operational'; - const url = `${NCMP_BASE_URL}/ncmp/v1/ch/alt-${cmHandleId}/data/ds/${datastoreName}?resourceIdentifier=${resourceIdentifier}&include-descendants=${includeDescendants}` - const response = http.get(url); - return response; + const url = generatePassthroughUrl(cmHandleReference, datastoreName, resourceIdentifier, includeDescendants); + return performGetRequest(url, 'passthroughRead'); } -export function passthroughWrite() { - const cmHandleId = getRandomCmHandleId(); +export function passthroughWrite(useAlternateId) { + const cmHandleReference = getRandomCmHandleReference(useAlternateId); const resourceIdentifier = 'my-resource-identifier'; const datastoreName = 'ncmp-datastore:passthrough-running'; - const url = `${NCMP_BASE_URL}/ncmp/v1/ch/${cmHandleId}/data/ds/${datastoreName}?resourceIdentifier=${resourceIdentifier}` - const body = `{"neType": "BaseStation"}` - const response = http.post(url, JSON.stringify(body), CONTENT_TYPE_JSON_PARAM); - return response; + const includeDescendants = false; + const url = generatePassthroughUrl(cmHandleReference, datastoreName, resourceIdentifier, includeDescendants); + const payload = JSON.stringify({"neType": "BaseStation"}); + return performPostRequest(url, payload, 'passthroughWrite'); } export function batchRead(cmHandleIds) { - const url = `${NCMP_BASE_URL}/ncmp/v1/data?topic=${TOPIC_DATA_OPERATIONS_BATCH_READ}` - const payload = { + const url = `${NCMP_BASE_URL}/ncmp/v1/data?topic=${TOPIC_DATA_OPERATIONS_BATCH_READ}`; + const payload = JSON.stringify({ "operations": [ { "resourceIdentifier": "parent/child", @@ -69,7 +59,16 @@ export function batchRead(cmHandleIds) { "operation": "read" } ] - }; - const response = http.post(url, JSON.stringify(payload), CONTENT_TYPE_JSON_PARAM); - return response; + }); + return performPostRequest(url, payload, 'batchRead'); +} + +function getRandomCmHandleReference(useAlternateId) { + const prefix = useAlternateId ? 'alt' : 'ch'; + return `${prefix}-${randomIntBetween(1, TOTAL_CM_HANDLES)}`; +} + +function generatePassthroughUrl(cmHandleReference, datastoreName, resourceIdentifier, includeDescendants) { + const descendantsParam = includeDescendants ? `&include-descendants=${includeDescendants}` : ''; + return `${NCMP_BASE_URL}/ncmp/v1/ch/${cmHandleReference}/data/ds/${datastoreName}?resourceIdentifier=${resourceIdentifier}${descendantsParam}`; }
\ No newline at end of file diff --git a/k6-tests/ncmp/common/search-base.js b/k6-tests/ncmp/common/search-base.js index bc964856af..a6424fe5d0 100644 --- a/k6-tests/ncmp/common/search-base.js +++ b/k6-tests/ncmp/common/search-base.js @@ -18,27 +18,7 @@ * ============LICENSE_END========================================================= */ -import http from 'k6/http'; -import { NCMP_BASE_URL, CONTENT_TYPE_JSON_PARAM } from './utils.js'; - -const SEARCH_PARAMETERS_PER_SCENARIO = { - 'module': { - 'cmHandleQueryParameters': [ - { - 'conditionName': 'hasAllModules', - 'conditionParameters': [{'moduleName': 'ietf-yang-types-1'}] - } - ] - }, - 'readyCmHandles': { - 'cmHandleQueryParameters': [ - { - 'conditionName': 'cmHandleWithCpsPath', - 'conditionParameters': [{'cpsPath': '//state[@cm-handle-state="READY"]'}] - } - ] - } -}; +import {performPostRequest, NCMP_BASE_URL} from './utils.js'; export function executeCmHandleSearch(scenario) { return executeSearchRequest('searches', scenario); @@ -52,6 +32,28 @@ function executeSearchRequest(searchType, scenario) { const searchParameters = SEARCH_PARAMETERS_PER_SCENARIO[scenario]; const payload = JSON.stringify(searchParameters); const url = `${NCMP_BASE_URL}/ncmp/v1/ch/${searchType}`; - const response = http.post(url, payload, CONTENT_TYPE_JSON_PARAM); - return response; + return performPostRequest(url, payload, searchType); } + +const SEARCH_PARAMETERS_PER_SCENARIO = { + "module-and-properties": { + "cmHandleQueryParameters": [ + { + "conditionName": "hasAllModules", + "conditionParameters": [{"moduleName": "ietf-yang-types"}] + }, + { + "conditionName": "hasAllProperties", + "conditionParameters": [{"Color": "yellow"}] + } + ] + }, + "readyCmHandles": { + "cmHandleQueryParameters": [ + { + "conditionName": "cmHandleWithCpsPath", + "conditionParameters": [{"cpsPath": "//state[@cm-handle-state='READY']"}] + } + ] + } +}; diff --git a/k6-tests/ncmp/common/utils.js b/k6-tests/ncmp/common/utils.js index 294789f940..e6d9c92ee6 100644 --- a/k6-tests/ncmp/common/utils.js +++ b/k6-tests/ncmp/common/utils.js @@ -18,25 +18,19 @@ * ============LICENSE_END========================================================= */ +import http from 'k6/http'; export const NCMP_BASE_URL = 'http://localhost:8883'; export const DMI_PLUGIN_URL = 'http://ncmp-dmi-plugin-demo-and-csit-stub:8092'; export const TOTAL_CM_HANDLES = 20000; export const REGISTRATION_BATCH_SIZE = 100; export const READ_DATA_FOR_CM_HANDLE_DELAY_MS = 300; // must have same value as in docker-compose.yml export const WRITE_DATA_FOR_CM_HANDLE_DELAY_MS = 670; // must have same value as in docker-compose.yml -export const CONTENT_TYPE_JSON_PARAM = { headers: {'Content-Type': 'application/json'} }; +export const CONTENT_TYPE_JSON_PARAM = {'Content-Type': 'application/json'}; export const DATA_OPERATION_READ_BATCH_SIZE = 200; export const TOPIC_DATA_OPERATIONS_BATCH_READ = 'topic-data-operations-batch-read'; export const KAFKA_BOOTSTRAP_SERVERS = ['localhost:9092']; export const MODULE_SET_TAGS = ['tagA','tagB','tagC',' tagD'] -export function recordTimeInSeconds(functionToExecute) { - const startTimeInMillis = Date.now(); - functionToExecute(); - const endTimeInMillis = Date.now(); - const totalTimeInSeconds = (endTimeInMillis - startTimeInMillis) / 1000.0; - return totalTimeInSeconds; -} /** * Generates a batch of CM-handle IDs based on batch size and number. @@ -45,29 +39,59 @@ export function recordTimeInSeconds(functionToExecute) { * @returns {string[]} Array of CM-handle IDs, for example ['ch-201', 'ch-202' ... 'ch-300'] */ export function makeBatchOfCmHandleIds(batchSize, batchNumber) { - const batchOfIds = []; const startIndex = 1 + batchNumber * batchSize; - for (let i = 0; i < batchSize; i++) { - let cmHandleId = `ch-${startIndex + i}`; - batchOfIds.push(cmHandleId); - } - return batchOfIds; + return Array.from({ length: batchSize }, (_, i) => `ch-${startIndex + i}`); +} + +/** + * Helper function to perform POST requests with JSON payload and content type. + * @param {string} url - The URL to send the POST request to. + * @param {Object} payload - The JSON payload to send in the POST request. + * @param {string} metricTag - A tag for the metric endpoint. + * @returns {Object} The response from the HTTP POST request. + */ +export function performPostRequest(url, payload, metricTag) { + const metricTags = { + endpoint: metricTag + }; + + return http.post(url, payload, { + headers: CONTENT_TYPE_JSON_PARAM, + tags: metricTags + }); } -export function getRandomCmHandleId() { - return `ch-${Math.floor(Math.random() * TOTAL_CM_HANDLES) + 1}`; +/** + * Helper function to perform GET requests with metric tags. + * + * This function sends an HTTP GET request to the specified URL and attaches + * a metric tag to the request, which is useful for monitoring and analytics. + * + * @param {string} url - The URL to which the GET request will be sent. + * @param {string} metricTag - A string representing the metric tag to associate with the request. + * This tag is used for monitoring and tracking the request. + * @returns {Object} The response from the HTTP GET request. The response includes the status code, + * headers, body, and other related information. + */ +export function performGetRequest(url, metricTag) { + const metricTags = { + endpoint: metricTag + }; + return http.get(url, {tags: metricTags}); } export function makeCustomSummaryReport(data, options) { const summaryCsvLines = [ '#,Test Name,Unit,Limit,Actual', + makeSummaryCsvLine('0', 'HTTP request failures for all tests', 'rate of failed requests', 'http_req_failed', data, options), makeSummaryCsvLine('1', 'Registration of CM-handles', 'CM-handles/second', 'cmhandles_created_per_second', data, options), makeSummaryCsvLine('2', 'De-registration of CM-handles', 'CM-handles/second', 'cmhandles_deleted_per_second', data, options), - makeSummaryCsvLine('3', 'CM-handle ID search with Module filter', 'milliseconds', 'http_req_duration{scenario:id_search_module}', data, options), - makeSummaryCsvLine('4', 'CM-handle search with Module filter', 'milliseconds', 'http_req_duration{scenario:cm_search_module}', data, options), + makeSummaryCsvLine('3', 'CM-handle ID search with Module and Property filter', 'milliseconds', 'id_search_duration', data, options), + makeSummaryCsvLine('4', 'CM-handle search with Module and Property filter', 'milliseconds', 'cm_search_duration', data, options), makeSummaryCsvLine('5a', 'NCMP overhead for Synchronous single CM-handle pass-through read', 'milliseconds', 'ncmp_overhead_passthrough_read', data, options), makeSummaryCsvLine('5b', 'NCMP overhead for Synchronous single CM-handle pass-through read with alternate id', 'milliseconds', 'ncmp_overhead_passthrough_read_alt_id', data, options), - makeSummaryCsvLine('6', 'NCMP overhead for Synchronous single CM-handle pass-through write', 'milliseconds', 'ncmp_overhead_passthrough_write', data, options), + makeSummaryCsvLine('6a', 'NCMP overhead for Synchronous single CM-handle pass-through write', 'milliseconds', 'ncmp_overhead_passthrough_write', data, options), + makeSummaryCsvLine('6b', 'NCMP overhead for Synchronous single CM-handle pass-through write with alternate id', 'milliseconds', 'ncmp_overhead_passthrough_write_alt_id', data, options), makeSummaryCsvLine('7', 'Data operations batch read', 'events/second', 'data_operations_batch_read_cmhandles_per_second', data, options), ]; return summaryCsvLines.join('\n') + '\n'; |