Skip to content

Commit

Permalink
k8s - adjust k6 to hit k8s resources
Browse files Browse the repository at this point in the history
  • Loading branch information
giovannymassuia committed Nov 17, 2024
1 parent 76181b0 commit d26b351
Showing 1 changed file with 42 additions and 22 deletions.
64 changes: 42 additions & 22 deletions local-dev/k6/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,37 @@ import {check, group, sleep} from 'k6';
const productGrpcClient = new grpc.Client();
const orderGrpcClient = new grpc.Client();

// Instructions for running the test
// kubernetes resources: k6 run --env ENV=k8s main.js
// docker-compose: k6 run --env ENV=docker main.js

export const options = {
scenarios: {
rampUpAndDown: {
executor: 'ramping-vus',
startVUs: 0,
stages: [
{duration: '3m', target: 25},
{duration: '5m', target: 10},
{duration: '4m', target: 15},
{duration: '4m', target: 0},
],
startTime: '0m',
exec: 'scenario1',
},
constantLoad: {
// rampUpAndDown: {
// executor: 'ramping-vus',
// startVUs: 0,
// stages: [
// {duration: '3m', target: 25},
// {duration: '5m', target: 10},
// {duration: '4m', target: 15},
// {duration: '4m', target: 0},
// ],
// startTime: '0m',
// exec: 'scenario1',
// },
//
// constantLoad: {
// executor: 'constant-vus',
// vus: 10,
// duration: '12m',
// startTime: '4m',
// exec: 'scenario1',
// },

smallLoad: {
executor: 'constant-vus',
vus: 10,
duration: '12m',
startTime: '4m',
vus: 5,
duration: '30s',
exec: 'scenario1',
},
}
Expand All @@ -35,13 +47,21 @@ export const options = {
};

export const scenario1 = () => {
let host = 'localhost';
if(__ENV.DOCKER === 'true') {
host = 'host.docker.internal';
let inventory_http_url = 'localhost:8081';
let product_grpc_url = 'localhost:5102';
let order_grpc_url = 'localhost:5101';
if(__ENV.ENV === 'docker') {
inventory_http_url = 'host.docker.internal:8081';
product_grpc_url = 'host.docker.internal:5102';
order_grpc_url = 'host.docker.internal:5101';
} else if (__ENV.ENV === 'k8s') {
inventory_http_url = 'inventory-management.127.0.0.1.nip.io:8888';
product_grpc_url = 'product-catalog.grpc.127.0.0.1.nip.io:8888';
order_grpc_url = 'order-management.grpc.127.0.0.1.nip.io:8888';
}

productGrpcClient.connect(`${host}:5102`, {plaintext: true, reflect: true});
orderGrpcClient.connect(`${host}:5101`, {plaintext: true, reflect: true});
productGrpcClient.connect(`${product_grpc_url}`, {plaintext: true, reflect: true});
orderGrpcClient.connect(`${order_grpc_url}`, {plaintext: true, reflect: true});

group("Product Service Calls", function () {
randomizedRequest(
Expand All @@ -64,7 +84,7 @@ export const scenario1 = () => {
const payload = JSON.stringify({sku: '1', newQuantity: 10});
const params = {headers: {'Content-Type': 'application/json'}};
randomizedRequest(
() => httpCall('post', `http://${host}:8081/inventory/on-hand`,
() => httpCall('post', `http://${inventory_http_url}/inventory/on-hand`,
payload, params),
10
);
Expand Down

0 comments on commit d26b351

Please sign in to comment.