blob: b4c476ecb23c98396eb090e5b797e88c7b7008d3 [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';
23import { TOTAL_CM_HANDLES, READ_DATA_FOR_CM_HANDLE_DELAY_MS, WRITE_DATA_FOR_CM_HANDLE_DELAY_MS,
24 makeCustomSummaryReport, recordTimeInSeconds } from './common/utils.js';
danielhanrahan4e9f68c2024-06-28 13:43:35 +010025import { registerAllCmHandles, deregisterAllCmHandles } from './common/cmhandle-crud.js';
26import { executeCmHandleSearch, executeCmHandleIdSearch } from './common/search-base.js';
halil.cakalfcc81ee2024-07-11 14:54:57 +010027import { passthroughRead, passthroughWrite } from './common/passthrough-crud.js';
danielhanrahan4e9f68c2024-06-28 13:43:35 +010028
29let cmHandlesCreatedPerSecondGauge = new Gauge('cmhandles_created_per_second');
30let cmHandlesDeletedPerSecondGauge = new Gauge('cmhandles_deleted_per_second');
danielhanrahandbe7b662024-07-16 11:47:24 +010031let passthroughReadNcmpOverheadTrend = new Trend('ncmp_overhead_passthrough_read');
32let passthroughWriteNcmpOverheadTrend = new Trend('ncmp_overhead_passthrough_write');
danielhanrahan4e9f68c2024-06-28 13:43:35 +010033
34const DURATION = '15m';
35
36export const options = {
37 setupTimeout: '6m',
38 teardownTimeout: '6m',
39 scenarios: {
40 passthrough_read: {
41 executor: 'constant-vus',
42 exec: 'passthrough_read',
43 vus: 10,
44 duration: DURATION,
45 },
halil.cakalfcc81ee2024-07-11 14:54:57 +010046 passthrough_write: {
47 executor: 'constant-vus',
48 exec: 'passthrough_write',
49 vus: 10,
50 duration: DURATION,
51 },
danielhanrahan4e9f68c2024-06-28 13:43:35 +010052 id_search_module: {
53 executor: 'constant-vus',
54 exec: 'id_search_module',
55 vus: 3,
56 duration: DURATION,
57 },
58 cm_search_module: {
59 executor: 'constant-vus',
60 exec: 'cm_search_module',
61 vus: 3,
62 duration: DURATION,
63 },
64 },
65 thresholds: {
66 'cmhandles_created_per_second': ['value >= 22'],
67 'cmhandles_deleted_per_second': ['value >= 22'],
halil.cakalfcc81ee2024-07-11 14:54:57 +010068 'http_reqs{scenario:passthrough_write}': ['rate >= 13'],
halil.cakal90464762024-07-09 17:43:25 +010069 'http_reqs{scenario:passthrough_read}': ['rate >= 25'],
danielhanrahandbe7b662024-07-16 11:47:24 +010070 'ncmp_overhead_passthrough_read': ['avg <= 100'],
71 'ncmp_overhead_passthrough_write': ['avg <= 100'],
danielhanrahan4e9f68c2024-06-28 13:43:35 +010072 'http_req_duration{scenario:id_search_module}': ['avg <= 625'],
73 'http_req_duration{scenario:cm_search_module}': ['avg <= 13000'],
danielhanrahandbe7b662024-07-16 11:47:24 +010074 'http_req_failed{scenario:id_search_module}': ['rate == 0'],
75 'http_req_failed{scenario:cm_search_module}': ['rate == 0'],
76 'http_req_failed{scenario:passthrough_read}': ['rate == 0'],
77 'http_req_failed{scenario:passthrough_write}': ['rate == 0'],
danielhanrahan4e9f68c2024-06-28 13:43:35 +010078 },
79};
80
81export function setup() {
82 const totalRegistrationTimeInSeconds = recordTimeInSeconds(registerAllCmHandles);
83 cmHandlesCreatedPerSecondGauge.add(TOTAL_CM_HANDLES / totalRegistrationTimeInSeconds);
84}
85
86export function teardown() {
87 const totalDeregistrationTimeInSeconds = recordTimeInSeconds(deregisterAllCmHandles);
88 cmHandlesDeletedPerSecondGauge.add(TOTAL_CM_HANDLES / totalDeregistrationTimeInSeconds);
89}
90
91export function passthrough_read() {
92 const response = passthroughRead();
93 check(response, { 'passthrough read status equals 200': (r) => r.status === 200 });
danielhanrahandbe7b662024-07-16 11:47:24 +010094 const overhead = response.timings.duration - READ_DATA_FOR_CM_HANDLE_DELAY_MS;
95 passthroughReadNcmpOverheadTrend.add(overhead);
danielhanrahan4e9f68c2024-06-28 13:43:35 +010096}
97
halil.cakalfcc81ee2024-07-11 14:54:57 +010098export function passthrough_write() {
99 const response = passthroughWrite();
danielhanrahandf584562024-07-25 16:20:15 +0100100 check(response, { 'passthrough write status equals 201': (r) => r.status === 201 });
danielhanrahandbe7b662024-07-16 11:47:24 +0100101 const overhead = response.timings.duration - WRITE_DATA_FOR_CM_HANDLE_DELAY_MS;
102 passthroughWriteNcmpOverheadTrend.add(overhead);
halil.cakalfcc81ee2024-07-11 14:54:57 +0100103}
104
danielhanrahan4e9f68c2024-06-28 13:43:35 +0100105export function id_search_module() {
106 const response = executeCmHandleIdSearch('module');
107 check(response, { 'module ID search status equals 200': (r) => r.status === 200 });
108 check(JSON.parse(response.body), { 'module ID search returned expected CM-handles': (arr) => arr.length === TOTAL_CM_HANDLES });
109}
110
111export function cm_search_module() {
112 const response = executeCmHandleSearch('module');
113 check(response, { 'module search status equals 200': (r) => r.status === 200 });
114 check(JSON.parse(response.body), { 'module search returned expected CM-handles': (arr) => arr.length === TOTAL_CM_HANDLES });
115}
116
117export function handleSummary(data) {
118 return {
119 stdout: makeCustomSummaryReport(data, options),
120 };
121}