Skip to content

Instantly share code, notes, and snippets.

@quiiver
Created October 7, 2022 19:31
Show Gist options
  • Save quiiver/97562c2ed0519a06759103c2b1a19b10 to your computer and use it in GitHub Desktop.
Save quiiver/97562c2ed0519a06759103c2b1a19b10 to your computer and use it in GitHub Desktop.
import http from "k6/http";
import { SharedArray } from 'k6/data';
export const options = {
scenarios: {
warmup: {
executor: 'ramping-arrival-rate',
preAllocatedVUs: 200,
timeUnit: '1s',
startRate: 0,
stages: [
{ target: 3200, duration: '10m' },
],
},
load: {
executor: 'constant-arrival-rate',
preAllocatedVUs: 200,
timeUnit: '1s',
rate: 3200,
duration: "10m",
startTime: "10m",
},
},
summaryTrendStats: ['avg', 'min', 'med', 'max', 'p(90)', 'p(95)'],
thresholds: {
// Intentionally empty. We'll programatically define our bogus
// thresholds (to generate the sub-metrics) below. In your real-world
// load test, you can add any real threshoulds you want here.
}
};
for (let key in options.scenarios) {
// Each scenario automaticall tags the metrics it generates with its own name
let thresholdName = `http_req_duration{scenario:${key}}`;
// Check to prevent us from overwriting a threshold that already exists
if (!options.thresholds[thresholdName]) {
options.thresholds[thresholdName] = [];
}
// 'max>=0' is a bogus condition that will always be fulfilled
options.thresholds[thresholdName].push('max>=0');
}
const data = new SharedArray('query names', function() {
return JSON.parse(open('./fixtures.json'));
});
const hosts = {
"merinopy-sandbox": "http://34.67.8.144",
"merinopy-stage": "https://stagepy.merino.nonprod.cloudops.mozgcp.net",
"merino-stage": "https://merino.nonprod.cloudops.mozgcp.net",
"local": "http://127.0.0.1:8000"
}
const providers = __ENV.PROVIDERS || ""
const path = "api/v1/suggest"
export default function() {
const host = hosts[__ENV.HOST] || hosts.local
const query = data[Math.floor(Math.random() * data.length)];
const uri = `${host}/${path}?providers=${providers}&q=${encodeURIComponent(query)}`;
http.get(uri);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment