Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

[question] Is there a way to pass Azure variables to a Jmeter property variable? #32

Closed
harveydecapiataxsystems opened this issue Jul 20, 2020 · 8 comments
Labels
question Further information is requested

Comments

@harveydecapiataxsystems
Copy link

harveydecapiataxsystems commented Jul 20, 2020

I used to run Jmeter using the command line non gui mode and passing the needed property variables from there to have configurable test plans instead of having multiple jmx scripts.

jmeter -JnoThreads=2 -JrampUp=1 -n -t sample.jmx

I simply passed the number of threads value and ramp up values.

Is there a way to replicate that? Or do I need to update the pipeline settings?

If I need to do updating on the pipeline, can you provide examples?

@allantargino
Copy link
Contributor

Hi @harveydecapiataxsystems,

I believe there are some ways to implement this. One possible one is to:

  1. Create variables (JMETER_NO_THREADS and JMETER_RAMP_UP) on variables file:
    https://github.com/Azure-Samples/jmeter-aci-terraform/blob/master/terraform/variables.tf

Something like:

variable "JMETER_NO_THREADS " {
  type    = number
  default = 2
}

variable "JMETER_RAMP_UP" {
  type    = number
  default = 1
}

Then, you can use those parameters at:

"cd /jmeter; /entrypoint.sh -n -J server.rmi.ssl.disable=true -t ${var.JMETER_JMX_FILE} -l ${var.JMETER_RESULTS_FILE} -e -o ${var.JMETER_DASHBOARD_FOLDER} -R ${join(",", "${azurerm_container_group.jmeter_workers.*.ip_address}")}",

Something like:

 "cd /jmeter; /entrypoint.sh -n -J noThreads=${var.JMETER_NO_THREADS} -J rampUp=${var.JMETER_RAMP_UP}  -J server.rmi.ssl.disable=true -t ${var.JMETER_JMX_FILE} -l ${var.JMETER_RESULTS_FILE} -e -o ${var.JMETER_DASHBOARD_FOLDER} -R ${join(",", "${azurerm_container_group.jmeter_workers.*.ip_address}")}", 

Then, when triggering the pipeline, you would replace values for both JMETER_NO_THREADS and JMETER_RAMP_UP variables.

@harveydecapiataxsystems
Copy link
Author

harveydecapiataxsystems commented Jul 23, 2020

@allantargino This really helps. Thank you! So I've configured everything and add jmeter arguments on the main.tf file but it seems like the script will not run and so does error producing the report.
I believe I have the same issue as here: https://stackoverflow.com/questions/44237184/jmeter-execution-on-remote-system-does-not-work

This is a different issue that I'm facing now but I think you have an idea on why the script is not running. Thanks for your help!

Here's the error:
2020-07-23 07:23:23,366 ERROR o.a.j.JMeter: Error generating the report java.lang.NullPointerException: null at org.apache.jmeter.report.dashboard.JsonExporter.createStatistic(JsonExporter.java:121) ~[ApacheJMeter_core.jar:5.1.1 r1855137] at org.apache.jmeter.report.dashboard.JsonExporter.export(JsonExporter.java:71) ~[ApacheJMeter_core.jar:5.1.1 r1855137] at org.apache.jmeter.report.dashboard.ReportGenerator.exportData(ReportGenerator.java:381) ~[ApacheJMeter_core.jar:5.1.1 r1855137] at org.apache.jmeter.report.dashboard.ReportGenerator.generate(ReportGenerator.java:262) ~[ApacheJMeter_core.jar:5.1.1 r1855137] at org.apache.jmeter.JMeter$ListenToTest.generateReport(JMeter.java:1324) ~[ApacheJMeter_core.jar:5.1.1 r1855137] at org.apache.jmeter.JMeter$ListenToTest.run(JMeter.java:1308) [ApacheJMeter_core.jar:5.1.1 r1855137] at java.lang.Thread.run(Thread.java:748) [?:1.8.0_222]

@harveydecapiataxsystems
Copy link
Author

@allantargino The error on my previous comment is because of jmeter not finding the csv files needed to login on the application.
Based on one of the answers here. https://stackoverflow.com/questions/14160241/jmeter-remote-run-and-csv-files#:~:text=For%20distributed%20testing%2C%20the%20CSV,has%20the%20same%20directory%20structure.

Relative file names are resolved with respect to the path of the active test plan.
For distributed testing, the CSV file must be stored on the server host system in the
correct relative directory to where the jmeter server is started.

Absolute file names are also supported, but note that they are unlikely to work in remote
mode, unless the remote server has the same directory structure.

So are there any ways we can store the needed CSV file in the server host system in such a way, the file is relative to the jmeter scipt (active test plan)?

@Mahesh-MSFT
Copy link

Mahesh-MSFT commented Aug 1, 2020

@allantargino - I am getting an error

Non HTTP response code: java.net.SocketException/Non HTTP response message: Invalid argument or cannot assign requested address

As you suggested, I have updated main.tf to pass HOST as a property as shown below.

commands = [
      "/bin/sh",
      "-c",
      "cd /jmeter; /entrypoint.sh -n -J server.rmi.ssl.disable=true -t ${var.JMETER_JMX_FILE} -J host=${var.JMETER_JMX_HOST_PARAM} -l ${var.JMETER_RESULTS_FILE} -e -o ${var.JMETER_DASHBOARD_FOLDER} -R ${join(",", "${azurerm_container_group.jmeter_workers.*.ip_address}")}",
    ]

I assign value and start pipeline as below.

$JMETER_JMX_HOST_PARAM="azure.microsoft.com"
az pipelines run --name $PIPELINE_NAME_JMETER `
    --variables TF_VAR_JMETER_JMX_FILE=$JMETER_JMX_FILE `
            TF_VAR_JMETER_JMX_HOST_PARAM=$JMETER_JMX_HOST_PARAM `
            TF_VAR_JMETER_WORKERS_COUNT=$JMETER_WORKERS_COUNT   

I map this property value to Host variable in my Test Plan-->User Defined Variables.

I can see that the host entry is passed correctly to jmeter controller.

jmeter args=-n -J server.rmi.ssl.disable=true -t test2.jmx -J host=azure.microsoft.com -l results.jtl -e -o dashboard -R 10.0.0.4

Everything works if I use the same host entry in JMX file and run test without passing HOST property.

What I may be missing?

@Mahesh-MSFT
Copy link

Mahesh-MSFT commented Aug 3, 2020

Answering my own question - it turns out that I was not mapping variables with properties in right way.

I needed to pass default value for every property in my test plan before assigning it to a variable.

host = ${__P(host,azure.microsoft.com)}

Its working after that.

@allantargino
Copy link
Contributor

Hi @harveydecapiataxsystems,
If you place your csv files at jmeter directory, the whole directory is mounted on every JMeter worker (at /jmeter directory). So if you use this location, you should be fine.

@allantargino
Copy link
Contributor

Hi @Mahesh-MSFT,
I am so sorry it took so long to check this thread, I'm glad you figured it out!

@allantargino allantargino added the question Further information is requested label Aug 4, 2020
@harveydecapiataxsystems
Copy link
Author

@allantargino Yes, I have placed all the necessary csv files in the jmeter folder where the script also resides. It's now working. Thank you!

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants