我想为k6
服务的负载测试创建一个自定义指标。我想测量http_req_duration
旧版本(代码更改之前)和新版本(代码更改)之间的偏差,并对差异设置一个阈值。可以做k6
吗?如果是,我该怎么做?
1 回答
0
使用下面的代码:
import http from "k6/http";
import {Trend} from "k6/metrics";
var diffT = new Trend("DiffTrend", true); // this true is just so in the summary it shows them as times
var oldURL = "https://test.loadimpact.com";
var newURL = "https://test.k6.io";
export default function() {
// you can use http.get, but this way the two requests will be done at the same time which will save time and probably be a better comparison
var res = http.batch([
["GET", oldURL, null, {"tags": {"varaint": "old"}}],
["GET", newURL, null, {"tags": {"varaint": "new"}}],
])
diffT.add(res[0].timings.duration - res[1].timings.duration);
}
您可以通过两种不同的方式使用它:
使用可能是最简单的 diffT 指标,但我认为除了最简单的情况外,它对任何事情都没有好处,因为它只处理请求差异的请求,而不是整体情况......但是你将区分 10 个请求对于相同的 API,这可能已经足够好了。
您可以使用标签“variant”来区分和比较新旧请求之间每个和所有请求所需的任何指标。这是 IMO 更好的方法,使用 Grafana 这将更强大,并为您提供更好的画面。
于 2020-03-31T08:40:02.407 回答