Add data to summary.json

After a K6 test I have a massive result.csv and a summary.json,
I do performance optimalization of payload, so I like to add some keys like description to summary.json, since changes in payload is not reflected in the results.
Currently I add share parameters with the reporttool, but this is not stored anywhere.

Any idea.
Thanks

Hi @mortenb123

I’m not sure I fully understand your question. Please bear with me.

Is the aim of the test to keep track of the payload size, to check if it has decreased, and you’d like to store that data point in the results?

Where do you get the keys like description you need to add to summary.json.

Can you also clarify this? What share parameters are you adding? Do you mean parameters you read via data parameterization?

Currently I add share parameters with the reporttool, but this is not stored anywhere.

If you could share a (sanitized) script and an example it might be easier for us to advice on the best options.

Cheers!

Hi, I just want to pass some extra variables along like certtype, certsize, hardwaretype, description etc, I use in presentation. I pass this as environment variables to the k6 javascript file.

This is more like an extension of vus,duration which I find in the summary.json file.
Would siplify a lot of stuff if I could just append a variable there. all jobs have *.csv and summary.json file.

Currently my options are using an extra json file, or pass as variables to the presentation script.

# run code
- bash -c -l "k6 run --insecure-skip-tls-verify --out json=results.json --vus ${VUS} --duration ${DURATION} -e CERTTYPE=${CERTTYPE} -e CERTSIZE=${CERTSIZE} ./sam-perf-test.js --summary-export 'report/summary.json'" || true

# presentation
- bash -c -l "python ./k6csv2plot.py --csv=results.csv --thresholds=report/summary.json --desc='certtype=${CERTTYPE}-${CERTSIZE}'" || true

Thanks

Hi @mortenb123

Based on my understanding of what you’re trying to achieve, you might want to consider overriding the handleSummary function in your script. That way, you can directly add any information you want to the JSON summary from your script. It involves a bit more work but should give you access to the customization level you’re looking for.

Here’s an example of adding a duration and certSize to the JSON summary:

import http from "k6/http";

export const options = {
  vus: 100,
  iterations: 1000,
};

const duration = __ENV.DURATION || "12m";
const certSize = __ENV.CERTSIZE || "2048";

export default function () {
  http.get("https://test.k6.io");
}

export function handleSummary(data) {
  const customized_report = Object.assign(
    {
      duration: duration,
      certSize: certSize,
    },
    data
  );

  return {
    // Writing the summary to a "summary.json" file in the cwd directory
    "summary.json": JSON.stringify(customized_report),
  };
}

Let me know if that’s helpful :bowing_man:

PS: In the event, you would need further support, could you please post an anonymized, stripped-down version of the kind of script?

3 Likes

Thanks this was excactly what I was looking for. I was pretty sure there was a standard way to do this, but could not find it. this works like a dream.