【问题标题】:K6 - breakup of results for each api requestK6 - 每个 api 请求的结果分解
【发布时间】:2021-10-04 04:19:02
【问题描述】:

我正在使用 HTTP 请求调用为一个工作流开发负载测试。在工作流中,一个 API 调用的响应在下一个 API 调用中用作参数或请求正文。所以,API被调用的顺序非常重要。

我的问题是关于结果的。 K6 中是否有任何机制可以让我分解执行每个 API 调用所花费的时间?

【问题讨论】:

    标签: k6


    【解决方案1】:

    是的,您可以按指标(默认或自定义)标签过滤指标。这是一个例子:

    import { check } from 'k6';
    import 'http' from 'k6/http';
    
    export const options = {
      thresholds: {
        'http_req_duration{name:${}/endpoint1}': [ 'avg>0' ], // arbitrary threshold
        'http_req_duration{name:${}/endpoint2}': [ 'avg>0' ],
      },
    };
    
    export default function() {
      const server = 'http://example.com';
      const token = http.get(http.url`${server}/endpoint1`).json('token');
      check(
        http.post(http.url`${server}/endpoint2`, 'token=' + token),
        {
          'token accepted': r => r.status === 200,
        });
    }
    

    带有http.url 标记的字符串模板会自动为您的请求设置name 标记,让您可以轻松过滤请求的子集。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-29
      • 2013-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多