Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we view summary for each requests in k6 script (endpoint wise summary) #42

Open
harishsambasivam opened this issue Aug 2, 2022 · 2 comments

Comments

@harishsambasivam
Copy link

Can we view the summary for each request in the k6 script (endpoint-wise summary)? Jmeter is offering this by default, we are looking for similar feature in k6 cli

@benc-uk
Copy link
Owner

benc-uk commented Aug 2, 2022

k6 doesn't do this by default, but there's a fairly simple work around using custom trends.

let myRequestTrend = new Trend('myRequest')

// do something

myRequestTrend .add(resp.timings.duration)

If you do this, you will get timings and metrics for each of your requests and they will show up in the reports

@harishsambasivam
Copy link
Author

Is there any trick to make it work for all the requests by default, by writing some code main.js file? it looks I have to create one trend for each of my requests.

import { textSummary } from 'https://jslib.k6.io/k6-summary/0.0.1/index.js';
import http from 'k6/http';
import { htmlReport } from "https://raw.githubusercontent.com/benc-uk/k6-reporter/main/dist/bundle.js";
import { Trend } from 'k6/metrics';

export const options = {
  "duration": "10s",
  "vus": 1
};

let myRequestTrend = new Trend('myRequest')

export default function () {
  let resp;
  resp = http.get("https://jsonplaceholder.typicode.com/todos/1", {
    tags: {
      name: "getTodos",
    },
  });
  myRequestTrend.add(resp.timings.duration)

  http.get("https://jsonplaceholder.typicode.com/users", {
    tags: {
      name: "getUsers",
    },
  });

  myRequestTrend.add(resp.timings.duration)
}

export const handleSummary = function (data) {
  return {
    'stdout': textSummary(data, { indent: ' ', enableColors: true }), // Show the text summary to stdout...
    "summary.html": htmlReport(data),
    'summary.json': JSON.stringify(data), // and a JSON with all the details...

  }
}

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants