danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 21 | import { check } from 'k6'; |
danielhanrahan | dbe7b66 | 2024-07-16 11:47:24 +0100 | [diff] [blame] | 22 | import { Gauge, Trend } from 'k6/metrics'; |
halil.cakal | 65b870b | 2024-07-25 11:12:29 +0100 | [diff] [blame] | 23 | import { |
| 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'; |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 28 | import { registerAllCmHandles, deregisterAllCmHandles } from './common/cmhandle-crud.js'; |
| 29 | import { executeCmHandleSearch, executeCmHandleIdSearch } from './common/search-base.js'; |
seanbeirne | 2855952 | 2024-07-19 16:55:06 +0100 | [diff] [blame] | 30 | import { passthroughRead, passthroughReadWithAltId, passthroughWrite, batchRead } from './common/passthrough-crud.js'; |
halil.cakal | 65b870b | 2024-07-25 11:12:29 +0100 | [diff] [blame] | 31 | import { |
| 32 | Reader, |
| 33 | } from 'k6/x/kafka'; |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 34 | |
| 35 | let cmHandlesCreatedPerSecondGauge = new Gauge('cmhandles_created_per_second'); |
| 36 | let cmHandlesDeletedPerSecondGauge = new Gauge('cmhandles_deleted_per_second'); |
danielhanrahan | dbe7b66 | 2024-07-16 11:47:24 +0100 | [diff] [blame] | 37 | let passthroughReadNcmpOverheadTrend = new Trend('ncmp_overhead_passthrough_read'); |
seanbeirne | 2855952 | 2024-07-19 16:55:06 +0100 | [diff] [blame] | 38 | let passthroughReadNcmpOverheadTrendWithAlternateId = new Trend('ncmp_overhead_passthrough_read_alt_id'); |
danielhanrahan | dbe7b66 | 2024-07-16 11:47:24 +0100 | [diff] [blame] | 39 | let passthroughWriteNcmpOverheadTrend = new Trend('ncmp_overhead_passthrough_write'); |
halil.cakal | 65b870b | 2024-07-25 11:12:29 +0100 | [diff] [blame] | 40 | let dataOperationsBatchReadCmHandlePerSecondTrend = new Trend('data_operations_batch_read_cmhandles_per_second'); |
| 41 | |
| 42 | const reader = new Reader({ |
| 43 | brokers: KAFKA_BOOTSTRAP_SERVERS, |
| 44 | topic: TOPIC_DATA_OPERATIONS_BATCH_READ, |
| 45 | }); |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 46 | |
| 47 | const DURATION = '15m'; |
| 48 | |
| 49 | export 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 | }, |
seanbeirne | 2855952 | 2024-07-19 16:55:06 +0100 | [diff] [blame] | 59 | passthrough_read_alt_id: { |
| 60 | executor: 'constant-vus', |
| 61 | exec: 'passthrough_read_alt_id', |
| 62 | vus: 1, |
| 63 | duration: DURATION, |
| 64 | }, |
halil.cakal | fcc81ee | 2024-07-11 14:54:57 +0100 | [diff] [blame] | 65 | passthrough_write: { |
| 66 | executor: 'constant-vus', |
| 67 | exec: 'passthrough_write', |
| 68 | vus: 10, |
| 69 | duration: DURATION, |
| 70 | }, |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 71 | 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.cakal | 65b870b | 2024-07-25 11:12:29 +0100 | [diff] [blame] | 83 | 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 | } |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 99 | }, |
| 100 | thresholds: { |
| 101 | 'cmhandles_created_per_second': ['value >= 22'], |
| 102 | 'cmhandles_deleted_per_second': ['value >= 22'], |
halil.cakal | fcc81ee | 2024-07-11 14:54:57 +0100 | [diff] [blame] | 103 | 'http_reqs{scenario:passthrough_write}': ['rate >= 13'], |
halil.cakal | 9046476 | 2024-07-09 17:43:25 +0100 | [diff] [blame] | 104 | 'http_reqs{scenario:passthrough_read}': ['rate >= 25'], |
danielhanrahan | dbe7b66 | 2024-07-16 11:47:24 +0100 | [diff] [blame] | 105 | 'ncmp_overhead_passthrough_read': ['avg <= 100'], |
seanbeirne | 2855952 | 2024-07-19 16:55:06 +0100 | [diff] [blame] | 106 | 'ncmp_overhead_passthrough_read_alt_id': ['avg <= 100'], |
danielhanrahan | dbe7b66 | 2024-07-16 11:47:24 +0100 | [diff] [blame] | 107 | 'ncmp_overhead_passthrough_write': ['avg <= 100'], |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 108 | 'http_req_duration{scenario:id_search_module}': ['avg <= 625'], |
| 109 | 'http_req_duration{scenario:cm_search_module}': ['avg <= 13000'], |
danielhanrahan | dbe7b66 | 2024-07-16 11:47:24 +0100 | [diff] [blame] | 110 | '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.cakal | 65b870b | 2024-07-25 11:12:29 +0100 | [diff] [blame] | 114 | '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'], |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 117 | }, |
| 118 | }; |
| 119 | |
| 120 | export function setup() { |
| 121 | const totalRegistrationTimeInSeconds = recordTimeInSeconds(registerAllCmHandles); |
| 122 | cmHandlesCreatedPerSecondGauge.add(TOTAL_CM_HANDLES / totalRegistrationTimeInSeconds); |
| 123 | } |
| 124 | |
| 125 | export function teardown() { |
| 126 | const totalDeregistrationTimeInSeconds = recordTimeInSeconds(deregisterAllCmHandles); |
| 127 | cmHandlesDeletedPerSecondGauge.add(TOTAL_CM_HANDLES / totalDeregistrationTimeInSeconds); |
| 128 | } |
| 129 | |
| 130 | export function passthrough_read() { |
| 131 | const response = passthroughRead(); |
| 132 | check(response, { 'passthrough read status equals 200': (r) => r.status === 200 }); |
danielhanrahan | dbe7b66 | 2024-07-16 11:47:24 +0100 | [diff] [blame] | 133 | const overhead = response.timings.duration - READ_DATA_FOR_CM_HANDLE_DELAY_MS; |
| 134 | passthroughReadNcmpOverheadTrend.add(overhead); |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 135 | } |
| 136 | |
seanbeirne | 2855952 | 2024-07-19 16:55:06 +0100 | [diff] [blame] | 137 | export 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.cakal | fcc81ee | 2024-07-11 14:54:57 +0100 | [diff] [blame] | 144 | export function passthrough_write() { |
| 145 | const response = passthroughWrite(); |
danielhanrahan | df58456 | 2024-07-25 16:20:15 +0100 | [diff] [blame] | 146 | check(response, { 'passthrough write status equals 201': (r) => r.status === 201 }); |
danielhanrahan | dbe7b66 | 2024-07-16 11:47:24 +0100 | [diff] [blame] | 147 | const overhead = response.timings.duration - WRITE_DATA_FOR_CM_HANDLE_DELAY_MS; |
| 148 | passthroughWriteNcmpOverheadTrend.add(overhead); |
halil.cakal | fcc81ee | 2024-07-11 14:54:57 +0100 | [diff] [blame] | 149 | } |
| 150 | |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 151 | export 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 | |
| 157 | export 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.cakal | 65b870b | 2024-07-25 11:12:29 +0100 | [diff] [blame] | 163 | export 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 | |
| 169 | export 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 | |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 179 | export function handleSummary(data) { |
| 180 | return { |
| 181 | stdout: makeCustomSummaryReport(data, options), |
| 182 | }; |
| 183 | } |