blob: f9a19c394fb9781d0d3f249c6f363852636f8ec6 [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';
halil.cakal8ea90c92024-09-18 12:48:27 +010050const LEGACY_BATCH_THROUGHPUT_TEST_START_TIME = '15m30s';
danielhanrahan4e9f68c2024-06-28 13:43:35 +010051
52export const options = {
danielhanrahan4dac1302024-08-30 15:03:06 +010053 setupTimeout: '8m',
danielhanrahan4e9f68c2024-06-28 13:43:35 +010054 teardownTimeout: '6m',
55 scenarios: {
halil.cakalfc499102024-08-28 10:19:26 +010056 passthrough_read_scenario: {
danielhanrahan4e9f68c2024-06-28 13:43:35 +010057 executor: 'constant-vus',
halil.cakalfc499102024-08-28 10:19:26 +010058 exec: 'passthroughReadScenario',
danielhanrahanf2e1e252024-08-25 21:35:19 +010059 vus: 4,
danielhanrahan4e9f68c2024-06-28 13:43:35 +010060 duration: DURATION,
61 },
halil.cakalfc499102024-08-28 10:19:26 +010062 passthrough_read_alt_id_scenario: {
seanbeirne28559522024-07-19 16:55:06 +010063 executor: 'constant-vus',
halil.cakalfc499102024-08-28 10:19:26 +010064 exec: 'passthroughReadAltIdScenario',
danielhanrahanf2e1e252024-08-25 21:35:19 +010065 vus: 4,
seanbeirne28559522024-07-19 16:55:06 +010066 duration: DURATION,
67 },
halil.cakalfc499102024-08-28 10:19:26 +010068 passthrough_write_scenario: {
halil.cakalfcc81ee2024-07-11 14:54:57 +010069 executor: 'constant-vus',
halil.cakalfc499102024-08-28 10:19:26 +010070 exec: 'passthroughWriteScenario',
danielhanrahanf2e1e252024-08-25 21:35:19 +010071 vus: 4,
halil.cakalfcc81ee2024-07-11 14:54:57 +010072 duration: DURATION,
73 },
halil.cakalfc499102024-08-28 10:19:26 +010074 passthrough_write_alt_id_scenario: {
danielhanrahan4e9f68c2024-06-28 13:43:35 +010075 executor: 'constant-vus',
halil.cakalfc499102024-08-28 10:19:26 +010076 exec: 'passthroughWriteAltIdScenario',
danielhanrahanf2e1e252024-08-25 21:35:19 +010077 vus: 4,
danielhanrahan4e9f68c2024-06-28 13:43:35 +010078 duration: DURATION,
79 },
halil.cakalfc499102024-08-28 10:19:26 +010080 cm_handle_id_search_scenario: {
danielhanrahan4e9f68c2024-06-28 13:43:35 +010081 executor: 'constant-vus',
halil.cakalfc499102024-08-28 10:19:26 +010082 exec: 'cmHandleIdSearchScenario',
danielhanrahanf2e1e252024-08-25 21:35:19 +010083 vus: 5,
84 duration: DURATION,
85 },
halil.cakalfc499102024-08-28 10:19:26 +010086 cm_handle_search_scenario: {
danielhanrahanf2e1e252024-08-25 21:35:19 +010087 executor: 'constant-vus',
halil.cakalfc499102024-08-28 10:19:26 +010088 exec: 'cmHandleSearchScenario',
danielhanrahanf2e1e252024-08-25 21:35:19 +010089 vus: 5,
danielhanrahan4e9f68c2024-06-28 13:43:35 +010090 duration: DURATION,
91 },
halil.cakalfc499102024-08-28 10:19:26 +010092 legacy_batch_produce_scenario: {
93 executor: 'shared-iterations',
94 exec: 'legacyBatchProduceScenario',
95 vus: 2,
96 iterations: LEGACY_BATCH_THROUGHPUT_TEST_NUMBER_OF_REQUESTS,
halil.cakal8ea90c92024-09-18 12:48:27 +010097 startTime: LEGACY_BATCH_THROUGHPUT_TEST_START_TIME,
halil.cakal65b870b2024-07-25 11:12:29 +010098 },
halil.cakalfc499102024-08-28 10:19:26 +010099 legacy_batch_consume_scenario: {
100 executor: 'per-vu-iterations',
101 exec: 'legacyBatchConsumeScenario',
102 vus: 1,
103 iterations: 1,
halil.cakal8ea90c92024-09-18 12:48:27 +0100104 startTime: LEGACY_BATCH_THROUGHPUT_TEST_START_TIME,
halil.cakal65b870b2024-07-25 11:12:29 +0100105 }
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100106 },
107 thresholds: {
danielhanrahan4cb62392024-08-27 17:57:26 +0100108 'http_req_failed': ['rate == 0'],
danielhanrahan78894db2024-08-16 13:56:14 +0100109 'cmhandles_created_per_second': ['avg >= 22'],
110 'cmhandles_deleted_per_second': ['avg >= 22'],
danielhanrahanf2e1e252024-08-25 21:35:19 +0100111 'ncmp_overhead_passthrough_read': ['avg <= 40'],
112 'ncmp_overhead_passthrough_write': ['avg <= 40'],
113 'ncmp_overhead_passthrough_read_alt_id': ['avg <= 40'],
114 'ncmp_overhead_passthrough_write_alt_id': ['avg <= 40'],
115 'id_search_duration': ['avg <= 2000'],
116 'cm_search_duration': ['avg <= 15000'],
halil.cakalfc499102024-08-28 10:19:26 +0100117 'legacy_batch_read_cmhandles_per_second': ['avg >= 150'],
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100118 },
119};
120
121export function setup() {
halil.cakal1745d202024-08-06 14:02:49 +0100122 const startTimeInMillis = Date.now();
123
124 const TOTAL_BATCHES = Math.ceil(TOTAL_CM_HANDLES / REGISTRATION_BATCH_SIZE);
125 for (let batchNumber = 0; batchNumber < TOTAL_BATCHES; batchNumber++) {
126 const nextBatchOfCmHandleIds = makeBatchOfCmHandleIds(REGISTRATION_BATCH_SIZE, batchNumber);
127 const response = createCmHandles(nextBatchOfCmHandleIds);
128 check(response, { 'create CM-handles status equals 200': (r) => r.status === 200 });
129 }
130
131 waitForAllCmHandlesToBeReady();
132
133 const endTimeInMillis = Date.now();
134 const totalRegistrationTimeInSeconds = (endTimeInMillis - startTimeInMillis) / 1000.0;
135
danielhanrahan78894db2024-08-16 13:56:14 +0100136 cmHandlesCreatedPerSecondTrend.add(TOTAL_CM_HANDLES / totalRegistrationTimeInSeconds);
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100137}
138
139export function teardown() {
halil.cakal1745d202024-08-06 14:02:49 +0100140 const startTimeInMillis = Date.now();
141
egernug2bdef262024-09-06 12:09:31 +0100142 let DEREGISTERED_CM_HANDLES = 0
halil.cakal1745d202024-08-06 14:02:49 +0100143 const TOTAL_BATCHES = Math.ceil(TOTAL_CM_HANDLES / REGISTRATION_BATCH_SIZE);
144 for (let batchNumber = 0; batchNumber < TOTAL_BATCHES; batchNumber++) {
145 const nextBatchOfCmHandleIds = makeBatchOfCmHandleIds(REGISTRATION_BATCH_SIZE, batchNumber);
146 const response = deleteCmHandles(nextBatchOfCmHandleIds);
egernug2bdef262024-09-06 12:09:31 +0100147 if (response.error_code === 0) {
148 DEREGISTERED_CM_HANDLES += REGISTRATION_BATCH_SIZE
149 }
halil.cakal1745d202024-08-06 14:02:49 +0100150 check(response, { 'delete CM-handles status equals 200': (r) => r.status === 200 });
151 }
152
153 const endTimeInMillis = Date.now();
154 const totalDeregistrationTimeInSeconds = (endTimeInMillis - startTimeInMillis) / 1000.0;
155
egernug2bdef262024-09-06 12:09:31 +0100156 cmHandlesDeletedPerSecondTrend.add(DEREGISTERED_CM_HANDLES / totalDeregistrationTimeInSeconds);
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100157}
158
halil.cakalfc499102024-08-28 10:19:26 +0100159export function passthroughReadScenario() {
danielhanrahanf2e1e252024-08-25 21:35:19 +0100160 const response = passthroughRead(false);
danielhanrahan78894db2024-08-16 13:56:14 +0100161 if (check(response, { 'passthrough read status equals 200': (r) => r.status === 200 })) {
162 const overhead = response.timings.duration - READ_DATA_FOR_CM_HANDLE_DELAY_MS;
163 passthroughReadNcmpOverheadTrend.add(overhead);
164 }
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100165}
166
halil.cakalfc499102024-08-28 10:19:26 +0100167export function passthroughReadAltIdScenario() {
danielhanrahanf2e1e252024-08-25 21:35:19 +0100168 const response = passthroughRead(true);
danielhanrahan78894db2024-08-16 13:56:14 +0100169 if (check(response, { 'passthrough read with alternate Id status equals 200': (r) => r.status === 200 })) {
170 const overhead = response.timings.duration - READ_DATA_FOR_CM_HANDLE_DELAY_MS;
171 passthroughReadNcmpOverheadTrendWithAlternateId.add(overhead);
172 }
seanbeirne28559522024-07-19 16:55:06 +0100173}
174
halil.cakalfc499102024-08-28 10:19:26 +0100175export function passthroughWriteScenario() {
danielhanrahanf2e1e252024-08-25 21:35:19 +0100176 const response = passthroughWrite(false);
danielhanrahan78894db2024-08-16 13:56:14 +0100177 if (check(response, { 'passthrough write status equals 201': (r) => r.status === 201 })) {
178 const overhead = response.timings.duration - WRITE_DATA_FOR_CM_HANDLE_DELAY_MS;
179 passthroughWriteNcmpOverheadTrend.add(overhead);
180 }
halil.cakalfcc81ee2024-07-11 14:54:57 +0100181}
182
halil.cakalfc499102024-08-28 10:19:26 +0100183export function passthroughWriteAltIdScenario() {
danielhanrahanf2e1e252024-08-25 21:35:19 +0100184 const response = passthroughWrite(true);
185 if (check(response, { 'passthrough write with alternate Id status equals 201': (r) => r.status === 201 })) {
186 const overhead = response.timings.duration - WRITE_DATA_FOR_CM_HANDLE_DELAY_MS;
187 passthroughWriteNcmpOverheadTrendWithAlternateId.add(overhead);
188 }
189}
190
halil.cakalfc499102024-08-28 10:19:26 +0100191export function cmHandleIdSearchScenario() {
danielhanrahanf2e1e252024-08-25 21:35:19 +0100192 const response = executeCmHandleIdSearch('module-and-properties');
danielhanrahan4dac1302024-08-30 15:03:06 +0100193 if (check(response, { 'CM handle ID search status equals 200': (r) => r.status === 200 })
194 && check(response, { 'CM handle ID search returned expected CM-handles': (r) => r.json('#') === TOTAL_CM_HANDLES })) {
danielhanrahan78894db2024-08-16 13:56:14 +0100195 idSearchDurationTrend.add(response.timings.duration);
196 }
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100197}
198
halil.cakalfc499102024-08-28 10:19:26 +0100199export function cmHandleSearchScenario() {
danielhanrahanf2e1e252024-08-25 21:35:19 +0100200 const response = executeCmHandleSearch('module-and-properties');
danielhanrahan4dac1302024-08-30 15:03:06 +0100201 if (check(response, { 'CM handle search status equals 200': (r) => r.status === 200 })
202 && check(response, { 'CM handle search returned expected CM-handles': (r) => r.json('#') === TOTAL_CM_HANDLES })) {
danielhanrahan78894db2024-08-16 13:56:14 +0100203 cmSearchDurationTrend.add(response.timings.duration);
204 }
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100205}
206
halil.cakalfc499102024-08-28 10:19:26 +0100207export function legacyBatchProduceScenario() {
208 const nextBatchOfCmHandleIds = makeBatchOfCmHandleIds(LEGACY_BATCH_THROUGHPUT_TEST_BATCH_SIZE, 0);
209 const response = legacyBatchRead(nextBatchOfCmHandleIds);
halil.cakal65b870b2024-07-25 11:12:29 +0100210 check(response, { 'data operation batch read status equals 200': (r) => r.status === 200 });
211}
212
halil.cakalfc499102024-08-28 10:19:26 +0100213export function legacyBatchConsumeScenario() {
214 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 +0100215 try {
halil.cakalfc499102024-08-28 10:19:26 +0100216 let messagesConsumed = 0;
217 let startTime = Date.now();
218
219 while (messagesConsumed < TOTAL_MESSAGES_TO_CONSUME) {
220 let messages = legacyBatchEventReader.consume({ limit: 1000 });
221
222 if (messages.length > 0) {
223 messagesConsumed += messages.length;
224 }
225 }
226
227 let endTime = Date.now();
228 const timeToConsumeMessagesInSeconds = (endTime - startTime) / 1000.0;
229 legacyBatchReadCmHandlesPerSecondTrend.add(TOTAL_MESSAGES_TO_CONSUME / timeToConsumeMessagesInSeconds);
halil.cakal65b870b2024-07-25 11:12:29 +0100230 } catch (error) {
halil.cakalfc499102024-08-28 10:19:26 +0100231 legacyBatchReadCmHandlesPerSecondTrend.add(0);
halil.cakal65b870b2024-07-25 11:12:29 +0100232 console.error(error);
233 }
234}
235
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100236export function handleSummary(data) {
237 return {
238 stdout: makeCustomSummaryReport(data, options),
239 };
240}