blob: 013849b866908fec77cda7049a82eff2bfd85a1b [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';
danielhanrahandbe7b662024-07-16 11:47:24 +010022import { Gauge, 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
37let cmHandlesCreatedPerSecondGauge = new Gauge('cmhandles_created_per_second');
38let cmHandlesDeletedPerSecondGauge = new Gauge('cmhandles_deleted_per_second');
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);
halil.cakal65b870b2024-07-25 11:12:29 +010042let dataOperationsBatchReadCmHandlePerSecondTrend = new Trend('data_operations_batch_read_cmhandles_per_second');
43
44const reader = new Reader({
45 brokers: KAFKA_BOOTSTRAP_SERVERS,
46 topic: TOPIC_DATA_OPERATIONS_BATCH_READ,
47});
danielhanrahan4e9f68c2024-06-28 13:43:35 +010048
49const DURATION = '15m';
50
51export const options = {
52 setupTimeout: '6m',
53 teardownTimeout: '6m',
54 scenarios: {
55 passthrough_read: {
56 executor: 'constant-vus',
57 exec: 'passthrough_read',
danielhanrahana1cdf732024-08-16 11:09:25 +010058 vus: 9,
danielhanrahan4e9f68c2024-06-28 13:43:35 +010059 duration: DURATION,
60 },
seanbeirne28559522024-07-19 16:55:06 +010061 passthrough_read_alt_id: {
62 executor: 'constant-vus',
63 exec: 'passthrough_read_alt_id',
64 vus: 1,
65 duration: DURATION,
66 },
halil.cakalfcc81ee2024-07-11 14:54:57 +010067 passthrough_write: {
68 executor: 'constant-vus',
69 exec: 'passthrough_write',
70 vus: 10,
71 duration: DURATION,
72 },
danielhanrahan4e9f68c2024-06-28 13:43:35 +010073 id_search_module: {
74 executor: 'constant-vus',
75 exec: 'id_search_module',
76 vus: 3,
77 duration: DURATION,
78 },
79 cm_search_module: {
80 executor: 'constant-vus',
81 exec: 'cm_search_module',
82 vus: 3,
83 duration: DURATION,
84 },
halil.cakal65b870b2024-07-25 11:12:29 +010085 data_operation_send_async_http_request: {
86 executor: 'constant-arrival-rate',
87 exec: 'data_operation_send_async_http_request',
88 duration: DURATION,
89 rate: 1,
90 timeUnit: '1s',
91 preAllocatedVUs: 1,
92 },
93 data_operation_async_batch_read: {
94 executor: 'constant-arrival-rate',
95 exec: 'data_operation_async_batch_read',
96 duration: DURATION,
97 rate: 1,
98 timeUnit: '1s',
99 preAllocatedVUs: 1,
100 }
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100101 },
102 thresholds: {
103 'cmhandles_created_per_second': ['value >= 22'],
104 'cmhandles_deleted_per_second': ['value >= 22'],
danielhanrahandbe7b662024-07-16 11:47:24 +0100105 'ncmp_overhead_passthrough_read': ['avg <= 100'],
seanbeirne28559522024-07-19 16:55:06 +0100106 'ncmp_overhead_passthrough_read_alt_id': ['avg <= 100'],
danielhanrahandbe7b662024-07-16 11:47:24 +0100107 'ncmp_overhead_passthrough_write': ['avg <= 100'],
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100108 'http_req_duration{scenario:id_search_module}': ['avg <= 625'],
109 'http_req_duration{scenario:cm_search_module}': ['avg <= 13000'],
danielhanrahandbe7b662024-07-16 11:47:24 +0100110 'http_req_failed{scenario:id_search_module}': ['rate == 0'],
111 'http_req_failed{scenario:cm_search_module}': ['rate == 0'],
112 'http_req_failed{scenario:passthrough_read}': ['rate == 0'],
113 'http_req_failed{scenario:passthrough_write}': ['rate == 0'],
halil.cakal1745d202024-08-06 14:02:49 +0100114 'http_req_failed{group:::setup}':['rate == 0'],
115 'http_req_failed{group:::teardown}':['rate == 0'],
halil.cakal65b870b2024-07-25 11:12:29 +0100116 'http_req_failed{scenario:data_operation_send_async_http_request}': ['rate == 0'],
117 'kafka_reader_error_count{scenario:data_operation_consume_kafka_responses}': ['count == 0'],
118 'data_operations_batch_read_cmhandles_per_second': ['avg >= 150'],
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100119 },
120};
121
122export function setup() {
halil.cakal1745d202024-08-06 14:02:49 +0100123 const startTimeInMillis = Date.now();
124
125 const TOTAL_BATCHES = Math.ceil(TOTAL_CM_HANDLES / REGISTRATION_BATCH_SIZE);
126 for (let batchNumber = 0; batchNumber < TOTAL_BATCHES; batchNumber++) {
127 const nextBatchOfCmHandleIds = makeBatchOfCmHandleIds(REGISTRATION_BATCH_SIZE, batchNumber);
128 const response = createCmHandles(nextBatchOfCmHandleIds);
129 check(response, { 'create CM-handles status equals 200': (r) => r.status === 200 });
130 }
131
132 waitForAllCmHandlesToBeReady();
133
134 const endTimeInMillis = Date.now();
135 const totalRegistrationTimeInSeconds = (endTimeInMillis - startTimeInMillis) / 1000.0;
136
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100137 cmHandlesCreatedPerSecondGauge.add(TOTAL_CM_HANDLES / totalRegistrationTimeInSeconds);
138}
139
140export function teardown() {
halil.cakal1745d202024-08-06 14:02:49 +0100141 const startTimeInMillis = Date.now();
142
143 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);
147 check(response, { 'delete CM-handles status equals 200': (r) => r.status === 200 });
148 }
149
150 const endTimeInMillis = Date.now();
151 const totalDeregistrationTimeInSeconds = (endTimeInMillis - startTimeInMillis) / 1000.0;
152
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100153 cmHandlesDeletedPerSecondGauge.add(TOTAL_CM_HANDLES / totalDeregistrationTimeInSeconds);
154}
155
156export function passthrough_read() {
157 const response = passthroughRead();
158 check(response, { 'passthrough read status equals 200': (r) => r.status === 200 });
danielhanrahandbe7b662024-07-16 11:47:24 +0100159 const overhead = response.timings.duration - READ_DATA_FOR_CM_HANDLE_DELAY_MS;
160 passthroughReadNcmpOverheadTrend.add(overhead);
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100161}
162
seanbeirne28559522024-07-19 16:55:06 +0100163export function passthrough_read_alt_id() {
164 const response = passthroughReadWithAltId();
165 check(response, { 'passthrough read with alternate Id status equals 200': (r) => r.status === 200 });
166 const overhead = response.timings.duration - READ_DATA_FOR_CM_HANDLE_DELAY_MS;
167 passthroughReadNcmpOverheadTrendWithAlternateId.add(overhead);
168}
169
halil.cakalfcc81ee2024-07-11 14:54:57 +0100170export function passthrough_write() {
171 const response = passthroughWrite();
danielhanrahandf584562024-07-25 16:20:15 +0100172 check(response, { 'passthrough write status equals 201': (r) => r.status === 201 });
danielhanrahandbe7b662024-07-16 11:47:24 +0100173 const overhead = response.timings.duration - WRITE_DATA_FOR_CM_HANDLE_DELAY_MS;
174 passthroughWriteNcmpOverheadTrend.add(overhead);
halil.cakalfcc81ee2024-07-11 14:54:57 +0100175}
176
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100177export function id_search_module() {
178 const response = executeCmHandleIdSearch('module');
179 check(response, { 'module ID search status equals 200': (r) => r.status === 200 });
180 check(JSON.parse(response.body), { 'module ID search returned expected CM-handles': (arr) => arr.length === TOTAL_CM_HANDLES });
181}
182
183export function cm_search_module() {
184 const response = executeCmHandleSearch('module');
185 check(response, { 'module search status equals 200': (r) => r.status === 200 });
186 check(JSON.parse(response.body), { 'module search returned expected CM-handles': (arr) => arr.length === TOTAL_CM_HANDLES });
187}
188
halil.cakal65b870b2024-07-25 11:12:29 +0100189export function data_operation_send_async_http_request() {
190 const nextBatchOfCmHandleIds = makeBatchOfCmHandleIds(DATA_OPERATION_READ_BATCH_SIZE,1);
191 const response = batchRead(nextBatchOfCmHandleIds)
192 check(response, { 'data operation batch read status equals 200': (r) => r.status === 200 });
193}
194
195export function data_operation_async_batch_read() {
196 try {
197 let messages = reader.consume({ limit: DATA_OPERATION_READ_BATCH_SIZE });
198 dataOperationsBatchReadCmHandlePerSecondTrend.add(messages.length);
199 } catch (error) {
200 dataOperationsBatchReadCmHandlePerSecondTrend.add(0);
201 console.error(error);
202 }
203}
204
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100205export function handleSummary(data) {
206 return {
207 stdout: makeCustomSummaryReport(data, options),
208 };
209}