-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
js/execution: Stage identifier #2215
Comments
@mstoykov re-starting the discussion from #2199 (comment). The plan was to have this as a foundation for achieving #796, so the main con to not including it in the core or having it as a |
I am still very much against In the case that this is interesting this is easy to calculate with some js (possibly hosted in jslib), the stages, now and when the scenario started(as has been established). AFAIK the only thing that is currently hard to get is So to me it seems that working on #2259 to export the final value for And if we have |
@mstoykov so what you're proposing should be what is provided by #796 (comment) with some additional improvements:
Is there a difference between export default function() {
let iterStartTime = new Date()
...
} |
Sorry, for the slow reply - yes this is more or less what I propose. I guess |
In the case, we would add the stage's name then we could support an auto-tagging function: export default function() {
tagByStage(new Date())
...
}
function tagByStage(iterStartTime) { // or just tagByStage() in the case we add exec.iteration.startTime
exec.vu.tags['stage'] = getStage(iterStartTime).name
} It would require to add (in order of priority):
|
I think this is a mostly academic concern... When I ask myself the question "in which stage is the second iteration of the first VU going to be?": import http from 'k6/http';
import exec from 'k6/execution';
import { sleep } from 'k6';
export const options = {
stages: [
{ duration: '5s', target: 10 },
{ duration: '1m', target: 10 },
],
};
export default function () {
console.log(`[t=${(new Date()) - exec.scenario.startTime}ms] VU{${exec.vu.idInTest}} started iteration ${exec.scenario.iterationInTest}`);
http.get(`https://httpbin.test.k6.io/delay/${(1 + 4 * Math.random()).toFixed(2)}`)
http.get(`https://httpbin.test.k6.io/delay/${(1 + 2 * Math.random()).toFixed(2)}`)
sleep(0.5);
} My answer is "it depends on what you mean 🤷♂️"... It's almost a meaningless question unless you know precisely what you want to measure. To set the right threshold, you might care when the iteration starts, or you might care about how many other VUs are currently running (and making requests) at the exact time as the current request your VU is making. Anyway,
I think we have that value only here: Line 790 in 737dfa7
And we don't have export default function() {
var startTime = new Date();
...
} So... yeah, if someone thinks a PoC will be quick, I am fine with trying it, but 👍 for starting by passing the JS time.
This mostly LGTM, with a couple of comments:
|
This is not going to be implemented as part of the execution API so I'm closing this and we will discuss more details in an eventual PR. For the current plan check: #796 (comment) |
Feature Description
As part of the journey to achieve #796, we decided to start by giving the ability for doing it from the JS code. One of the main steps for doing it, it would be to detect which is the current Stage for the running iteration.
Proposal
The proposal is to add a Stage's identifier information. We would add a new
stage
object to the already existingscenario
object as part of thejs/execution
module. It would export theexec.scenario.stage.id
property that returns a zero-based value, that would track the index of the current running Stage.The following example shows how to would be used for tracking the stage as a tag, invoking the already implemented
tags
setter #2172:Known problem
After a PoC, we have identified that the main problem for this, would be how to return an accurate value, especially for the
ramping-vus
executor. Because the current implementation of theramping-vus
doesn't have a specific event during execution where an iteration is going to be defined as part of a Stage. It pre-computes them and it will totally lose the connection with the defined Scenario's stages.For this reason, the proposed workaround, it's to recognize the current Stage computing the elapsed time from the
exec.scenario.startTime
property then find the Stage that contains it. It has the benefit that the implementation is simple but in some circumstances, it could be not accurate (e.g when the iteration uses thegracefulRampDown
period).Alternatives
Currently, the identified alternatives are:
jslib
.@grafana/k6-devs let's discuss if we have more alternatives and/or better solutions.
The text was updated successfully, but these errors were encountered: