Skip to content

Commit

Permalink
Merge pull request #5 from Informatievlaanderen/chore/add-queueing
Browse files Browse the repository at this point in the history
Chore/add queueing
  • Loading branch information
rorlic authored Apr 24, 2024
2 parents 93b39d3 + fb3d977 commit e5434fa
Show file tree
Hide file tree
Showing 10 changed files with 461 additions and 268 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# build environment
FROM node:20-bullseye-slim AS builder
# fix vulnerabilities
ARG NPM_TAG=9.9.2
ARG NPM_TAG=10.5.2
RUN npm install -g npm@${NPM_TAG}
# build it
WORKDIR /build
Expand All @@ -26,13 +26,13 @@ RUN mkdir -p jmeter-runner/tests
RUN mkdir -p jmeter-runner/temp
COPY --chown=node:node --from=builder /build/package*.json jmeter-runner/
COPY --chown=node:node --from=builder /build/dist/*.js jmeter-runner/
COPY --chown=node:node --from=builder /build/*.html jmeter-runner/
RUN cd ./jmeter-runner && npm ci --omit=dev
ENV BASE_URL=
ENV PORT=
ENV TEST_FOLDER_BASE=
ENV TEMP_FOLDER_BASE=
ENV SILENT=
ENV MAX_RUNNING=
ENV REFRESH_TIME=
ENV RUN_TEST_API_KEY=
ENV CHECK_TEST_API_KEY=
Expand Down Expand Up @@ -60,4 +60,4 @@ RUN echo "jmeter.reportgenerator.temp_dir=/tmp/jmeter" >> /home/node/apache-jmet
RUN chown node:node -R /home/node/*
WORKDIR /home/node/jmeter-runner
USER node
CMD ["sh", "-c", "node ./server.js --host=0.0.0.0 --port=${PORT} --base-url=${BASE_URL} --test-folder-base=${TEST_FOLDER_BASE} --temp-folder-base=${TEMP_FOLDER_BASE} --silent=${SILENT} --max-running=${MAX_RUNNING} --refresh-time=${REFRESH_TIME} --run-test-api-key=${RUN_TEST_API_KEY} --check-test-api-key=${CHECK_TEST_API_KEY} --delete-test-api-key=${DELETE_TEST_API_KEY} --custom-labels=\"${CUSTOM_LABELS}\""]
CMD ["sh", "-c", "node ./server.js --host=0.0.0.0 --port=${PORT} --base-url=${BASE_URL} --test-folder-base=${TEST_FOLDER_BASE} --temp-folder-base=${TEMP_FOLDER_BASE} --silent=${SILENT} --refresh-time=${REFRESH_TIME} --run-test-api-key=${RUN_TEST_API_KEY} --check-test-api-key=${CHECK_TEST_API_KEY} --delete-test-api-key=${DELETE_TEST_API_KEY} --custom-labels=\"${CUSTOM_LABELS}\""]
40 changes: 27 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ The jmeter runner takes the following command line arguments:
* `--silent=<true|false>` prevents any console debug output if true, defaults to false (not silent, logging all debug info)
* `--port=<port-number>` allows to set the port, defaults to `80`
* `--host=<host-name>` allows to set the hostname, defaults to `localhost`
* `--max-running` allows to set the maximum number of simultenaously running tests, defaults to `1`
* `--refresh-time` allows to change the status and overview page refresh time in seconds, defaults to `30`
* `--run-test-api-key` the API key to protect the run test endpoint, defaults to no API key checking
* `--check-test-api-key` the API key to protect the test status and results endpoints, defaults to no API key checking
Expand All @@ -79,13 +78,18 @@ Test runner listening at http://127.0.0.1:9000
## Usage
The jmeter runner accepts the following REST calls.

### `GET /` -- Get Test Runs Overview
Returns a HTML page listing the test runs per test and per category, e.g.
### `GET /test` -- Get Test Runs Overview
Returns a HTML page displaying the queued tests (if any), the currently running test (if any) and the completed test runs per test and per category, e.g.
```bash
curl http://localhost:9000/
curl http://localhost:9000/test
```

### `POST /` -- Start Test Run
> **Note** that you can cancel a running test on this page. Also see [Cancel a Test Run](#delete-testtest-run-idconfirmtrue----cancel-test-run-or-remove-test-and-results).

> **Note** that after cancelling a test you may need to cleanup your system being tested and therefore the jmeter runner will pause running (queued) tests until you [Resume the Runner](#post-statusresume----resume-the-runner-if-paused).
### `POST /test` -- Start Test Run
> **Note** that before running the jmeter [example test](./example.jmx) you will need to install an HTTP server (once) and serve the test page (in a separate bash shell):
```bash
npm install --global http-server
Expand All @@ -95,34 +99,36 @@ http-server ./example -p 8080
Initiates a jmeter test (mime-type: `application/xml`) and returns the test ID as well as a URL to the status page and the results page, e.g.
```bash
curl -X POST http://localhost:9000/ -H "Content-Type: application/xml" --data "@./example.jmx"
curl -X POST http://localhost:9000/test -H "Content-Type: application/xml" --data "@./example.jmx"
```
returns:
returns something like:
```json
{"id":"c47a3487-2f9f-433c-ab5a-82b196fff7e1","status":"http://localhost:9000/test/c47a3487-2f9f-433c-ab5a-82b196fff7e1","results":"http://localhost:9000/test/c47a3487-2f9f-433c-ab5a-82b196fff7e1/results/"}
{"id":"c47a3487-2f9f-433c-ab5a-82b196fff7e1"}
```

> **Note** that the results page will only exist after the test has completed and the status page allows you to follow the test progress and is automatically refreshed (see `--refresh-time`).
> **Note** that the jmeter runner extracts the test name from the jmeter test and uses it to group together all the test runs for the same test name. In addition, you can pass a category to allow grouping tests according to this category by appending a category name in the query string. E.g.:
```bash
curl -X POST http://localhost:9000/?category=Examples -H "Content-Type: application/xml" --data "@./example.jmx"
curl -X POST http://localhost:9000/test?category=Examples -H "Content-Type: application/xml" --data "@./example.jmx"
```

### `GET /<test-run-id>` -- Get Test Run Status
### `GET /test/<test-run-id>` -- Get Test Run Status
Returns a HTML page (auto-refreshed) with the status for the test run with the given ID.
```bash
curl http://localhost:9000/c47a3487-2f9f-433c-ab5a-82b196fff7e1
curl http://localhost:9000/test/c47a3487-2f9f-433c-ab5a-82b196fff7e1
```
> **Note** that the jmeter runner only displays the last 1000 lines by default. If you need to see more or less lines you can specify a `limit` as a query parameter. E.g.:
```bash
curl http://localhost:9000/c47a3487-2f9f-433c-ab5a-82b196fff7e1?limit=100
curl http://localhost:9000/test/c47a3487-2f9f-433c-ab5a-82b196fff7e1?limit=100
```
or if you want to display everything, you need to add a zero limit:
```bash
curl http://localhost:9000/c47a3487-2f9f-433c-ab5a-82b196fff7e1?limit=0
curl http://localhost:9000/test/c47a3487-2f9f-433c-ab5a-82b196fff7e1?limit=0
```

> **Note** that the jmeter runner will automatically redirect if the test is done to either the results (test completed) or the `jmeter.log` file (test cancelled).
### `GET /test/<test-run-id>/results` -- Get Test Run Results
Returns a HTML page with the results for the test run with the given ID.
```bash
Expand All @@ -139,6 +145,8 @@ If confirmed (`?confirm=true`), removes the test run with the given ID and its r
curl -X DELETE http://localhost:9000/test/c47a3487-2f9f-433c-ab5a-82b196fff7e1?confirm=true
```

> **Note** that you can also cancel a running test by clicking the `Cancel` button on [the test overview page](#get-test----get-test-runs-overview) next to the running test.
If not confirmed, a running test is simply cancelled. E.g.:
```bash
curl -X DELETE http://localhost:9000/test/c47a3487-2f9f-433c-ab5a-82b196fff7e1
Expand All @@ -156,3 +164,9 @@ curl -X DELETE http://localhost:9000/test

### `GET /prometheus` -- Get Metrics
Exposes the metrics using [Prometheus](https://prometheus.io/) format.

### `POST /status/resume` -- Resume the Runner if Paused
When you [Cancel a Test](#delete-testtest-run-idconfirmtrue----cancel-test-run-or-remove-test-and-results) you need to verify and if needed clean the state of your system under test (SUT). Therefore the jmeter runner will pause processing new tests by queue new test requests until you confirm that it should resume. E.g. :
```bash
curl -X POST http://localhost:9000/status/resume
```
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ services:
- TEMP_FOLDER_BASE=/home/node/jmeter-runner/temp
- BASE_URL=${BASE_URL:-http://localhost:9000}
- SILENT=${SILENT:-false}
- MAX_RUNNING=${MAX_RUNNING:-1}
- REFRESH_TIME=${REFRESH_TIME:-30}
- RUN_TEST_API_KEY=${RUN_TEST_API_KEY:-}
- CHECK_TEST_API_KEY=${CHECK_TEST_API_KEY:-}
Expand Down
56 changes: 56 additions & 0 deletions overview.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!DOCTYPE html>
<html>

<head>
<title>Test Runs Overview</title>
<meta http-equiv="refresh" content="{{refresh}}">
<script src="https://code.jquery.com/jquery-3.7.1.min.js"
integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
<script type="text/javascript">
function reload() { location.reload(); }
function cancelTest(id, headers) { $.ajax({ type: "DELETE", url: "/test/" + id, headers: headers, success: reload }); }
function resume(headers) { $.ajax({ type: "POST", url: "/status/resume", headers: headers, success: reload }); }
</script>
</head>

<body>
<h1>Test Runner</h1>
<p><strong>Status</strong>: {{status}}{{#action}} <input id="action" type="button" value="{{label}}"
onclick="{{onClick}}" />{{/action}}</p>
<h2>Queued Tests</h2>
{{^queued}}
<p>No queued tests found.</p>
{{/queued}}
<ul>
{{#queued}}
<li>{{name}} (queued at: {{timestamp}}, category: {{category}})</li>
{{/queued}}
</ul>
<h2>Running Test</h2>
{{^current}}
<p>No test running.</p>
{{/current}}
{{#current}}
<p>
<strong>Test</strong>: {{name}}</br>
<strong>Started at</strong>: {{timestamp}}, see <a href="{{link}}" target="_blank">{{text}}</a></br>
<strong>Category</strong>: {{category}}
</p>
{{/current}}
<h2>Completed Tests</h2>
{{^tests}}
<p>No completed tests found.</p>
{{/tests}}
{{#tests}}
<h3>Category: {{category}}</h3>
{{#group}}<h4>Test: {{name}}</h4>
<ul>
{{#group}}
<li>Test run started at {{timestamp}}: {{status}}, see <a href="{{link}}" target="_blank">{{text}}</a></li>
{{/group}}
</ul>
{{/group}}
{{/tests}}
</body>

</html>
Loading

0 comments on commit e5434fa

Please sign in to comment.