blob: d7e4405393118bf5acba0e0d85323fcbfbc5d2fe [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';
seanbeirne28559522024-07-19 16:55:06 +010030import { passthroughRead, passthroughReadWithAltId, passthroughWrite, batchRead } from './common/passthrough-crud.js';
halil.cakal65b870b2024-07-25 11:12:29 +010031import {
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');
seanbeirne28559522024-07-19 16:55:06 +010038let passthroughReadNcmpOverheadTrendWithAlternateId = new Trend('ncmp_overhead_passthrough_read_alt_id');
danielhanrahandbe7b662024-07-16 11:47:24 +010039let passthroughWriteNcmpOverheadTrend = new Trend('ncmp_overhead_passthrough_write');
halil.cakal65b870b2024-07-25 11:12:29 +010040let dataOperationsBatchReadCmHandlePerSecondTrend = new Trend('data_operations_batch_read_cmhandles_per_second');
41
42const reader = new Reader({
43 brokers: KAFKA_BOOTSTRAP_SERVERS,
44 topic: TOPIC_DATA_OPERATIONS_BATCH_READ,
45});
danielhanrahan4e9f68c2024-06-28 13:43:35 +010046
47const DURATION = '15m';
48
49export const options = {
50 setupTimeout: '6m',
51 teardownTimeout: '6m',
52 scenarios: {
53 passthrough_read: {
54 executor: 'constant-vus',
55 exec: 'passthrough_read',
56 vus: 10,
57 duration: DURATION,
58 },
seanbeirne28559522024-07-19 16:55:06 +010059 passthrough_read_alt_id: {
60 executor: 'constant-vus',
61 exec: 'passthrough_read_alt_id',
62 vus: 1,
63 duration: DURATION,
64 },
halil.cakalfcc81ee2024-07-11 14:54:57 +010065 passthrough_write: {
66 executor: 'constant-vus',
67 exec: 'passthrough_write',
68 vus: 10,
69 duration: DURATION,
70 },
danielhanrahan4e9f68c2024-06-28 13:43:35 +010071 id_search_module: {
72 executor: 'constant-vus',
73 exec: 'id_search_module',
74 vus: 3,
75 duration: DURATION,
76 },
77 cm_search_module: {
78 executor: 'constant-vus',
79 exec: 'cm_search_module',
80 vus: 3,
81 duration: DURATION,
82 },
halil.cakal65b870b2024-07-25 11:12:29 +010083 data_operation_send_async_http_request: {
84 executor: 'constant-arrival-rate',
85 exec: 'data_operation_send_async_http_request',
86 duration: DURATION,
87 rate: 1,
88 timeUnit: '1s',
89 preAllocatedVUs: 1,
90 },
91 data_operation_async_batch_read: {
92 executor: 'constant-arrival-rate',
93 exec: 'data_operation_async_batch_read',
94 duration: DURATION,
95 rate: 1,
96 timeUnit: '1s',
97 preAllocatedVUs: 1,
98 }
danielhanrahan4e9f68c2024-06-28 13:43:35 +010099 },
100 thresholds: {
101 'cmhandles_created_per_second': ['value >= 22'],
102 'cmhandles_deleted_per_second': ['value >= 22'],
halil.cakalfcc81ee2024-07-11 14:54:57 +0100103 'http_reqs{scenario:passthrough_write}': ['rate >= 13'],
halil.cakal90464762024-07-09 17:43:25 +0100104 'http_reqs{scenario:passthrough_read}': ['rate >= 25'],
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.cakal65b870b2024-07-25 11:12:29 +0100114 'http_req_failed{scenario:data_operation_send_async_http_request}': ['rate == 0'],
115 'kafka_reader_error_count{scenario:data_operation_consume_kafka_responses}': ['count == 0'],
116 'data_operations_batch_read_cmhandles_per_second': ['avg >= 150'],
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100117 },
118};
119
120export function setup() {
121 const totalRegistrationTimeInSeconds = recordTimeInSeconds(registerAllCmHandles);
122 cmHandlesCreatedPerSecondGauge.add(TOTAL_CM_HANDLES / totalRegistrationTimeInSeconds);
123}
124
125export function teardown() {
126 const totalDeregistrationTimeInSeconds = recordTimeInSeconds(deregisterAllCmHandles);
127 cmHandlesDeletedPerSecondGauge.add(TOTAL_CM_HANDLES / totalDeregistrationTimeInSeconds);
128}
129
130export function passthrough_read() {
131 const response = passthroughRead();
132 check(response, { 'passthrough read status equals 200': (r) => r.status === 200 });
danielhanrahandbe7b662024-07-16 11:47:24 +0100133 const overhead = response.timings.duration - READ_DATA_FOR_CM_HANDLE_DELAY_MS;
134 passthroughReadNcmpOverheadTrend.add(overhead);
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100135}
136
seanbeirne28559522024-07-19 16:55:06 +0100137export function passthrough_read_alt_id() {
138 const response = passthroughReadWithAltId();
139 check(response, { 'passthrough read with alternate Id status equals 200': (r) => r.status === 200 });
140 const overhead = response.timings.duration - READ_DATA_FOR_CM_HANDLE_DELAY_MS;
141 passthroughReadNcmpOverheadTrendWithAlternateId.add(overhead);
142}
143
halil.cakalfcc81ee2024-07-11 14:54:57 +0100144export function passthrough_write() {
145 const response = passthroughWrite();
danielhanrahandf584562024-07-25 16:20:15 +0100146 check(response, { 'passthrough write status equals 201': (r) => r.status === 201 });
danielhanrahandbe7b662024-07-16 11:47:24 +0100147 const overhead = response.timings.duration - WRITE_DATA_FOR_CM_HANDLE_DELAY_MS;
148 passthroughWriteNcmpOverheadTrend.add(overhead);
halil.cakalfcc81ee2024-07-11 14:54:57 +0100149}
150
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100151export function id_search_module() {
152 const response = executeCmHandleIdSearch('module');
153 check(response, { 'module ID search status equals 200': (r) => r.status === 200 });
154 check(JSON.parse(response.body), { 'module ID search returned expected CM-handles': (arr) => arr.length === TOTAL_CM_HANDLES });
155}
156
157export function cm_search_module() {
158 const response = executeCmHandleSearch('module');
159 check(response, { 'module search status equals 200': (r) => r.status === 200 });
160 check(JSON.parse(response.body), { 'module search returned expected CM-handles': (arr) => arr.length === TOTAL_CM_HANDLES });
161}
162
halil.cakal65b870b2024-07-25 11:12:29 +0100163export function data_operation_send_async_http_request() {
164 const nextBatchOfCmHandleIds = makeBatchOfCmHandleIds(DATA_OPERATION_READ_BATCH_SIZE,1);
165 const response = batchRead(nextBatchOfCmHandleIds)
166 check(response, { 'data operation batch read status equals 200': (r) => r.status === 200 });
167}
168
169export function data_operation_async_batch_read() {
170 try {
171 let messages = reader.consume({ limit: DATA_OPERATION_READ_BATCH_SIZE });
172 dataOperationsBatchReadCmHandlePerSecondTrend.add(messages.length);
173 } catch (error) {
174 dataOperationsBatchReadCmHandlePerSecondTrend.add(0);
175 console.error(error);
176 }
177}
178
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100179export function handleSummary(data) {
180 return {
181 stdout: makeCustomSummaryReport(data, options),
182 };
183}