blob: f4a44dba68afc112eba3e62fdfab45cbdad1a281 [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,
26 makeCustomSummaryReport, recordTimeInSeconds, makeBatchOfCmHandleIds, DATA_OPERATION_READ_BATCH_SIZE,
27 TOPIC_DATA_OPERATIONS_BATCH_READ, KAFKA_BOOTSTRAP_SERVERS
28} from './common/utils.js';
danielhanrahan4e9f68c2024-06-28 13:43:35 +010029import { registerAllCmHandles, deregisterAllCmHandles } from './common/cmhandle-crud.js';
30import { 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
33let cmHandlesCreatedPerSecondGauge = new Gauge('cmhandles_created_per_second');
34let cmHandlesDeletedPerSecondGauge = new Gauge('cmhandles_deleted_per_second');
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);
halil.cakal65b870b2024-07-25 11:12:29 +010038let dataOperationsBatchReadCmHandlePerSecondTrend = new Trend('data_operations_batch_read_cmhandles_per_second');
39
40const reader = new Reader({
41 brokers: KAFKA_BOOTSTRAP_SERVERS,
42 topic: TOPIC_DATA_OPERATIONS_BATCH_READ,
43});
danielhanrahan4e9f68c2024-06-28 13:43:35 +010044
45const DURATION = '15m';
46
47export const options = {
48 setupTimeout: '6m',
49 teardownTimeout: '6m',
50 scenarios: {
51 passthrough_read: {
52 executor: 'constant-vus',
53 exec: 'passthrough_read',
danielhanrahana1cdf732024-08-16 11:09:25 +010054 vus: 9,
danielhanrahan4e9f68c2024-06-28 13:43:35 +010055 duration: DURATION,
56 },
seanbeirne28559522024-07-19 16:55:06 +010057 passthrough_read_alt_id: {
58 executor: 'constant-vus',
59 exec: 'passthrough_read_alt_id',
60 vus: 1,
61 duration: DURATION,
62 },
halil.cakalfcc81ee2024-07-11 14:54:57 +010063 passthrough_write: {
64 executor: 'constant-vus',
65 exec: 'passthrough_write',
66 vus: 10,
67 duration: DURATION,
68 },
danielhanrahan4e9f68c2024-06-28 13:43:35 +010069 id_search_module: {
70 executor: 'constant-vus',
71 exec: 'id_search_module',
72 vus: 3,
73 duration: DURATION,
74 },
75 cm_search_module: {
76 executor: 'constant-vus',
77 exec: 'cm_search_module',
78 vus: 3,
79 duration: DURATION,
80 },
halil.cakal65b870b2024-07-25 11:12:29 +010081 data_operation_send_async_http_request: {
82 executor: 'constant-arrival-rate',
83 exec: 'data_operation_send_async_http_request',
84 duration: DURATION,
85 rate: 1,
86 timeUnit: '1s',
87 preAllocatedVUs: 1,
88 },
89 data_operation_async_batch_read: {
90 executor: 'constant-arrival-rate',
91 exec: 'data_operation_async_batch_read',
92 duration: DURATION,
93 rate: 1,
94 timeUnit: '1s',
95 preAllocatedVUs: 1,
96 }
danielhanrahan4e9f68c2024-06-28 13:43:35 +010097 },
98 thresholds: {
99 'cmhandles_created_per_second': ['value >= 22'],
100 'cmhandles_deleted_per_second': ['value >= 22'],
danielhanrahandbe7b662024-07-16 11:47:24 +0100101 'ncmp_overhead_passthrough_read': ['avg <= 100'],
seanbeirne28559522024-07-19 16:55:06 +0100102 'ncmp_overhead_passthrough_read_alt_id': ['avg <= 100'],
danielhanrahandbe7b662024-07-16 11:47:24 +0100103 'ncmp_overhead_passthrough_write': ['avg <= 100'],
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100104 'http_req_duration{scenario:id_search_module}': ['avg <= 625'],
105 'http_req_duration{scenario:cm_search_module}': ['avg <= 13000'],
danielhanrahandbe7b662024-07-16 11:47:24 +0100106 'http_req_failed{scenario:id_search_module}': ['rate == 0'],
107 'http_req_failed{scenario:cm_search_module}': ['rate == 0'],
108 'http_req_failed{scenario:passthrough_read}': ['rate == 0'],
109 'http_req_failed{scenario:passthrough_write}': ['rate == 0'],
halil.cakal65b870b2024-07-25 11:12:29 +0100110 'http_req_failed{scenario:data_operation_send_async_http_request}': ['rate == 0'],
111 'kafka_reader_error_count{scenario:data_operation_consume_kafka_responses}': ['count == 0'],
112 'data_operations_batch_read_cmhandles_per_second': ['avg >= 150'],
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100113 },
114};
115
116export function setup() {
117 const totalRegistrationTimeInSeconds = recordTimeInSeconds(registerAllCmHandles);
118 cmHandlesCreatedPerSecondGauge.add(TOTAL_CM_HANDLES / totalRegistrationTimeInSeconds);
119}
120
121export function teardown() {
122 const totalDeregistrationTimeInSeconds = recordTimeInSeconds(deregisterAllCmHandles);
123 cmHandlesDeletedPerSecondGauge.add(TOTAL_CM_HANDLES / totalDeregistrationTimeInSeconds);
124}
125
126export function passthrough_read() {
127 const response = passthroughRead();
128 check(response, { 'passthrough read status equals 200': (r) => r.status === 200 });
danielhanrahandbe7b662024-07-16 11:47:24 +0100129 const overhead = response.timings.duration - READ_DATA_FOR_CM_HANDLE_DELAY_MS;
130 passthroughReadNcmpOverheadTrend.add(overhead);
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100131}
132
seanbeirne28559522024-07-19 16:55:06 +0100133export function passthrough_read_alt_id() {
134 const response = passthroughReadWithAltId();
135 check(response, { 'passthrough read with alternate Id status equals 200': (r) => r.status === 200 });
136 const overhead = response.timings.duration - READ_DATA_FOR_CM_HANDLE_DELAY_MS;
137 passthroughReadNcmpOverheadTrendWithAlternateId.add(overhead);
138}
139
halil.cakalfcc81ee2024-07-11 14:54:57 +0100140export function passthrough_write() {
141 const response = passthroughWrite();
danielhanrahandf584562024-07-25 16:20:15 +0100142 check(response, { 'passthrough write status equals 201': (r) => r.status === 201 });
danielhanrahandbe7b662024-07-16 11:47:24 +0100143 const overhead = response.timings.duration - WRITE_DATA_FOR_CM_HANDLE_DELAY_MS;
144 passthroughWriteNcmpOverheadTrend.add(overhead);
halil.cakalfcc81ee2024-07-11 14:54:57 +0100145}
146
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100147export function id_search_module() {
148 const response = executeCmHandleIdSearch('module');
149 check(response, { 'module ID search status equals 200': (r) => r.status === 200 });
150 check(JSON.parse(response.body), { 'module ID search returned expected CM-handles': (arr) => arr.length === TOTAL_CM_HANDLES });
151}
152
153export function cm_search_module() {
154 const response = executeCmHandleSearch('module');
155 check(response, { 'module search status equals 200': (r) => r.status === 200 });
156 check(JSON.parse(response.body), { 'module search returned expected CM-handles': (arr) => arr.length === TOTAL_CM_HANDLES });
157}
158
halil.cakal65b870b2024-07-25 11:12:29 +0100159export function data_operation_send_async_http_request() {
160 const nextBatchOfCmHandleIds = makeBatchOfCmHandleIds(DATA_OPERATION_READ_BATCH_SIZE,1);
161 const response = batchRead(nextBatchOfCmHandleIds)
162 check(response, { 'data operation batch read status equals 200': (r) => r.status === 200 });
163}
164
165export function data_operation_async_batch_read() {
166 try {
167 let messages = reader.consume({ limit: DATA_OPERATION_READ_BATCH_SIZE });
168 dataOperationsBatchReadCmHandlePerSecondTrend.add(messages.length);
169 } catch (error) {
170 dataOperationsBatchReadCmHandlePerSecondTrend.add(0);
171 console.error(error);
172 }
173}
174
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100175export function handleSummary(data) {
176 return {
177 stdout: makeCustomSummaryReport(data, options),
178 };
179}