diff options
author | Toine Siebelink <toine.siebelink@est.tech> | 2024-09-10 13:34:35 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2024-09-10 13:34:35 +0000 |
commit | c6a75c4ce6b6e041f2e91b5d4fb64cae6de6c0ab (patch) | |
tree | 072433da02203710e957117706ba31faaeb0dbaf /k6-tests/ncmp/common/utils.js | |
parent | 4e68380c9e39feb5bd479bac6138e3cd2da3edad (diff) | |
parent | 175d12da41b1257fe3be5b3e95540e99c8952f82 (diff) |
Merge "Fix high-cardinality metrics in k6, causing high memory use"
Diffstat (limited to 'k6-tests/ncmp/common/utils.js')
-rw-r--r-- | k6-tests/ncmp/common/utils.js | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/k6-tests/ncmp/common/utils.js b/k6-tests/ncmp/common/utils.js index 8391d5c3bd..e6d9c92ee6 100644 --- a/k6-tests/ncmp/common/utils.js +++ b/k6-tests/ncmp/common/utils.js @@ -18,13 +18,14 @@ * ============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']; @@ -42,6 +43,43 @@ export function makeBatchOfCmHandleIds(batchSize, batchNumber) { 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 + }); +} + +/** + * 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', |