we want to run k6 batch, and want to depart every k6 tasks from the log. such as:
scriptA run as taskA with API1 API2
scriptB run as taskB with API2 API3
can we tell the log appart by adding extra info to the log? such as taskId?
Hi @rawbin
Thanks for reaching out, I’ll try my best to support you!
In the spirit of avoiding misunderstandings, here is what I understood from your request, please let me know if that’s accurate:
- you are using the k6 http/batch API
- you wish to distinguish the different HTTP requests from each other
- you wish to attach extra meta-data to each requests
If that’s the case, I think this part of the http/batch documentation might prove helpful. Note how it uses tags to add contextual and grouping information to requests, this might be what you were looking for?
I have a hunch that I might have missed your point. Please don’t hesitate to clarify your use case and needs with example scripts (anonymized) if that’s the case
Cheers
Thank you very much for you answer, and exactly almost there.
I am not batching the requests, but batching the scripts.
And I want to add extra info for every scripts to depart them from each other. may be the expected logs as:
scrpitA starting
////some log for scriptA
scriptA finished
I have tried to use console.log but the log repeated when I set the script to be repeated either vus or duration and I want the result one run one log regardless of repeating times.
and further more:logs from different machine all gathered to grafana,and different logs are crossed like:
aaaa1
bbbb1
aaaa2
aaaaa3
bbbb2
and we want to add some prefix like machineA-jobA:
machine-A-jobA-###aaaa1
machine-B-jobB-###bbbb1
machine-A-jobA-###aaaa2
machine-A-jobA-###aaaaa3
machine-B-jobB-###bbbb2
so we can grep then to group by machine-A-jobA-### together.
we wonder how to do this in k6 or any other suggestion to solve the problem
I’m truly sorry @rawbin, I think I still fail to understand what your workflow looks like. I think it might be because we use a different terminology. Please bear with me…
Would you be open to share (anonymized) your test script(s), or some script(s) that’s similar to what you’re building? As well as how you run it.
What I assume I understand so far is that you have multiple k6 test scripts, which you want to run from multiple machines, and wish to distinguish their running logs, based on the machine and context they run onto.
From this partial understanding, it sounds like you could benefit from using environment variables. They are accessible from your scripts via the __ENV
variable. You could, for instance, put your machine name into an environment variable and use it as a tag in the context of your scripts or logging?
Assuming you are actually using multiple scenarios, and based on my partial understanding still, I have a hunch, that you might benefit from using scenarios, who also support tagging?
Let me know if that’s helpful, and please provide more concrete context if you can
I’ve also been pointed out that in the event you are using Loki for logging, k6 supports the label.instance=<instancel-id>
argument to do what sounds like what you’re looking for? If relevant, see the documentation about.
We Wrapped K6 and run scripts user uploaded. these scripts would be run any machine in the pool. and we gathered the logs to grafana. We want to tell apart logs from each run without looking inside the scripts.
If we write scripts maybe solutions above are much enough. But here we want to work outside the scripts.