blob: 8ff9ec50b4054ac6bcf63d1a2a5ebb31e719e473 [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';
halil.cakal65b870b2024-07-25 11:12:29 +010023import {
24 TOTAL_CM_HANDLES, READ_DATA_FOR_CM_HANDLE_DELAY_MS, WRITE_DATA_FOR_CM_HANDLE_DELAY_MS,
25 makeCustomSummaryReport, recordTimeInSeconds, makeBatchOfCmHandleIds, DATA_OPERATION_READ_BATCH_SIZE,
26 TOPIC_DATA_OPERATIONS_BATCH_READ, KAFKA_BOOTSTRAP_SERVERS
27} from './common/utils.js';
danielhanrahan4e9f68c2024-06-28 13:43:35 +010028import { registerAllCmHandles, deregisterAllCmHandles } from './common/cmhandle-crud.js';
29import { executeCmHandleSearch, executeCmHandleIdSearch } from './common/search-base.js';
halil.cakal65b870b2024-07-25 11:12:29 +010030import { passthroughRead, passthroughWrite, batchRead } from './common/passthrough-crud.js';
31import {
32 Reader,
33} from 'k6/x/kafka';
danielhanrahan4e9f68c2024-06-28 13:43:35 +010034
35let cmHandlesCreatedPerSecondGauge = new Gauge('cmhandles_created_per_second');
36let cmHandlesDeletedPerSecondGauge = new Gauge('cmhandles_deleted_per_second');
danielhanrahandbe7b662024-07-16 11:47:24 +010037let passthroughReadNcmpOverheadTrend = new Trend('ncmp_overhead_passthrough_read');
38let passthroughWriteNcmpOverheadTrend = new Trend('ncmp_overhead_passthrough_write');
halil.cakal65b870b2024-07-25 11:12:29 +010039let dataOperationsBatchReadCmHandlePerSecondTrend = new Trend('data_operations_batch_read_cmhandles_per_second');
40
41const reader = new Reader({
42 brokers: KAFKA_BOOTSTRAP_SERVERS,
43 topic: TOPIC_DATA_OPERATIONS_BATCH_READ,
44});
danielhanrahan4e9f68c2024-06-28 13:43:35 +010045
46const DURATION = '15m';
47
48export const options = {
49 setupTimeout: '6m',
50 teardownTimeout: '6m',
51 scenarios: {
52 passthrough_read: {
53 executor: 'constant-vus',
54 exec: 'passthrough_read',
55 vus: 10,
56 duration: DURATION,
57 },
halil.cakalfcc81ee2024-07-11 14:54:57 +010058 passthrough_write: {
59 executor: 'constant-vus',
60 exec: 'passthrough_write',
61 vus: 10,
62 duration: DURATION,
63 },
danielhanrahan4e9f68c2024-06-28 13:43:35 +010064 id_search_module: {
65 executor: 'constant-vus',
66 exec: 'id_search_module',
67 vus: 3,
68 duration: DURATION,
69 },
70 cm_search_module: {
71 executor: 'constant-vus',
72 exec: 'cm_search_module',
73 vus: 3,
74 duration: DURATION,
75 },
halil.cakal65b870b2024-07-25 11:12:29 +010076 data_operation_send_async_http_request: {
77 executor: 'constant-arrival-rate',
78 exec: 'data_operation_send_async_http_request',
79 duration: DURATION,
80 rate: 1,
81 timeUnit: '1s',
82 preAllocatedVUs: 1,
83 },
84 data_operation_async_batch_read: {
85 executor: 'constant-arrival-rate',
86 exec: 'data_operation_async_batch_read',
87 duration: DURATION,
88 rate: 1,
89 timeUnit: '1s',
90 preAllocatedVUs: 1,
91 }
danielhanrahan4e9f68c2024-06-28 13:43:35 +010092 },
93 thresholds: {
94 'cmhandles_created_per_second': ['value >= 22'],
95 'cmhandles_deleted_per_second': ['value >= 22'],
halil.cakalfcc81ee2024-07-11 14:54:57 +010096 'http_reqs{scenario:passthrough_write}': ['rate >= 13'],
halil.cakal90464762024-07-09 17:43:25 +010097 'http_reqs{scenario:passthrough_read}': ['rate >= 25'],
danielhanrahandbe7b662024-07-16 11:47:24 +010098 'ncmp_overhead_passthrough_read': ['avg <= 100'],
99 'ncmp_overhead_passthrough_write': ['avg <= 100'],
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100100 'http_req_duration{scenario:id_search_module}': ['avg <= 625'],
101 'http_req_duration{scenario:cm_search_module}': ['avg <= 13000'],
danielhanrahandbe7b662024-07-16 11:47:24 +0100102 'http_req_failed{scenario:id_search_module}': ['rate == 0'],
103 'http_req_failed{scenario:cm_search_module}': ['rate == 0'],
104 'http_req_failed{scenario:passthrough_read}': ['rate == 0'],
105 'http_req_failed{scenario:passthrough_write}': ['rate == 0'],
halil.cakal65b870b2024-07-25 11:12:29 +0100106 'http_req_failed{scenario:data_operation_send_async_http_request}': ['rate == 0'],
107 'kafka_reader_error_count{scenario:data_operation_consume_kafka_responses}': ['count == 0'],
108 'data_operations_batch_read_cmhandles_per_second': ['avg >= 150'],
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100109 },
110};
111
112export function setup() {
113 const totalRegistrationTimeInSeconds = recordTimeInSeconds(registerAllCmHandles);
114 cmHandlesCreatedPerSecondGauge.add(TOTAL_CM_HANDLES / totalRegistrationTimeInSeconds);
115}
116
117export function teardown() {
118 const totalDeregistrationTimeInSeconds = recordTimeInSeconds(deregisterAllCmHandles);
119 cmHandlesDeletedPerSecondGauge.add(TOTAL_CM_HANDLES / totalDeregistrationTimeInSeconds);
120}
121
122export function passthrough_read() {
123 const response = passthroughRead();
124 check(response, { 'passthrough read status equals 200': (r) => r.status === 200 });
danielhanrahandbe7b662024-07-16 11:47:24 +0100125 const overhead = response.timings.duration - READ_DATA_FOR_CM_HANDLE_DELAY_MS;
126 passthroughReadNcmpOverheadTrend.add(overhead);
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100127}
128
halil.cakalfcc81ee2024-07-11 14:54:57 +0100129export function passthrough_write() {
130 const response = passthroughWrite();
danielhanrahandf584562024-07-25 16:20:15 +0100131 check(response, { 'passthrough write status equals 201': (r) => r.status === 201 });
danielhanrahandbe7b662024-07-16 11:47:24 +0100132 const overhead = response.timings.duration - WRITE_DATA_FOR_CM_HANDLE_DELAY_MS;
133 passthroughWriteNcmpOverheadTrend.add(overhead);
halil.cakalfcc81ee2024-07-11 14:54:57 +0100134}
135
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100136export function id_search_module() {
137 const response = executeCmHandleIdSearch('module');
138 check(response, { 'module ID search status equals 200': (r) => r.status === 200 });
139 check(JSON.parse(response.body), { 'module ID search returned expected CM-handles': (arr) => arr.length === TOTAL_CM_HANDLES });
140}
141
142export function cm_search_module() {
143 const response = executeCmHandleSearch('module');
144 check(response, { 'module search status equals 200': (r) => r.status === 200 });
145 check(JSON.parse(response.body), { 'module search returned expected CM-handles': (arr) => arr.length === TOTAL_CM_HANDLES });
146}
147
halil.cakal65b870b2024-07-25 11:12:29 +0100148export function data_operation_send_async_http_request() {
149 const nextBatchOfCmHandleIds = makeBatchOfCmHandleIds(DATA_OPERATION_READ_BATCH_SIZE,1);
150 const response = batchRead(nextBatchOfCmHandleIds)
151 check(response, { 'data operation batch read status equals 200': (r) => r.status === 200 });
152}
153
154export function data_operation_async_batch_read() {
155 try {
156 let messages = reader.consume({ limit: DATA_OPERATION_READ_BATCH_SIZE });
157 dataOperationsBatchReadCmHandlePerSecondTrend.add(messages.length);
158 } catch (error) {
159 dataOperationsBatchReadCmHandlePerSecondTrend.add(0);
160 console.error(error);
161 }
162}
163
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100164export function handleSummary(data) {
165 return {
166 stdout: makeCustomSummaryReport(data, options),
167 };
168}