0

When I start in a Docker environment with Jenkins a JMeter test using a jmeter-maven-plugin, then the HttpRequests will always fail with a 403. It doesn't matter whether the receiving SpringBootApplication runs within a Docker environment or just on my PC (host). The Docker environment is 'Docker for Windows'.

Running the jmeter-maven-script within a Maven on Windows (no Docker), then everything runs smoothly. Also running within the JMeter GUI works fine.

Updates:

  • When I change the URL to an invalid one, the 403 http status remains. Changing the path to an invalid server keeps giving the 403 http status.
  • When I start the JMeter run (1 thread, 2 times) on http://example.com it works.
  • Starting the SpringBootApplication on the same Docker network on port 80 is also not working. Both using http://localhost and http://dockercontainername fail with "Non HTTP response code: java.net.ConnectException,Non HTTP response message: Connection refused (Connection refused)"

I prepare the JMeter script file on Windows. I copy the file to my Spring Maven project.

I prefer NOT to install the JMeter stuff in all my environments, so working with the jmeter-maven-plugin is a good solution.

Can you help me solving this very annoying issue?

My Maven plugin description is:

<plugin>
    <groupId>com.lazerycode.jmeter</groupId>
    <artifactId>jmeter-maven-plugin</artifactId>
    <version>2.7.0</version>
    <executions>
        <execution>
            <id>jmeter-tests</id>
            <goals>
                <goal>jmeter</goal>
            </goals>
            <phase>verify</phase>
        </execution>
    </executions>
    <configuration>
        <skipTests>${skipPerformanceTests}</skipTests>
        <testFilesDirectory>${project.basedir}/src/main/resources/jmeter</testFilesDirectory>
        <resultsDirectory>${project.basedir}/target/jmeter/testFiles</resultsDirectory>
        <resultsFileFormat>csv</resultsFileFormat>
    </configuration>
</plugin>

My JMeter script:

 <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="HTTP Request" enabled="true">
  <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
    <collectionProp name="Arguments.arguments">
      <elementProp name="" elementType="HTTPArgument">
        <boolProp name="HTTPArgument.always_encode">false</boolProp>
        <stringProp name="Argument.value"></stringProp>
        <stringProp name="Argument.metadata">=</stringProp>
        <boolProp name="HTTPArgument.use_equals">true</boolProp>
      </elementProp>
    </collectionProp>
  </elementProp>
  <stringProp name="HTTPSampler.domain"></stringProp>
  <stringProp name="HTTPSampler.port"></stringProp>
  <stringProp name="HTTPSampler.protocol"></stringProp>
  <stringProp name="HTTPSampler.contentEncoding"></stringProp>
  <stringProp name="HTTPSampler.path">http://127.0.0.1:8080/indexRoleA.html</stringProp>
  <stringProp name="HTTPSampler.method">GET</stringProp>
  <boolProp name="HTTPSampler.follow_redirects">true</boolProp>
  <boolProp name="HTTPSampler.auto_redirects">false</boolProp>
  <boolProp name="HTTPSampler.use_keepalive">true</boolProp>
  <boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
  <stringProp name="HTTPSampler.embedded_url_re"></stringProp>
  <stringProp name="HTTPSampler.connect_timeout"></stringProp>
  <stringProp name="HTTPSampler.response_timeout"></stringProp>
</HTTPSamplerProxy>

My JMeter HttpRequets are as simple as going to /indexRole.html.

Ardesco
  • 7,281
  • 26
  • 49
tm1701
  • 7,307
  • 17
  • 79
  • 168
  • 403 sounds like the webserver can be reached but doesn't have a web application at the path you try to access. Are you certain that the URL is correct as seen from the JMeter instance? 8080 might be the Jenkins instance and not the webserver that you think it is. – Thorbjørn Ravn Andersen Jan 12 '19 at 21:35
  • Tx. The website is active, I can reach it via a browser or other tests. My Jenkins is at port 8888. Can I configure something so that I can see which requests are fired? – tm1701 Jan 13 '19 at 12:35
  • Does the browser run inside docker? If not, you are not seeing the same as JMeter does. – Thorbjørn Ravn Andersen Jan 13 '19 at 21:47

2 Answers2

0

Please feel free to supply a better answer than this one. At the very least this is a good 'workaround'. I tried all combinations, including configuring Docker networks, etc. Please let me know if you have a better solution.

In summary, when starting Jenkins within a Docker container, it looked as if Jmeter could not connect to another (Docker) Spring Boot application on my PC.

So, I started the SpringBoot application from the Shell. This works:

try { 
  sh "mv target/jenkinstesting-0.1-SNAPSHOT.jar ./jenkingstest.jar"
  sh "nohup java -jar -Dserver.port=8081 ./jenkingstest.jar &"
  sh "mvn clean verify -Dmaven.test.skip=true -P performancetest"
} catch(e) {
  ...
}
sh "curl -X GET http://localhost:8081/exit"   // which will exit my application
sh "rm -f ./jenkingstest.jar"

Why using port 8081? Otherwise I get a conflict with other (started) testing stuff. And moving the JAR? The same reason. Any improvements are welcome!

tm1701
  • 7,307
  • 17
  • 79
  • 168
  • How did you tell docker the two instances should be able to see each other? – Thorbjørn Ravn Andersen Jan 13 '19 at 21:47
  • In the above solution I don't use Docker. Notice: I start the jenkinsjob within a Jenkins Docker instance. I put them both on the same network. I accessed the other via the container-id name. Any further suggestions? – tm1701 Jan 14 '19 at 18:05
0

The JMeter test is started from Maven. The Maven is executed within the Jenkins Docker container, thus working with Docker networks and container-names is required.

Solving the issue required therefore:

  • Determining the network of the Jenkins container (use: docker network ls)
  • When running the next scripts, the Docker container 'under test' was added to the determined network. The docker container received a clear container-name.
  • The test was performed with the URL to the (running) Docker container-name.

So, the test is started as a Jenkinsjob (within a Docker container) with:

sh "docker login -u ${env.DOCKER_USERNAME} -p ${env.DOCKER_PASSWORD}"
sh "docker build -t org/project1:latest ."
sh "docker run -d -p 8080:8080 --name jenkinsperformacetester --network=docker-compose_default org/project1:latest"
sh "mvn clean verify -Dmaven.test.skip=true -P performancetest"

This is the right solution. I was glad the mentioned 'workaround' is now declared obsolete.

tm1701
  • 7,307
  • 17
  • 79
  • 168