blob: 05500a60a3c91b81442844bf35cd0f749054ef40 [file] [log] [blame]
danielhanrahan4e9f68c2024-06-28 13:43:35 +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
21import { check } from 'k6';
danielhanrahan78894db2024-08-16 13:56:14 +010022import { Trend } from 'k6/metrics';
danielhanrahana1cdf732024-08-16 11:09:25 +010023import { Reader } from 'k6/x/kafka';
halil.cakal65b870b2024-07-25 11:12:29 +010024import {
25 TOTAL_CM_HANDLES, READ_DATA_FOR_CM_HANDLE_DELAY_MS, WRITE_DATA_FOR_CM_HANDLE_DELAY_MS,
halil.cakalfc499102024-08-28 10:19:26 +010026 makeCustomSummaryReport, makeBatchOfCmHandleIds, LEGACY_BATCH_THROUGHPUT_TEST_BATCH_SIZE,
27 LEGACY_BATCH_TOPIC_NAME, KAFKA_BOOTSTRAP_SERVERS, REGISTRATION_BATCH_SIZE,
28 LEGACY_BATCH_THROUGHPUT_TEST_NUMBER_OF_REQUESTS
halil.cakal65b870b2024-07-25 11:12:29 +010029} from './common/utils.js';
danielhanrahanf2e1e252024-08-25 21:35:19 +010030import { createCmHandles, deleteCmHandles, waitForAllCmHandlesToBeReady } from './common/cmhandle-crud.js';
danielhanrahan4e9f68c2024-06-28 13:43:35 +010031import { executeCmHandleSearch, executeCmHandleIdSearch } from './common/search-base.js';
halil.cakalfc499102024-08-28 10:19:26 +010032import { passthroughRead, passthroughWrite, legacyBatchRead } from './common/passthrough-crud.js';
danielhanrahan4e9f68c2024-06-28 13:43:35 +010033
danielhanrahan78894db2024-08-16 13:56:14 +010034let cmHandlesCreatedPerSecondTrend = new Trend('cmhandles_created_per_second', false);
35let cmHandlesDeletedPerSecondTrend = new Trend('cmhandles_deleted_per_second', false);
danielhanrahana1cdf732024-08-16 11:09:25 +010036let passthroughReadNcmpOverheadTrend = new Trend('ncmp_overhead_passthrough_read', true);
37let passthroughReadNcmpOverheadTrendWithAlternateId = new Trend('ncmp_overhead_passthrough_read_alt_id', true);
38let passthroughWriteNcmpOverheadTrend = new Trend('ncmp_overhead_passthrough_write', true);
danielhanrahanf2e1e252024-08-25 21:35:19 +010039let passthroughWriteNcmpOverheadTrendWithAlternateId = new Trend('ncmp_overhead_passthrough_write_alt_id', true);
danielhanrahan78894db2024-08-16 13:56:14 +010040let idSearchDurationTrend = new Trend('id_search_duration', true);
41let cmSearchDurationTrend = new Trend('cm_search_duration', true);
halil.cakalfc499102024-08-28 10:19:26 +010042let legacyBatchReadCmHandlesPerSecondTrend = new Trend('legacy_batch_read_cmhandles_per_second', false);
halil.cakal65b870b2024-07-25 11:12:29 +010043
halil.cakalfc499102024-08-28 10:19:26 +010044const legacyBatchEventReader = new Reader({
halil.cakal65b870b2024-07-25 11:12:29 +010045 brokers: KAFKA_BOOTSTRAP_SERVERS,
halil.cakalfc499102024-08-28 10:19:26 +010046 topic: LEGACY_BATCH_TOPIC_NAME,
halil.cakal65b870b2024-07-25 11:12:29 +010047});
danielhanrahan4e9f68c2024-06-28 13:43:35 +010048
49const DURATION = '15m';
50
51export const options = {
danielhanrahan4dac1302024-08-30 15:03:06 +010052 setupTimeout: '8m',
danielhanrahan4e9f68c2024-06-28 13:43:35 +010053 teardownTimeout: '6m',
54 scenarios: {
halil.cakalfc499102024-08-28 10:19:26 +010055 passthrough_read_scenario: {
danielhanrahan4e9f68c2024-06-28 13:43:35 +010056 executor: 'constant-vus',
halil.cakalfc499102024-08-28 10:19:26 +010057 exec: 'passthroughReadScenario',
danielhanrahanf2e1e252024-08-25 21:35:19 +010058 vus: 4,
danielhanrahan4e9f68c2024-06-28 13:43:35 +010059 duration: DURATION,
60 },
halil.cakalfc499102024-08-28 10:19:26 +010061 passthrough_read_alt_id_scenario: {
seanbeirne28559522024-07-19 16:55:06 +010062 executor: 'constant-vus',
halil.cakalfc499102024-08-28 10:19:26 +010063 exec: 'passthroughReadAltIdScenario',
danielhanrahanf2e1e252024-08-25 21:35:19 +010064 vus: 4,
seanbeirne28559522024-07-19 16:55:06 +010065 duration: DURATION,
66 },
halil.cakalfc499102024-08-28 10:19:26 +010067 passthrough_write_scenario: {
halil.cakalfcc81ee2024-07-11 14:54:57 +010068 executor: 'constant-vus',
halil.cakalfc499102024-08-28 10:19:26 +010069 exec: 'passthroughWriteScenario',
danielhanrahanf2e1e252024-08-25 21:35:19 +010070 vus: 4,
halil.cakalfcc81ee2024-07-11 14:54:57 +010071 duration: DURATION,
72 },
halil.cakalfc499102024-08-28 10:19:26 +010073 passthrough_write_alt_id_scenario: {
danielhanrahan4e9f68c2024-06-28 13:43:35 +010074 executor: 'constant-vus',
halil.cakalfc499102024-08-28 10:19:26 +010075 exec: 'passthroughWriteAltIdScenario',
danielhanrahanf2e1e252024-08-25 21:35:19 +010076 vus: 4,
danielhanrahan4e9f68c2024-06-28 13:43:35 +010077 duration: DURATION,
78 },
halil.cakalfc499102024-08-28 10:19:26 +010079 cm_handle_id_search_scenario: {
danielhanrahan4e9f68c2024-06-28 13:43:35 +010080 executor: 'constant-vus',
halil.cakalfc499102024-08-28 10:19:26 +010081 exec: 'cmHandleIdSearchScenario',
danielhanrahanf2e1e252024-08-25 21:35:19 +010082 vus: 5,
83 duration: DURATION,
84 },
halil.cakalfc499102024-08-28 10:19:26 +010085 cm_handle_search_scenario: {
danielhanrahanf2e1e252024-08-25 21:35:19 +010086 executor: 'constant-vus',
halil.cakalfc499102024-08-28 10:19:26 +010087 exec: 'cmHandleSearchScenario',
danielhanrahanf2e1e252024-08-25 21:35:19 +010088 vus: 5,
danielhanrahan4e9f68c2024-06-28 13:43:35 +010089 duration: DURATION,
90 },
halil.cakalfc499102024-08-28 10:19:26 +010091 legacy_batch_produce_scenario: {
92 executor: 'shared-iterations',
93 exec: 'legacyBatchProduceScenario',
94 vus: 2,
95 iterations: LEGACY_BATCH_THROUGHPUT_TEST_NUMBER_OF_REQUESTS,
96 maxDuration: DURATION,
halil.cakal65b870b2024-07-25 11:12:29 +010097 },
halil.cakalfc499102024-08-28 10:19:26 +010098 legacy_batch_consume_scenario: {
99 executor: 'per-vu-iterations',
100 exec: 'legacyBatchConsumeScenario',
101 vus: 1,
102 iterations: 1,
103 maxDuration: DURATION,
halil.cakal65b870b2024-07-25 11:12:29 +0100104 }
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100105 },
106 thresholds: {
danielhanrahan4cb62392024-08-27 17:57:26 +0100107 'http_req_failed': ['rate == 0'],
danielhanrahan78894db2024-08-16 13:56:14 +0100108 'cmhandles_created_per_second': ['avg >= 22'],
109 'cmhandles_deleted_per_second': ['avg >= 22'],
danielhanrahanf2e1e252024-08-25 21:35:19 +0100110 'ncmp_overhead_passthrough_read': ['avg <= 40'],
111 'ncmp_overhead_passthrough_write': ['avg <= 40'],
112 'ncmp_overhead_passthrough_read_alt_id': ['avg <= 40'],
113 'ncmp_overhead_passthrough_write_alt_id': ['avg <= 40'],
114 'id_search_duration': ['avg <= 2000'],
115 'cm_search_duration': ['avg <= 15000'],
halil.cakalfc499102024-08-28 10:19:26 +0100116 'legacy_batch_read_cmhandles_per_second': ['avg >= 150'],
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100117 },
118};
119
120export function setup() {
halil.cakal1745d202024-08-06 14:02:49 +0100121 const startTimeInMillis = Date.now();
122
123 const TOTAL_BATCHES = Math.ceil(TOTAL_CM_HANDLES / REGISTRATION_BATCH_SIZE);
124 for (let batchNumber = 0; batchNumber < TOTAL_BATCHES; batchNumber++) {
125 const nextBatchOfCmHandleIds = makeBatchOfCmHandleIds(REGISTRATION_BATCH_SIZE, batchNumber);
126 const response = createCmHandles(nextBatchOfCmHandleIds);
127 check(response, { 'create CM-handles status equals 200': (r) => r.status === 200 });
128 }
129
130 waitForAllCmHandlesToBeReady();
131
132 const endTimeInMillis = Date.now();
133 const totalRegistrationTimeInSeconds = (endTimeInMillis - startTimeInMillis) / 1000.0;
134
danielhanrahan78894db2024-08-16 13:56:14 +0100135 cmHandlesCreatedPerSecondTrend.add(TOTAL_CM_HANDLES / totalRegistrationTimeInSeconds);
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100136}
137
138export function teardown() {
halil.cakal1745d202024-08-06 14:02:49 +0100139 const startTimeInMillis = Date.now();
140
egernug2bdef262024-09-06 12:09:31 +0100141 let DEREGISTERED_CM_HANDLES = 0
halil.cakal1745d202024-08-06 14:02:49 +0100142 const TOTAL_BATCHES = Math.ceil(TOTAL_CM_HANDLES / REGISTRATION_BATCH_SIZE);
143 for (let batchNumber = 0; batchNumber < TOTAL_BATCHES; batchNumber++) {
144 const nextBatchOfCmHandleIds = makeBatchOfCmHandleIds(REGISTRATION_BATCH_SIZE, batchNumber);
145 const response = deleteCmHandles(nextBatchOfCmHandleIds);
egernug2bdef262024-09-06 12:09:31 +0100146 if (response.error_code === 0) {
147 DEREGISTERED_CM_HANDLES += REGISTRATION_BATCH_SIZE
148 }
halil.cakal1745d202024-08-06 14:02:49 +0100149 check(response, { 'delete CM-handles status equals 200': (r) => r.status === 200 });
150 }
151
152 const endTimeInMillis = Date.now();
153 const totalDeregistrationTimeInSeconds = (endTimeInMillis - startTimeInMillis) / 1000.0;
154
egernug2bdef262024-09-06 12:09:31 +0100155 cmHandlesDeletedPerSecondTrend.add(DEREGISTERED_CM_HANDLES / totalDeregistrationTimeInSeconds);
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100156}
157
halil.cakalfc499102024-08-28 10:19:26 +0100158export function passthroughReadScenario() {
danielhanrahanf2e1e252024-08-25 21:35:19 +0100159 const response = passthroughRead(false);
danielhanrahan78894db2024-08-16 13:56:14 +0100160 if (check(response, { 'passthrough read status equals 200': (r) => r.status === 200 })) {
161 const overhead = response.timings.duration - READ_DATA_FOR_CM_HANDLE_DELAY_MS;
162 passthroughReadNcmpOverheadTrend.add(overhead);
163 }
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100164}
165
halil.cakalfc499102024-08-28 10:19:26 +0100166export function passthroughReadAltIdScenario() {
danielhanrahanf2e1e252024-08-25 21:35:19 +0100167 const response = passthroughRead(true);
danielhanrahan78894db2024-08-16 13:56:14 +0100168 if (check(response, { 'passthrough read with alternate Id status equals 200': (r) => r.status === 200 })) {
169 const overhead = response.timings.duration - READ_DATA_FOR_CM_HANDLE_DELAY_MS;
170 passthroughReadNcmpOverheadTrendWithAlternateId.add(overhead);
171 }
seanbeirne28559522024-07-19 16:55:06 +0100172}
173
halil.cakalfc499102024-08-28 10:19:26 +0100174export function passthroughWriteScenario() {
danielhanrahanf2e1e252024-08-25 21:35:19 +0100175 const response = passthroughWrite(false);
danielhanrahan78894db2024-08-16 13:56:14 +0100176 if (check(response, { 'passthrough write status equals 201': (r) => r.status === 201 })) {
177 const overhead = response.timings.duration - WRITE_DATA_FOR_CM_HANDLE_DELAY_MS;
178 passthroughWriteNcmpOverheadTrend.add(overhead);
179 }
halil.cakalfcc81ee2024-07-11 14:54:57 +0100180}
181
halil.cakalfc499102024-08-28 10:19:26 +0100182export function passthroughWriteAltIdScenario() {
danielhanrahanf2e1e252024-08-25 21:35:19 +0100183 const response = passthroughWrite(true);
184 if (check(response, { 'passthrough write with alternate Id status equals 201': (r) => r.status === 201 })) {
185 const overhead = response.timings.duration - WRITE_DATA_FOR_CM_HANDLE_DELAY_MS;
186 passthroughWriteNcmpOverheadTrendWithAlternateId.add(overhead);
187 }
188}
189
halil.cakalfc499102024-08-28 10:19:26 +0100190export function cmHandleIdSearchScenario() {
danielhanrahanf2e1e252024-08-25 21:35:19 +0100191 const response = executeCmHandleIdSearch('module-and-properties');
danielhanrahan4dac1302024-08-30 15:03:06 +0100192 if (check(response, { 'CM handle ID search status equals 200': (r) => r.status === 200 })
193 && check(response, { 'CM handle ID search returned expected CM-handles': (r) => r.json('#') === TOTAL_CM_HANDLES })) {
danielhanrahan78894db2024-08-16 13:56:14 +0100194 idSearchDurationTrend.add(response.timings.duration);
195 }
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100196}
197
halil.cakalfc499102024-08-28 10:19:26 +0100198export function cmHandleSearchScenario() {
danielhanrahanf2e1e252024-08-25 21:35:19 +0100199 const response = executeCmHandleSearch('module-and-properties');
danielhanrahan4dac1302024-08-30 15:03:06 +0100200 if (check(response, { 'CM handle search status equals 200': (r) => r.status === 200 })
201 && check(response, { 'CM handle search returned expected CM-handles': (r) => r.json('#') === TOTAL_CM_HANDLES })) {
danielhanrahan78894db2024-08-16 13:56:14 +0100202 cmSearchDurationTrend.add(response.timings.duration);
203 }
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100204}
205
halil.cakalfc499102024-08-28 10:19:26 +0100206export function legacyBatchProduceScenario() {
207 const nextBatchOfCmHandleIds = makeBatchOfCmHandleIds(LEGACY_BATCH_THROUGHPUT_TEST_BATCH_SIZE, 0);
208 const response = legacyBatchRead(nextBatchOfCmHandleIds);
halil.cakal65b870b2024-07-25 11:12:29 +0100209 check(response, { 'data operation batch read status equals 200': (r) => r.status === 200 });
210}
211
halil.cakalfc499102024-08-28 10:19:26 +0100212export function legacyBatchConsumeScenario() {
213 const TOTAL_MESSAGES_TO_CONSUME = LEGACY_BATCH_THROUGHPUT_TEST_NUMBER_OF_REQUESTS * LEGACY_BATCH_THROUGHPUT_TEST_BATCH_SIZE;
halil.cakal65b870b2024-07-25 11:12:29 +0100214 try {
halil.cakalfc499102024-08-28 10:19:26 +0100215 let messagesConsumed = 0;
216 let startTime = Date.now();
217
218 while (messagesConsumed < TOTAL_MESSAGES_TO_CONSUME) {
219 let messages = legacyBatchEventReader.consume({ limit: 1000 });
220
221 if (messages.length > 0) {
222 messagesConsumed += messages.length;
223 }
224 }
225
226 let endTime = Date.now();
227 const timeToConsumeMessagesInSeconds = (endTime - startTime) / 1000.0;
228 legacyBatchReadCmHandlesPerSecondTrend.add(TOTAL_MESSAGES_TO_CONSUME / timeToConsumeMessagesInSeconds);
halil.cakal65b870b2024-07-25 11:12:29 +0100229 } catch (error) {
halil.cakalfc499102024-08-28 10:19:26 +0100230 legacyBatchReadCmHandlesPerSecondTrend.add(0);
halil.cakal65b870b2024-07-25 11:12:29 +0100231 console.error(error);
232 }
233}
234
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100235export function handleSummary(data) {
236 return {
237 stdout: makeCustomSummaryReport(data, options),
238 };
239}