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'; |
danielhanrahan | a1cdf73 | 2024-08-16 11:09:25 +0100 | [diff] [blame] | 23 | import { Reader } from 'k6/x/kafka'; |
halil.cakal | 65b870b | 2024-07-25 11:12:29 +0100 | [diff] [blame] | 24 | import { |
| 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'; |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 29 | import { registerAllCmHandles, deregisterAllCmHandles } from './common/cmhandle-crud.js'; |
| 30 | import { executeCmHandleSearch, executeCmHandleIdSearch } from './common/search-base.js'; |
seanbeirne | 2855952 | 2024-07-19 16:55:06 +0100 | [diff] [blame] | 31 | import { passthroughRead, passthroughReadWithAltId, passthroughWrite, batchRead } from './common/passthrough-crud.js'; |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 32 | |
| 33 | let cmHandlesCreatedPerSecondGauge = new Gauge('cmhandles_created_per_second'); |
| 34 | let cmHandlesDeletedPerSecondGauge = new Gauge('cmhandles_deleted_per_second'); |
danielhanrahan | a1cdf73 | 2024-08-16 11:09:25 +0100 | [diff] [blame] | 35 | let passthroughReadNcmpOverheadTrend = new Trend('ncmp_overhead_passthrough_read', true); |
| 36 | let passthroughReadNcmpOverheadTrendWithAlternateId = new Trend('ncmp_overhead_passthrough_read_alt_id', true); |
| 37 | let passthroughWriteNcmpOverheadTrend = new Trend('ncmp_overhead_passthrough_write', true); |
halil.cakal | 65b870b | 2024-07-25 11:12:29 +0100 | [diff] [blame] | 38 | let dataOperationsBatchReadCmHandlePerSecondTrend = new Trend('data_operations_batch_read_cmhandles_per_second'); |
| 39 | |
| 40 | const reader = new Reader({ |
| 41 | brokers: KAFKA_BOOTSTRAP_SERVERS, |
| 42 | topic: TOPIC_DATA_OPERATIONS_BATCH_READ, |
| 43 | }); |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 44 | |
| 45 | const DURATION = '15m'; |
| 46 | |
| 47 | export const options = { |
| 48 | setupTimeout: '6m', |
| 49 | teardownTimeout: '6m', |
| 50 | scenarios: { |
| 51 | passthrough_read: { |
| 52 | executor: 'constant-vus', |
| 53 | exec: 'passthrough_read', |
danielhanrahan | a1cdf73 | 2024-08-16 11:09:25 +0100 | [diff] [blame] | 54 | vus: 9, |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 55 | duration: DURATION, |
| 56 | }, |
seanbeirne | 2855952 | 2024-07-19 16:55:06 +0100 | [diff] [blame] | 57 | passthrough_read_alt_id: { |
| 58 | executor: 'constant-vus', |
| 59 | exec: 'passthrough_read_alt_id', |
| 60 | vus: 1, |
| 61 | duration: DURATION, |
| 62 | }, |
halil.cakal | fcc81ee | 2024-07-11 14:54:57 +0100 | [diff] [blame] | 63 | passthrough_write: { |
| 64 | executor: 'constant-vus', |
| 65 | exec: 'passthrough_write', |
| 66 | vus: 10, |
| 67 | duration: DURATION, |
| 68 | }, |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 69 | 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.cakal | 65b870b | 2024-07-25 11:12:29 +0100 | [diff] [blame] | 81 | 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 | } |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 97 | }, |
| 98 | thresholds: { |
| 99 | 'cmhandles_created_per_second': ['value >= 22'], |
| 100 | 'cmhandles_deleted_per_second': ['value >= 22'], |
danielhanrahan | dbe7b66 | 2024-07-16 11:47:24 +0100 | [diff] [blame] | 101 | 'ncmp_overhead_passthrough_read': ['avg <= 100'], |
seanbeirne | 2855952 | 2024-07-19 16:55:06 +0100 | [diff] [blame] | 102 | 'ncmp_overhead_passthrough_read_alt_id': ['avg <= 100'], |
danielhanrahan | dbe7b66 | 2024-07-16 11:47:24 +0100 | [diff] [blame] | 103 | 'ncmp_overhead_passthrough_write': ['avg <= 100'], |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 104 | 'http_req_duration{scenario:id_search_module}': ['avg <= 625'], |
| 105 | 'http_req_duration{scenario:cm_search_module}': ['avg <= 13000'], |
danielhanrahan | dbe7b66 | 2024-07-16 11:47:24 +0100 | [diff] [blame] | 106 | '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.cakal | 65b870b | 2024-07-25 11:12:29 +0100 | [diff] [blame] | 110 | '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'], |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 113 | }, |
| 114 | }; |
| 115 | |
| 116 | export function setup() { |
| 117 | const totalRegistrationTimeInSeconds = recordTimeInSeconds(registerAllCmHandles); |
| 118 | cmHandlesCreatedPerSecondGauge.add(TOTAL_CM_HANDLES / totalRegistrationTimeInSeconds); |
| 119 | } |
| 120 | |
| 121 | export function teardown() { |
| 122 | const totalDeregistrationTimeInSeconds = recordTimeInSeconds(deregisterAllCmHandles); |
| 123 | cmHandlesDeletedPerSecondGauge.add(TOTAL_CM_HANDLES / totalDeregistrationTimeInSeconds); |
| 124 | } |
| 125 | |
| 126 | export function passthrough_read() { |
| 127 | const response = passthroughRead(); |
| 128 | check(response, { 'passthrough read status equals 200': (r) => r.status === 200 }); |
danielhanrahan | dbe7b66 | 2024-07-16 11:47:24 +0100 | [diff] [blame] | 129 | const overhead = response.timings.duration - READ_DATA_FOR_CM_HANDLE_DELAY_MS; |
| 130 | passthroughReadNcmpOverheadTrend.add(overhead); |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 131 | } |
| 132 | |
seanbeirne | 2855952 | 2024-07-19 16:55:06 +0100 | [diff] [blame] | 133 | export 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.cakal | fcc81ee | 2024-07-11 14:54:57 +0100 | [diff] [blame] | 140 | export function passthrough_write() { |
| 141 | const response = passthroughWrite(); |
danielhanrahan | df58456 | 2024-07-25 16:20:15 +0100 | [diff] [blame] | 142 | check(response, { 'passthrough write status equals 201': (r) => r.status === 201 }); |
danielhanrahan | dbe7b66 | 2024-07-16 11:47:24 +0100 | [diff] [blame] | 143 | const overhead = response.timings.duration - WRITE_DATA_FOR_CM_HANDLE_DELAY_MS; |
| 144 | passthroughWriteNcmpOverheadTrend.add(overhead); |
halil.cakal | fcc81ee | 2024-07-11 14:54:57 +0100 | [diff] [blame] | 145 | } |
| 146 | |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 147 | export 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 | |
| 153 | export 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.cakal | 65b870b | 2024-07-25 11:12:29 +0100 | [diff] [blame] | 159 | export 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 | |
| 165 | export 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 | |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 175 | export function handleSummary(data) { |
| 176 | return { |
| 177 | stdout: makeCustomSummaryReport(data, options), |
| 178 | }; |
| 179 | } |