Перейти к содержимому

k6 Load Testing #8: Custom Metrics (Counter, Trend, Rate) and Tags with Thresholds (Real Terminal)

Code & Test Automation

0:00 / 0:00

k6 Load Testing #8: Custom Metrics (Counter, Trend, Rate) and Tags with Thresholds (Real Terminal)

0 просмотров · 1 дн. назад
Code & Test Automation
21 подписчик
0 просмотров · 1 дн. назад
Code & Test Automation |    / @codetestautomation   Measure business outcomes in Grafana k6: Counter, Trend and Rate from k6/metrics, thresholds on custom metrics with exit code 99, Trend isTime for millisecond units, name tags to group dynamic URLs, tagged thresholds per page, and the tags in raw CSV output. Every run is real k6 output against a small local practice server. In this video: Why custom metrics Counter, Trend, Rate (and Gauge) Thresholds on custom metrics Trend isTime The CUSTOM summary section name tags for dynamic URLs 'http_req_duration{name:...}' thresholds --out csv and tags in raw data Video 8 of 10 in the k6 Load Testing series with Grafana k6, for freshers and experienced test engineers on Windows, macOS and Linux: install, scripts, checks, thresholds, stages, scenarios and executors, test data, custom metrics, setup and teardown, and CI workflows. Almost every minute is a real terminal session with real k6 output, run only against a local practice server. CHAPTERS 0:00 Introduction 0:52 Start the practice server 1:07 Why custom metrics 1:50 The four metric types 2:31 Creating the metrics 3:00 Thresholds on custom metrics 3:26 The login step 3:55 Adding values 4:19 Run it 4:58 Reading custom metrics 5:39 Where the values come from 6:15 Thresholds failed 7:00 More about thresholds 7:30 Trend with isTime 7:50 Fixing the bug 8:07 Run it again 9:12 Tagging requests 10:12 Why the name tag 10:59 Tagged thresholds 11:45 Tags in the raw data 12:57 Checks and groups are tagged too 13:26 Common mistakes 14:01 Stop the server 14:11 Putting it together 14:41 Recap 15:18 Next episode HOW THE DEMOS WERE MADE Everything between the title card and the recap is a live screen recording of a real terminal: bash 5.2 in xfce4-terminal on Debian Linux, with the official k6 v2.3.0 release binary from GitHub (checksum verified) and the GNU nano 8.4 editor. Every script was typed at a human pace and every line of k6 output is real; nothing was edited in afterwards. SAFETY: every test in this video sends load ONLY to a small practice server (ShopKart, a Python standard-library app in the project zip) running on localhost on the same machine. The recording sandbox has its own network namespace with only the loopback interface, so k6 could not reach any public or third-party site even by mistake. Where the course notes use the public demo site test.k6.io, the video uses the local server instead and shows the original line as TYPED ONLY. Load is kept small (a few virtual users for seconds). No account was used: no sign-in to Grafana Cloud, no k6 cloud command, and anonymous usage reporting is switched off with K6_NO_USAGE_REPORT=true. Keys pressed appear in on-screen badges with the Mac keys and the Windows / Linux keys. Commands that were not run here (package managers that need sudo or admin rights, Docker, cloud commands, public URLs) are shown as TYPED ONLY: typed on screen, never run, and cancelled with Ctrl+C, so no output is ever invented. CORRECTIONS TO THE COURSE NOTES new Trend('login_duration') shows plain numbers with no unit; pass isTime as the second argument, new Trend('login_duration', true), for durations in ms. k6/metrics has four types: Counter, Gauge, Rate and Trend; the notes list three. Create them in the init stage (global scope), not inside the default function. A Counter that never receives a value is left out of the summary; a threshold on it is still evaluated. http.get(url, { tags: { name: 'Login' } }) in the notes: the login is a POST in ShopKart; the video tags GET pages ('Home', 'ProductPage'). Without a name tag, name is the full URL, so dynamic URLs create one group per id. Tagged thresholds need quotes: 'http_req_duration{name:ProductPage}': ['p(95)‹300']. A 401 response also counts in http_req_failed. The video injects a wrong password every fifth iteration on purpose to show failing custom metrics, then removes it. Load is 2 VUs to keep it light. PRACTICE 1. Start the practice server: python3 server/shop_server.py & 2. k6 run metrics-test.js 3. Put the wrong-password line back and watch login_success fail. 4. Add a Trend for /api/products with isTime true and a p95 threshold. 5. k6 run -q tags-test.js and read the {name:...} lines Practice tip: install k6, unzip the project, start the local ShopKart practice server, and type every script right after you see it. Only ever point load tests at a server you own or have written permission to test; this series uses a local server on localhost for every run. Next video: #09 setup, teardown, Groups and Modules. #k6 #LoadTesting #PerformanceTesting #GrafanaK6 #CodeAndTestAutomation Subscribe to Code & Test Automation for more k6, performance testing, Java, coding and test automation tutorials:    / @codetestautomation