(Optional) Spike multiple endpoints
Note
This milestone is optional. The core path continues with Turn spike results into action after the next optional step. To skip the optional milestones, open Turn spike results into action in the sidebar.
Real applications expose many routes; burst capacity is rarely identical across them. A read-heavy cacheable endpoint may handle a spike while a write path or dependency-heavy API degrades first. This milestone extends your spike profile to hit two QuickPizza routes in the same test so you can compare behavior under the same VU ramp.
To keep the per-route metrics readable, this script uses two k6 features:
- Groups (
group()) wrap related requests under a label so you can see combined timing for a logical action, such as “home” or “pizza API”. - Tags (
tags: { name: '...' }) attach a label to individual requests so k6 breaks metrics out per route instead of per raw URL, which also keeps metric cardinality low.
To spike multiple endpoints, complete the following steps:
Save a copy of your
spike.jsfile asspike-multi.jsso you can compare with your single-endpoint run later.Replace the default function with a version that requests both the home page and the pizza API, using
groupandtagsso Grafana Cloud k6 can break metrics out per route without blowing up metric cardinality:import http from 'k6/http'; import { check, sleep, group } from 'k6'; export default function () { group('home', function () { const res = http.get('https://quickpizza.grafana.com/', { tags: { name: 'GET_home' }, }); check(res, { 'home status 200': (r) => r.status === 200, }); }); group('pizza API', function () { const payload = JSON.stringify({ mustBeVegetarian: false, excludedIngredients: [], excludedTools: [], maxCaloriesPerSlice: 500, minNumberOfToppings: 2, maxNumberOfToppings: 5, }); const res = http.post( 'https://quickpizza.grafana.com/api/pizza', payload, { headers: { 'Content-Type': 'application/json', Authorization: 'Token abcdef0123456789', }, tags: { name: 'POST_api_pizza' }, } ); check(res, { 'pizza status 200': (r) => r.status === 200, }); }); sleep(1); }Keep the same
export const optionsblock (stages and thresholds) as in your originalspike.js.Run the test locally, then send results to Grafana Cloud k6 the same way as in the Visualize the spike in Grafana Cloud k6 milestone:
k6 cloud run --local-execution spike-multi.jsAs in the earlier milestones, drop
--local-execution(k6 cloud run spike-multi.js) to generate the load on cloud load generators, which is the better choice for higher VU counts.In the Grafana Cloud k6 result, compare response time and errors per tag or group during the spike phase. The
grouplabels andnametags you set are what let Grafana Cloud k6 split the metrics per route so you can compare them side by side.Note which route showed higher latency, errors, or slower recovery. Prioritize that route when you tune pools, timeouts, or rate limits for production.
In the next optional milestone, you add authentication headers driven by environment variables. If you prefer to move on to Turn spike results into action, open that milestone in the sidebar.
At this point in your path, you can explore the following topics: