Hi @pabhishek24
Welcome to the community forum
The error you are getting is caused by the import. You should import import { group } from 'k6';
, not import { group } from 'k6/metrics';
.
After that, the next line that fails is console.log(group.duration('my-group'));
fails. So remove that bit and the script works.
import { group } from 'k6';
import http from 'k6/http';
export default function () {
group('my-group', function () {
http.get('https://test.k6.io');
});
}
I understand the goal is to get the group duration, and that will be available with the results. What type of output are you using, end-of-test, or real-time?
If you run, for example, with csv
output, k6 run --out csv=test_results.csv script.js
, you would see in the resulting CSV the http_req_duration
for my-group
:
metric_name,timestamp,metric_value,check,error,error_code,expected_response,group,method,name,proto,scenario,service,status,subproto,tls_version,url,extra_tags,metadata
...
http_req_duration,1681672047,105.724000,,,,true,::my-group,GET,https://test.k6.io,HTTP/1.1,default,,200,,tls1.3,https://test.k6.io,,
...
I hope this helps.
Cheers!