Skip to content
This repository has been archived by the owner on Feb 7, 2022. It is now read-only.

Implement jmeter-to-k6 #2

Merged
merged 224 commits into from
Feb 5, 2019
Merged

Conversation

bookmoons
Copy link
Contributor

@bookmoons bookmoons commented Jan 24, 2019

Adds v1 implementation of the converter. Converts all elements listed in #1.

Closes #1.

@bookmoons
Copy link
Contributor Author

The SteppingThreadGroup is converting as specified. Also added all the test files to examples.

@robingustafsson
Copy link
Member

Good stuff! I'll do a second review tomorrow.

Multiple stepping courses would reuse VU numbers. Running standard
thread groups after a stepping course would also cause reuse
(eg step up to 50 then down to 0, standard threads now reuse 1-50).
As branching to the correct logic uses VU number, this would cause
collisions in the branching logic.

This patch constrains to max 1 stepping course and forces it to
order after all standard thread groups.
@robingustafsson
Copy link
Member

Sorry for the delay. Have now done a second pass after your fixes, found some more issues:

General

  • Add semicolons at end of lines when running prettier. I know it's a subjective matter, but we've used semicolons all over the docs and examples for k6 so would like to keep it consistent 🙂
  • I had to add the following to package.json to have it run ./bundle now:
"dependencies": {
    "@babel/runtime": "^7.0.0-beta.55"
}

as I got: Error: Cannot find module '@babel/runtime/helpers/builtin/interopRequireDefault' (any idea why?)

If controller

  • When I have a statement like ${someVariable}=="Some string" in JMeter it converts to something like this in k6 JS (see JMX and generated JS: https://gist.github.com/robingustafsson/56cd5aef0e69ad25afbaf0bde1b572d7):
    if (`${vars[`someVariable`]}=="Some string"` === "true") {
        ...
    }
    
    This is not going to execute correctly, it would have to be something like this to work:
    if (eval(`"${vars[`someVariable`]}"=="Some string"`) === true) {
        ...
    }
    
  • When running this the JSON extraction block (JSONPostProcessor) that is defined above the if-controller is also included inside the if-statement in the generated JS.

Stepping thread group

  • In the ramp-down the slope should be calculated and then set as one stage entry rather than one for every X VUs/s (see JMX and generated JS: https://gist.github.com/robingustafsson/e13dd7d2dd7a560dafda4e9b2cf36239). In the linked gist the ramp-down should be {target: 0, duration:"20s"} (20s = 100 VUs / 5 VUs per second) rather than:
      { target: 95, duration: "0s" },
      { target: 95, duration: "1s" },
      { target: 90, duration: "0s" },
      { target: 90, duration: "1s" },
      { target: 85, duration: "0s" },
      { target: 85, duration: "1s" },
      { target: 80, duration: "0s" },
      { target: 80, duration: "1s" },
      { target: 75, duration: "0s" },
      { target: 75, duration: "1s" },
      { target: 70, duration: "0s" },
      { target: 70, duration: "1s" },
      { target: 65, duration: "0s" },
      { target: 65, duration: "1s" },
      { target: 60, duration: "0s" },
      { target: 60, duration: "1s" },
      { target: 55, duration: "0s" },
      { target: 55, duration: "1s" },
      { target: 50, duration: "0s" },
      { target: 50, duration: "1s" },
      { target: 45, duration: "0s" },
      { target: 45, duration: "1s" },
      { target: 40, duration: "0s" },
      { target: 40, duration: "1s" },
      { target: 35, duration: "0s" },
      { target: 35, duration: "1s" },
      { target: 30, duration: "0s" },
      { target: 30, duration: "1s" },
      { target: 25, duration: "0s" },
      { target: 25, duration: "1s" },
      { target: 20, duration: "0s" },
      { target: 20, duration: "1s" },
      { target: 15, duration: "0s" },
      { target: 15, duration: "1s" },
      { target: 10, duration: "0s" },
      { target: 10, duration: "1s" },
      { target: 5, duration: "0s" },
      { target: 5, duration: "1s" },
      { target: 0, duration: "0s" }
    

@bookmoons
Copy link
Contributor Author

bookmoons commented Jan 30, 2019

Thanks for that. Have updated all of it.

Not sure what caused Babel requirement, but I added it as a dependency. The only package I've added to bundle was papaparse for the CSV update.


When I have a statement like ${someVariable}=="Some string" in JMeter it converts to something like this in k6 JS

I think this piece is following JMeter. The IfController has a special flag for the condition, it seemed to be the only one that has it.

Interpret Condition as Variable Expression?
If this is selected, then the condition must be an expression that evaluates to "true" (case is ignored).

(Expression here meaning a JMeter expression). If you uncheck that flag then it's meant to be JavaScript, and it should render with an eval.


When running this the JSON extraction block (JSONPostProcessor) that is defined above the if-controller is also included inside the if-statement in the generated JS.

I think this one is correct. Processors and assertions are supposed to apply to all descendants of the parent element. So it caches them up in the context and duplicates for all samplers in that section of the tree.

@bookmoons
Copy link
Contributor Author

It looks like that Babel requirement comes from yaml, only necessary when bundling. So I think it's OK:

It runs on Node.js 6 and later with no external dependencies, and in browsers from IE 11 upwards using @babel/runtime (Note: not included in dependencies, install separately).

That package is used by JSONPathAssertion JSONPathExtractor to support YAML data in a response body.

@robingustafsson
Copy link
Member

Ah, you're right about the IFController and var expression vs JS code. I'd missed unchecking that flag.

Regarding the post processors and assertions you're also correct that they apply to all samplers in the same scope. Think I found another issue here though:

@bookmoons
Copy link
Contributor Author

It seems that even when I add the post-processor to be a child of the sampler, the post-processor is still applied to children of the grandparent

Think I know just where I did this. Looking into it.

Only necessary in generated code. Installed by bundle instead.
@bookmoons
Copy link
Contributor Author

Not what I thought it was, but I've just pushed a fix.

@robingustafsson
Copy link
Member

Ok @bookmoons. I've looked through the code as well and I think it looks good; structure, style and tests. Well done, thanks for your work on this 👏Now, go claim the bounty!

PS. I sent you a message on k6 slack if you can have a look when you get a chance.

@robingustafsson robingustafsson merged commit 392d322 into grafana:master Feb 5, 2019
@bookmoons
Copy link
Contributor Author

Very nice, thank you very much. Submitted a claim and will open slack.

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

Successfully merging this pull request may close these issues.

None yet

2 participants