blob: 1d084f21e313470aae77d202e3789189203d76a9 [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';
danielhanrahanf2e1e252024-08-25 21:35:19 +010029import { createCmHandles, deleteCmHandles, waitForAllCmHandlesToBeReady } from './common/cmhandle-crud.js';
danielhanrahan4e9f68c2024-06-28 13:43:35 +010030import { executeCmHandleSearch, executeCmHandleIdSearch } from './common/search-base.js';
seanbeirne28559522024-07-19 16:55:06 +010031import { passthroughRead, passthroughReadWithAltId, passthroughWrite, batchRead } from './common/passthrough-crud.js';
danielhanrahan4e9f68c2024-06-28 13:43:35 +010032
danielhanrahan78894db2024-08-16 13:56:14 +010033let cmHandlesCreatedPerSecondTrend = new Trend('cmhandles_created_per_second', false);
34let cmHandlesDeletedPerSecondTrend = new Trend('cmhandles_deleted_per_second', false);
danielhanrahana1cdf732024-08-16 11:09:25 +010035let passthroughReadNcmpOverheadTrend = new Trend('ncmp_overhead_passthrough_read', true);
36let passthroughReadNcmpOverheadTrendWithAlternateId = new Trend('ncmp_overhead_passthrough_read_alt_id', true);
37let passthroughWriteNcmpOverheadTrend = new Trend('ncmp_overhead_passthrough_write', true);
danielhanrahanf2e1e252024-08-25 21:35:19 +010038let passthroughWriteNcmpOverheadTrendWithAlternateId = new Trend('ncmp_overhead_passthrough_write_alt_id', true);
danielhanrahan78894db2024-08-16 13:56:14 +010039let idSearchDurationTrend = new Trend('id_search_duration', true);
40let cmSearchDurationTrend = new Trend('cm_search_duration', true);
41let dataOperationsBatchReadCmHandlePerSecondTrend = new Trend('data_operations_batch_read_cmhandles_per_second', false);
halil.cakal65b870b2024-07-25 11:12:29 +010042
43const reader = new Reader({
44 brokers: KAFKA_BOOTSTRAP_SERVERS,
45 topic: TOPIC_DATA_OPERATIONS_BATCH_READ,
46});
danielhanrahan4e9f68c2024-06-28 13:43:35 +010047
48const DURATION = '15m';
49
50export const options = {
danielhanrahan4dac1302024-08-30 15:03:06 +010051 setupTimeout: '8m',
danielhanrahan4e9f68c2024-06-28 13:43:35 +010052 teardownTimeout: '6m',
53 scenarios: {
54 passthrough_read: {
55 executor: 'constant-vus',
danielhanrahanf2e1e252024-08-25 21:35:19 +010056 exec: 'executePassthroughReadScenario',
57 vus: 4,
danielhanrahan4e9f68c2024-06-28 13:43:35 +010058 duration: DURATION,
59 },
seanbeirne28559522024-07-19 16:55:06 +010060 passthrough_read_alt_id: {
61 executor: 'constant-vus',
danielhanrahanf2e1e252024-08-25 21:35:19 +010062 exec: 'executePassthroughReadAltIdScenario',
63 vus: 4,
seanbeirne28559522024-07-19 16:55:06 +010064 duration: DURATION,
65 },
halil.cakalfcc81ee2024-07-11 14:54:57 +010066 passthrough_write: {
67 executor: 'constant-vus',
danielhanrahanf2e1e252024-08-25 21:35:19 +010068 exec: 'executePassthroughWriteScenario',
69 vus: 4,
halil.cakalfcc81ee2024-07-11 14:54:57 +010070 duration: DURATION,
71 },
danielhanrahanf2e1e252024-08-25 21:35:19 +010072 passthrough_write_alt_id: {
danielhanrahan4e9f68c2024-06-28 13:43:35 +010073 executor: 'constant-vus',
danielhanrahanf2e1e252024-08-25 21:35:19 +010074 exec: 'executePassthroughWriteAltIdScenario',
75 vus: 4,
danielhanrahan4e9f68c2024-06-28 13:43:35 +010076 duration: DURATION,
77 },
danielhanrahanf2e1e252024-08-25 21:35:19 +010078 cm_handle_id_search: {
danielhanrahan4e9f68c2024-06-28 13:43:35 +010079 executor: 'constant-vus',
danielhanrahanf2e1e252024-08-25 21:35:19 +010080 exec: 'executeCmHandleIdSearchScenario',
81 vus: 5,
82 duration: DURATION,
83 },
84 cm_handle_search: {
85 executor: 'constant-vus',
86 exec: 'executeCmHandleSearchScenario',
87 vus: 5,
danielhanrahan4e9f68c2024-06-28 13:43:35 +010088 duration: DURATION,
89 },
halil.cakal65b870b2024-07-25 11:12:29 +010090 data_operation_send_async_http_request: {
91 executor: 'constant-arrival-rate',
92 exec: 'data_operation_send_async_http_request',
93 duration: DURATION,
94 rate: 1,
95 timeUnit: '1s',
96 preAllocatedVUs: 1,
97 },
98 data_operation_async_batch_read: {
99 executor: 'constant-arrival-rate',
100 exec: 'data_operation_async_batch_read',
101 duration: DURATION,
102 rate: 1,
103 timeUnit: '1s',
104 preAllocatedVUs: 1,
105 }
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'],
danielhanrahan78894db2024-08-16 13:56:14 +0100117 'data_operations_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
danielhanrahanf2e1e252024-08-25 21:35:19 +0100159export function executePassthroughReadScenario() {
160 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
danielhanrahanf2e1e252024-08-25 21:35:19 +0100167export function executePassthroughReadAltIdScenario() {
168 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
danielhanrahanf2e1e252024-08-25 21:35:19 +0100175export function executePassthroughWriteScenario() {
176 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
danielhanrahanf2e1e252024-08-25 21:35:19 +0100183export function executePassthroughWriteAltIdScenario() {
184 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
191export function executeCmHandleIdSearchScenario() {
192 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
danielhanrahanf2e1e252024-08-25 21:35:19 +0100199export function executeCmHandleSearchScenario() {
200 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.cakal65b870b2024-07-25 11:12:29 +0100207export function data_operation_send_async_http_request() {
danielhanrahan78894db2024-08-16 13:56:14 +0100208 const nextBatchOfCmHandleIds = makeBatchOfCmHandleIds(DATA_OPERATION_READ_BATCH_SIZE, 0);
209 const response = batchRead(nextBatchOfCmHandleIds);
halil.cakal65b870b2024-07-25 11:12:29 +0100210 check(response, { 'data operation batch read status equals 200': (r) => r.status === 200 });
211}
212
213export function data_operation_async_batch_read() {
214 try {
215 let messages = reader.consume({ limit: DATA_OPERATION_READ_BATCH_SIZE });
216 dataOperationsBatchReadCmHandlePerSecondTrend.add(messages.length);
217 } catch (error) {
218 dataOperationsBatchReadCmHandlePerSecondTrend.add(0);
219 console.error(error);
220 }
221}
222
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100223export function handleSummary(data) {
224 return {
225 stdout: makeCustomSummaryReport(data, options),
226 };
227}