blob: 769b4b2ce175629e67b3f186b9608ea26fa76e83 [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.cakal1745d202024-08-06 14:02:49 +010026 makeCustomSummaryReport, makeBatchOfCmHandleIds, DATA_OPERATION_READ_BATCH_SIZE,
27 TOPIC_DATA_OPERATIONS_BATCH_READ, KAFKA_BOOTSTRAP_SERVERS, REGISTRATION_BATCH_SIZE
halil.cakal65b870b2024-07-25 11:12:29 +010028} from './common/utils.js';
halil.cakal1745d202024-08-06 14:02:49 +010029import {
30 createCmHandles,
31 deleteCmHandles,
32 waitForAllCmHandlesToBeReady
33} from './common/cmhandle-crud.js';
danielhanrahan4e9f68c2024-06-28 13:43:35 +010034import { executeCmHandleSearch, executeCmHandleIdSearch } from './common/search-base.js';
seanbeirne28559522024-07-19 16:55:06 +010035import { passthroughRead, passthroughReadWithAltId, passthroughWrite, batchRead } from './common/passthrough-crud.js';
danielhanrahan4e9f68c2024-06-28 13:43:35 +010036
danielhanrahan78894db2024-08-16 13:56:14 +010037let cmHandlesCreatedPerSecondTrend = new Trend('cmhandles_created_per_second', false);
38let cmHandlesDeletedPerSecondTrend = new Trend('cmhandles_deleted_per_second', false);
danielhanrahana1cdf732024-08-16 11:09:25 +010039let passthroughReadNcmpOverheadTrend = new Trend('ncmp_overhead_passthrough_read', true);
40let passthroughReadNcmpOverheadTrendWithAlternateId = new Trend('ncmp_overhead_passthrough_read_alt_id', true);
41let passthroughWriteNcmpOverheadTrend = new Trend('ncmp_overhead_passthrough_write', true);
danielhanrahan78894db2024-08-16 13:56:14 +010042let idSearchDurationTrend = new Trend('id_search_duration', true);
43let cmSearchDurationTrend = new Trend('cm_search_duration', true);
44let dataOperationsBatchReadCmHandlePerSecondTrend = new Trend('data_operations_batch_read_cmhandles_per_second', false);
halil.cakal65b870b2024-07-25 11:12:29 +010045
46const reader = new Reader({
47 brokers: KAFKA_BOOTSTRAP_SERVERS,
48 topic: TOPIC_DATA_OPERATIONS_BATCH_READ,
49});
danielhanrahan4e9f68c2024-06-28 13:43:35 +010050
51const DURATION = '15m';
52
53export const options = {
54 setupTimeout: '6m',
55 teardownTimeout: '6m',
56 scenarios: {
57 passthrough_read: {
58 executor: 'constant-vus',
59 exec: 'passthrough_read',
danielhanrahana1cdf732024-08-16 11:09:25 +010060 vus: 9,
danielhanrahan4e9f68c2024-06-28 13:43:35 +010061 duration: DURATION,
62 },
seanbeirne28559522024-07-19 16:55:06 +010063 passthrough_read_alt_id: {
64 executor: 'constant-vus',
65 exec: 'passthrough_read_alt_id',
66 vus: 1,
67 duration: DURATION,
68 },
halil.cakalfcc81ee2024-07-11 14:54:57 +010069 passthrough_write: {
70 executor: 'constant-vus',
71 exec: 'passthrough_write',
72 vus: 10,
73 duration: DURATION,
74 },
danielhanrahan4e9f68c2024-06-28 13:43:35 +010075 id_search_module: {
76 executor: 'constant-vus',
77 exec: 'id_search_module',
78 vus: 3,
79 duration: DURATION,
80 },
81 cm_search_module: {
82 executor: 'constant-vus',
83 exec: 'cm_search_module',
84 vus: 3,
85 duration: DURATION,
86 },
halil.cakal65b870b2024-07-25 11:12:29 +010087 data_operation_send_async_http_request: {
88 executor: 'constant-arrival-rate',
89 exec: 'data_operation_send_async_http_request',
90 duration: DURATION,
91 rate: 1,
92 timeUnit: '1s',
93 preAllocatedVUs: 1,
94 },
95 data_operation_async_batch_read: {
96 executor: 'constant-arrival-rate',
97 exec: 'data_operation_async_batch_read',
98 duration: DURATION,
99 rate: 1,
100 timeUnit: '1s',
101 preAllocatedVUs: 1,
102 }
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100103 },
104 thresholds: {
danielhanrahan78894db2024-08-16 13:56:14 +0100105 'cmhandles_created_per_second': ['avg >= 22'],
106 'cmhandles_deleted_per_second': ['avg >= 22'],
danielhanrahandbe7b662024-07-16 11:47:24 +0100107 'ncmp_overhead_passthrough_read': ['avg <= 100'],
seanbeirne28559522024-07-19 16:55:06 +0100108 'ncmp_overhead_passthrough_read_alt_id': ['avg <= 100'],
danielhanrahandbe7b662024-07-16 11:47:24 +0100109 'ncmp_overhead_passthrough_write': ['avg <= 100'],
danielhanrahan78894db2024-08-16 13:56:14 +0100110 'id_search_duration': ['avg <= 625'],
111 'cm_search_duration': ['avg <= 13000'],
112 'data_operations_batch_read_cmhandles_per_second': ['avg >= 150'],
danielhanrahandbe7b662024-07-16 11:47:24 +0100113 'http_req_failed{scenario:id_search_module}': ['rate == 0'],
114 'http_req_failed{scenario:cm_search_module}': ['rate == 0'],
115 'http_req_failed{scenario:passthrough_read}': ['rate == 0'],
116 'http_req_failed{scenario:passthrough_write}': ['rate == 0'],
halil.cakal1745d202024-08-06 14:02:49 +0100117 'http_req_failed{group:::setup}':['rate == 0'],
118 'http_req_failed{group:::teardown}':['rate == 0'],
halil.cakal65b870b2024-07-25 11:12:29 +0100119 'http_req_failed{scenario:data_operation_send_async_http_request}': ['rate == 0'],
120 'kafka_reader_error_count{scenario:data_operation_consume_kafka_responses}': ['count == 0'],
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100121 },
122};
123
124export function setup() {
halil.cakal1745d202024-08-06 14:02:49 +0100125 const startTimeInMillis = Date.now();
126
127 const TOTAL_BATCHES = Math.ceil(TOTAL_CM_HANDLES / REGISTRATION_BATCH_SIZE);
128 for (let batchNumber = 0; batchNumber < TOTAL_BATCHES; batchNumber++) {
129 const nextBatchOfCmHandleIds = makeBatchOfCmHandleIds(REGISTRATION_BATCH_SIZE, batchNumber);
130 const response = createCmHandles(nextBatchOfCmHandleIds);
131 check(response, { 'create CM-handles status equals 200': (r) => r.status === 200 });
132 }
133
134 waitForAllCmHandlesToBeReady();
135
136 const endTimeInMillis = Date.now();
137 const totalRegistrationTimeInSeconds = (endTimeInMillis - startTimeInMillis) / 1000.0;
138
danielhanrahan78894db2024-08-16 13:56:14 +0100139 cmHandlesCreatedPerSecondTrend.add(TOTAL_CM_HANDLES / totalRegistrationTimeInSeconds);
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100140}
141
142export function teardown() {
halil.cakal1745d202024-08-06 14:02:49 +0100143 const startTimeInMillis = Date.now();
144
145 const TOTAL_BATCHES = Math.ceil(TOTAL_CM_HANDLES / REGISTRATION_BATCH_SIZE);
146 for (let batchNumber = 0; batchNumber < TOTAL_BATCHES; batchNumber++) {
147 const nextBatchOfCmHandleIds = makeBatchOfCmHandleIds(REGISTRATION_BATCH_SIZE, batchNumber);
148 const response = deleteCmHandles(nextBatchOfCmHandleIds);
149 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
danielhanrahan78894db2024-08-16 13:56:14 +0100155 cmHandlesDeletedPerSecondTrend.add(TOTAL_CM_HANDLES / totalDeregistrationTimeInSeconds);
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100156}
157
158export function passthrough_read() {
159 const response = passthroughRead();
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
seanbeirne28559522024-07-19 16:55:06 +0100166export function passthrough_read_alt_id() {
167 const response = passthroughReadWithAltId();
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.cakalfcc81ee2024-07-11 14:54:57 +0100174export function passthrough_write() {
175 const response = passthroughWrite();
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
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100182export function id_search_module() {
183 const response = executeCmHandleIdSearch('module');
danielhanrahan78894db2024-08-16 13:56:14 +0100184 if (check(response, { 'CM handle ID search status equals 200': (r) => r.status === 200 })) {
185 check(response, { 'CM handle ID search returned expected CM-handles': (r) => r.json('#') === TOTAL_CM_HANDLES });
186 idSearchDurationTrend.add(response.timings.duration);
187 }
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100188}
189
190export function cm_search_module() {
191 const response = executeCmHandleSearch('module');
danielhanrahan78894db2024-08-16 13:56:14 +0100192 if (check(response, { 'CM handle search status equals 200': (r) => r.status === 200 })) {
193 check(response, { 'CM handle search returned expected CM-handles': (r) => r.json('#') === TOTAL_CM_HANDLES });
194 cmSearchDurationTrend.add(response.timings.duration);
195 }
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100196}
197
halil.cakal65b870b2024-07-25 11:12:29 +0100198export function data_operation_send_async_http_request() {
danielhanrahan78894db2024-08-16 13:56:14 +0100199 const nextBatchOfCmHandleIds = makeBatchOfCmHandleIds(DATA_OPERATION_READ_BATCH_SIZE, 0);
200 const response = batchRead(nextBatchOfCmHandleIds);
halil.cakal65b870b2024-07-25 11:12:29 +0100201 check(response, { 'data operation batch read status equals 200': (r) => r.status === 200 });
202}
203
204export function data_operation_async_batch_read() {
205 try {
206 let messages = reader.consume({ limit: DATA_OPERATION_READ_BATCH_SIZE });
207 dataOperationsBatchReadCmHandlePerSecondTrend.add(messages.length);
208 } catch (error) {
209 dataOperationsBatchReadCmHandlePerSecondTrend.add(0);
210 console.error(error);
211 }
212}
213
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100214export function handleSummary(data) {
215 return {
216 stdout: makeCustomSummaryReport(data, options),
217 };
218}