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'; |
halil.cakal | 65b870b | 2024-07-25 11:12:29 +0100 | [diff] [blame] | 30 | import { passthroughRead, passthroughWrite, batchRead } from './common/passthrough-crud.js'; |
| 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'); |
| 38 | let passthroughWriteNcmpOverheadTrend = new Trend('ncmp_overhead_passthrough_write'); |
halil.cakal | 65b870b | 2024-07-25 11:12:29 +0100 | [diff] [blame] | 39 | let dataOperationsBatchReadCmHandlePerSecondTrend = new Trend('data_operations_batch_read_cmhandles_per_second'); |
| 40 | |
| 41 | const reader = new Reader({ |
| 42 | brokers: KAFKA_BOOTSTRAP_SERVERS, |
| 43 | topic: TOPIC_DATA_OPERATIONS_BATCH_READ, |
| 44 | }); |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 45 | |
| 46 | const DURATION = '15m'; |
| 47 | |
| 48 | export 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.cakal | fcc81ee | 2024-07-11 14:54:57 +0100 | [diff] [blame] | 58 | passthrough_write: { |
| 59 | executor: 'constant-vus', |
| 60 | exec: 'passthrough_write', |
| 61 | vus: 10, |
| 62 | duration: DURATION, |
| 63 | }, |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 64 | 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.cakal | 65b870b | 2024-07-25 11:12:29 +0100 | [diff] [blame] | 76 | 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 | } |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 92 | }, |
| 93 | thresholds: { |
| 94 | 'cmhandles_created_per_second': ['value >= 22'], |
| 95 | 'cmhandles_deleted_per_second': ['value >= 22'], |
halil.cakal | fcc81ee | 2024-07-11 14:54:57 +0100 | [diff] [blame] | 96 | 'http_reqs{scenario:passthrough_write}': ['rate >= 13'], |
halil.cakal | 9046476 | 2024-07-09 17:43:25 +0100 | [diff] [blame] | 97 | 'http_reqs{scenario:passthrough_read}': ['rate >= 25'], |
danielhanrahan | dbe7b66 | 2024-07-16 11:47:24 +0100 | [diff] [blame] | 98 | 'ncmp_overhead_passthrough_read': ['avg <= 100'], |
| 99 | 'ncmp_overhead_passthrough_write': ['avg <= 100'], |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 100 | 'http_req_duration{scenario:id_search_module}': ['avg <= 625'], |
| 101 | 'http_req_duration{scenario:cm_search_module}': ['avg <= 13000'], |
danielhanrahan | dbe7b66 | 2024-07-16 11:47:24 +0100 | [diff] [blame] | 102 | '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.cakal | 65b870b | 2024-07-25 11:12:29 +0100 | [diff] [blame] | 106 | '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'], |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 109 | }, |
| 110 | }; |
| 111 | |
| 112 | export function setup() { |
| 113 | const totalRegistrationTimeInSeconds = recordTimeInSeconds(registerAllCmHandles); |
| 114 | cmHandlesCreatedPerSecondGauge.add(TOTAL_CM_HANDLES / totalRegistrationTimeInSeconds); |
| 115 | } |
| 116 | |
| 117 | export function teardown() { |
| 118 | const totalDeregistrationTimeInSeconds = recordTimeInSeconds(deregisterAllCmHandles); |
| 119 | cmHandlesDeletedPerSecondGauge.add(TOTAL_CM_HANDLES / totalDeregistrationTimeInSeconds); |
| 120 | } |
| 121 | |
| 122 | export function passthrough_read() { |
| 123 | const response = passthroughRead(); |
| 124 | check(response, { 'passthrough read status equals 200': (r) => r.status === 200 }); |
danielhanrahan | dbe7b66 | 2024-07-16 11:47:24 +0100 | [diff] [blame] | 125 | const overhead = response.timings.duration - READ_DATA_FOR_CM_HANDLE_DELAY_MS; |
| 126 | passthroughReadNcmpOverheadTrend.add(overhead); |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 127 | } |
| 128 | |
halil.cakal | fcc81ee | 2024-07-11 14:54:57 +0100 | [diff] [blame] | 129 | export function passthrough_write() { |
| 130 | const response = passthroughWrite(); |
danielhanrahan | df58456 | 2024-07-25 16:20:15 +0100 | [diff] [blame] | 131 | check(response, { 'passthrough write status equals 201': (r) => r.status === 201 }); |
danielhanrahan | dbe7b66 | 2024-07-16 11:47:24 +0100 | [diff] [blame] | 132 | const overhead = response.timings.duration - WRITE_DATA_FOR_CM_HANDLE_DELAY_MS; |
| 133 | passthroughWriteNcmpOverheadTrend.add(overhead); |
halil.cakal | fcc81ee | 2024-07-11 14:54:57 +0100 | [diff] [blame] | 134 | } |
| 135 | |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 136 | export 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 | |
| 142 | export 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.cakal | 65b870b | 2024-07-25 11:12:29 +0100 | [diff] [blame] | 148 | export 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 | |
| 154 | export 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 | |
danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 164 | export function handleSummary(data) { |
| 165 | return { |
| 166 | stdout: makeCustomSummaryReport(data, options), |
| 167 | }; |
| 168 | } |