Use alternate IDs for Legacy Batch Read operation 44/140644/2
authorhalil.cakal <halil.cakal@est.tech>
Wed, 2 Apr 2025 09:49:07 +0000 (10:49 +0100)
committerhalil.cakal <halil.cakal@est.tech>
Thu, 3 Apr 2025 09:03:27 +0000 (10:03 +0100)
- generate a random set of alternate ids out of 50K
- each alternate id is unique in the batches
- this is for both kpi and endurance pipelines

Issue-ID: CPS-2417

Change-Id: Id848593d472fa1df677ded301948e526e193aa5a
Signed-off-by: halil.cakal <halil.cakal@est.tech>
k6-tests/ncmp/common/passthrough-crud.js
k6-tests/ncmp/common/utils.js
k6-tests/ncmp/ncmp-test-runner.js

index eed1ab5..c673257 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  ============LICENSE_START=======================================================
- *  Copyright (C) 2024 Nordix Foundation
+ *  Copyright (C) 2024-2025 OpenInfra Foundation Europe. All rights reserved.
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
  *  ============LICENSE_END=========================================================
  */
 
-import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js';
 import {
     performPostRequest,
     performGetRequest,
     NCMP_BASE_URL,
     LEGACY_BATCH_TOPIC_NAME,
-    TOTAL_CM_HANDLES,
+    getRandomCmHandleReference,
 } from './utils.js';
 
 export function passthroughRead(useAlternateId) {
@@ -66,11 +65,6 @@ export function legacyBatchRead(cmHandleIds) {
     return performPostRequest(url, payload, 'batchRead');
 }
 
-function getRandomCmHandleReference(useAlternateId) {
-    const prefix = useAlternateId ? 'Region=NorthAmerica,Segment=' : '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}`;
index 36ce6b4..ea77aae 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  ============LICENSE_START=======================================================
- *  Copyright (C) 2024-2025 Nordix Foundation
+ *  Copyright (C) 2024-2025 OpenInfra Foundation Europe. All rights reserved.
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
  *  ============LICENSE_END=========================================================
  */
 
+import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js';
 import http from 'k6/http';
 
 export const testConfig = JSON.parse(open(`../config/${__ENV.TEST_PROFILE}.json`));
@@ -48,16 +49,29 @@ export function makeBatchOfCmHandleIds(batchSize, batchNumber) {
 }
 
 /**
- * Generates an unordered batch of CM-handle IDs based on batch size.
- * @returns {string[]} Array of CM-handle IDs, for example ['ch-8', 'ch-2' ... 'ch-32432']
+ * Generates an unordered batch of Alternate IDs.
+ * The batch size is determined by `LEGACY_BATCH_THROUGHPUT_TEST_BATCH_SIZE`,
+ * and the IDs are generated within the range of `TOTAL_CM_HANDLES`.
+ *
+ * @returns {string[]} Array of Alternate IDs, for example,
+ * ['Region=NorthAmerica,Segment=8', 'Region=NorthAmerica,Segment=2' ... 'Region=NorthAmerica,Segment=32432']
  */
-export function makeRandomBatchOfCmHandleIds() {
-    const cmHandleIds = new Set();
-    while (cmHandleIds.size < LEGACY_BATCH_THROUGHPUT_TEST_BATCH_SIZE) {
-        const randomNum = Math.floor(Math.random() * TOTAL_CM_HANDLES) + 1;
-        cmHandleIds.add('ch-' + randomNum);
+export function makeRandomBatchOfAlternateIds() {
+    const alternateIds = new Set();
+    while (alternateIds.size < LEGACY_BATCH_THROUGHPUT_TEST_BATCH_SIZE) {
+        alternateIds.add(getRandomCmHandleReference(true));
     }
-    return Array.from(cmHandleIds)
+    return Array.from(alternateIds)
+}
+
+/**
+ * Generates a random CM Handle reference based on the provided flag.
+ * @param useAlternateId
+ * @returns {string} CM Handle reference representing a CM handle ID or an alternate ID.
+ */
+export function getRandomCmHandleReference(useAlternateId) {
+    const prefix = useAlternateId ? 'Region=NorthAmerica,Segment=' : 'ch-';
+    return `${prefix}${randomIntBetween(1, TOTAL_CM_HANDLES)}`;
 }
 
 /**
index 1104b14..1c53139 100644 (file)
@@ -23,7 +23,7 @@ import { Trend } from 'k6/metrics';
 import { Reader } from 'k6/x/kafka';
 import {
     TOTAL_CM_HANDLES, READ_DATA_FOR_CM_HANDLE_DELAY_MS, WRITE_DATA_FOR_CM_HANDLE_DELAY_MS,
-    makeCustomSummaryReport, makeBatchOfCmHandleIds, makeRandomBatchOfCmHandleIds,
+    makeCustomSummaryReport, makeBatchOfCmHandleIds, makeRandomBatchOfAlternateIds,
     LEGACY_BATCH_THROUGHPUT_TEST_BATCH_SIZE, REGISTRATION_BATCH_SIZE, LEGACY_BATCH_THROUGHPUT_TEST_NUMBER_OF_REQUESTS,
     KAFKA_BOOTSTRAP_SERVERS, LEGACY_BATCH_TOPIC_NAME, CONTAINER_UP_TIME_IN_SECONDS, testConfig
 } from './common/utils.js';
@@ -183,7 +183,7 @@ export function cmHandleSearchCpsPathScenario() {
 export function cmHandleIdSearchTrustLevelScenario() {
     const response = executeCmHandleIdSearch('trust-level');
     if (check(response, { 'CM handle ID trust level search status equals 200': (r) => r.status === 200 })
-     && check(response, { 'CM handle ID trust level search returned the correct number of ids': (r) => r.json('#') === TOTAL_CM_HANDLES })) {
+     && check(response, { 'CM handle ID trust level search returned the correct number of cm handle references': (r) => r.json('#') === TOTAL_CM_HANDLES })) {
         idSearchTrustLevelDurationTrend.add(response.timings.duration);
     }
 }
@@ -197,8 +197,8 @@ export function cmHandleSearchTrustLevelScenario() {
 }
 
 export function legacyBatchProduceScenario() {
-    const nextBatchOfCmHandleIds = makeRandomBatchOfCmHandleIds();
-    const response = legacyBatchRead(nextBatchOfCmHandleIds);
+    const nextBatchOfAlternateIds = makeRandomBatchOfAlternateIds();
+    const response = legacyBatchRead(nextBatchOfAlternateIds);
     check(response, { 'data operation batch read status equals 200': (r) => r.status === 200 });
 }