Skip to content

Commit c77a6df

Browse files
authored
Merge pull request #81 from mendhak/log_ignore_regex
Log ignore path takes a regex
2 parents ced7692 + 99fcbce commit c77a6df

File tree

5 files changed

+78
-28
lines changed

5 files changed

+78
-28
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## Version `37` - 2025-05-10
2+
* The `LOG_IGNORE_PATH` environment variable now takes a regex, so you can ignore multiple paths.
3+
14
## Version `36` - 2025-03-22
25
* Basic handling of gzip content-encoding on requests by [matt-mercer](https://github.com/mendhak/docker-http-https-echo/pull/79)
36

README.md

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ It comes with various options that can manipulate the response output, see the t
88

99
![browser](./screenshots/screenshot.png)
1010

11-
The image is available on [Docker Hub](https://hub.docker.com/r/mendhak/http-https-echo): `mendhak/http-https-echo:36`
12-
The image is available on [Github Container Registry](https://github.com/mendhak/docker-http-https-echo/pkgs/container/http-https-echo): `ghcr.io/mendhak/http-https-echo:36`
11+
The image is available on [Docker Hub](https://hub.docker.com/r/mendhak/http-https-echo): `mendhak/http-https-echo:37`
12+
The image is available on [Github Container Registry](https://github.com/mendhak/docker-http-https-echo/pkgs/container/http-https-echo): `ghcr.io/mendhak/http-https-echo:37`
1313

1414
Please do not use the `:latest` tag as it will break without warning, use a specific version instead.
1515

@@ -44,7 +44,7 @@ This image is executed as non root by default and is fully compliant with Kubern
4444

4545
Run with Docker
4646

47-
docker run -p 8080:8080 -p 8443:8443 --rm -t mendhak/http-https-echo:36
47+
docker run -p 8080:8080 -p 8443:8443 --rm -t mendhak/http-https-echo:37
4848

4949
Or run with Docker Compose
5050

@@ -61,13 +61,13 @@ You can choose a different internal port instead of 8080 and 8443 with the `HTTP
6161

6262
In this example I'm setting http to listen on 8888, and https to listen on 9999.
6363

64-
docker run -e HTTP_PORT=8888 -e HTTPS_PORT=9999 -p 8080:8888 -p 8443:9999 --rm -t mendhak/http-https-echo:36
64+
docker run -e HTTP_PORT=8888 -e HTTPS_PORT=9999 -p 8080:8888 -p 8443:9999 --rm -t mendhak/http-https-echo:37
6565

6666

6767
With docker compose, this would be:
6868

6969
my-http-listener:
70-
image: mendhak/http-https-echo:36
70+
image: mendhak/http-https-echo:37
7171
environment:
7272
- HTTP_PORT=8888
7373
- HTTPS_PORT=9999
@@ -83,7 +83,7 @@ The certificates are at `/app/fullchain.pem` and `/app/privkey.pem`.
8383
You can use volume mounting to substitute the certificate and private key with your own.
8484

8585
my-http-listener:
86-
image: mendhak/http-https-echo:36
86+
image: mendhak/http-https-echo:37
8787
ports:
8888
- "8080:8080"
8989
- "8443:8443"
@@ -98,7 +98,7 @@ You can use the environment variables `HTTPS_CERT_FILE` and `HTTPS_KEY_FILE` to
9898

9999
If you specify the header that contains the JWT, the echo output will contain the decoded JWT. Use the `JWT_HEADER` environment variable for this.
100100

101-
docker run -e JWT_HEADER=Authentication -p 8080:8080 -p 8443:8443 --rm -it mendhak/http-https-echo:36
101+
docker run -e JWT_HEADER=Authentication -p 8080:8080 -p 8443:8443 --rm -it mendhak/http-https-echo:37
102102

103103

104104
Now make your request with `Authentication: eyJ...` header (it should also work with the `Authentication: Bearer eyJ...` schema too):
@@ -111,27 +111,23 @@ And in the output you should see a `jwt` section.
111111

112112
In the log output set the environment variable `DISABLE_REQUEST_LOGS` to true, to disable the specific ExpressJS request log lines. The ones like `::ffff:172.17.0.1 - - [03/Jan/2022:21:31:51 +0000] "GET /xyz HTTP/1.1" 200 423 "-" "curl/7.68.0"`. The JSON output will still appear.
113113

114-
docker run --rm -e DISABLE_REQUEST_LOGS=true --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:36
114+
docker run --rm -e DISABLE_REQUEST_LOGS=true --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:37
115115

116116

117117
## Do not log specific path
118118

119-
Set the environment variable `LOG_IGNORE_PATH` to a path you would like to exclude from verbose logging to stdout.
119+
Set the environment variable `LOG_IGNORE_PATH` to a path or a regex you would like to exclude from verbose logging to stdout.
120120
This can help reduce noise from healthchecks in orchestration/infrastructure like Swarm, Kubernetes, ALBs, etc.
121121

122-
docker run -e LOG_IGNORE_PATH=/ping -p 8080:8080 -p 8443:8443 --rm -t mendhak/http-https-echo:36
122+
# Ignore a single path
123+
docker run -e LOG_IGNORE_PATH=/ping -p 8080:8080 -p 8443:8443 --rm -t mendhak/http-https-echo:37
124+
# Ignore multiple paths
125+
docker run -e LOG_IGNORE_PATH="^\/ping|^\/health|^\/metrics" -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:37
126+
# Ignore all paths
127+
docker run -e LOG_IGNORE_PATH=".*" -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:37
128+
docker run -e LOG_IGNORE_PATH="^" -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:37
123129

124130

125-
With docker compose, this would be:
126-
127-
my-http-listener:
128-
image: mendhak/http-https-echo:36
129-
environment:
130-
- LOG_IGNORE_PATH=/ping
131-
ports:
132-
- "8080:8080"
133-
- "8443:8443"
134-
135131

136132
## JSON payloads and JSON output
137133

@@ -156,15 +152,15 @@ Will contain a `json` property in the response/output.
156152
You can disable new lines in the log output by setting the environment variable `LOG_WITHOUT_NEWLINE`. For example,
157153

158154
```bash
159-
docker run -e LOG_WITHOUT_NEWLINE=true -p 8080:8080 -p 8443:8443 --rm -t mendhak/http-https-echo:36
155+
docker run -e LOG_WITHOUT_NEWLINE=true -p 8080:8080 -p 8443:8443 --rm -t mendhak/http-https-echo:37
160156
```
161157

162158
## Send an empty response
163159

164160
You can disable the JSON output in the response by setting the environment variable `ECHO_BACK_TO_CLIENT`. For example,
165161

166162
```bash
167-
docker run -e ECHO_BACK_TO_CLIENT=false -p 8080:8080 -p 8443:8443 --rm -t mendhak/http-https-echo:36
163+
docker run -e ECHO_BACK_TO_CLIENT=false -p 8080:8080 -p 8443:8443 --rm -t mendhak/http-https-echo:37
168164
```
169165

170166
## Custom status code
@@ -245,7 +241,7 @@ You can have environment variables (that are visible to the echo server's proces
245241
Pass the `ECHO_INCLUDE_ENV_VARS=1` environment variable in.
246242

247243
```bash
248-
docker run -d --rm -e ECHO_INCLUDE_ENV_VARS=1 --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:36
244+
docker run -d --rm -e ECHO_INCLUDE_ENV_VARS=1 --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:37
249245
```
250246

251247
Then do a normal request via curl or browser, and you will see the `env` property in the response body.
@@ -285,7 +281,7 @@ openssl pkcs12 -export -in cert.pem -inkey privkey.pem -out certpkcs12.pfx
285281
By default, the headers in the response body are lowercased. To attempt to preserve the case of headers in the response body, set the environment variable `PRESERVE_HEADER_CASE` to true.
286282

287283
```bash
288-
docker run -e PRESERVE_HEADER_CASE=true -p 8080:8080 -p 8443:8443 --rm -t mendhak/http-https-echo:36
284+
docker run -e PRESERVE_HEADER_CASE=true -p 8080:8080 -p 8443:8443 --rm -t mendhak/http-https-echo:37
289285
```
290286

291287
## Override the response body with a file
@@ -294,7 +290,7 @@ To override the response body with a file, set the environment variable `OVERRID
294290
The file path needs to be in the `/app` directory.
295291

296292
```bash
297-
docker run -d --rm -v ${PWD}/test.html:/app/test.html -p 8080:8080 -e OVERRIDE_RESPONSE_BODY_FILE_PATH=/test.html -t mendhak/http-https-echo:36
293+
docker run -d --rm -v ${PWD}/test.html:/app/test.html -p 8080:8080 -e OVERRIDE_RESPONSE_BODY_FILE_PATH=/test.html -t mendhak/http-https-echo:37
298294
```
299295

300296

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: '3'
22
services:
33
my-http-listener:
4-
image: mendhak/http-https-echo:36
4+
image: mendhak/http-https-echo:37
55
environment:
66
- HTTP_PORT=8888
77
- HTTPS_PORT=9999

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ app.all('*', (req, res) => {
175175
}
176176

177177
//Certain paths can be ignored in the container logs, useful to reduce noise from healthchecks
178-
if (process.env.LOG_IGNORE_PATH != req.path) {
178+
if (!process.env.LOG_IGNORE_PATH || !new RegExp(process.env.LOG_IGNORE_PATH).test(req.path)) {
179179

180180
let spacer = 4;
181181
if(process.env.LOG_WITHOUT_NEWLINE){

tests.sh

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ docker stop http-echo-tests
270270
sleep 5
271271

272272

273-
message " Start container with LOG_IGNORE_PATH "
273+
message " Start container with LOG_IGNORE_PATH (normal path)"
274274
docker run -d --rm -e LOG_IGNORE_PATH=/ping --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:testing
275275
sleep 5
276276
curl -s -k -X POST -d "banana" https://localhost:8443/ping > /dev/null
@@ -285,11 +285,62 @@ else
285285
exit 1
286286
fi
287287

288+
message " Stop containers "
289+
docker stop http-echo-tests
290+
sleep 5
291+
292+
message " Start container with LOG_IGNORE_PATH (regex path)"
293+
docker run -d --rm -e LOG_IGNORE_PATH="^\/ping|^\/health|^\/metrics" --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:testing
294+
sleep 5
295+
curl -s -k -X POST -d "banana" https://localhost:8443/metrics > /dev/null
296+
297+
if [ $(docker logs http-echo-tests | wc -l) == 2 ] && \
298+
! [ $(docker logs http-echo-tests | grep banana) ]
299+
then
300+
passed "LOG_IGNORE_PATH ignored the /metrics path"
301+
else
302+
failed "LOG_IGNORE_PATH failed"
303+
docker logs http-echo-tests
304+
exit 1
305+
fi
306+
307+
# Test a positive case where the path is not ignored
308+
curl -s -k -X POST -d "strawberry" https://localhost:8443/veryvisible > /dev/null
309+
310+
if [[ $(docker logs http-echo-tests | grep strawberry) ]]
311+
then
312+
passed "LOG_IGNORE_PATH didn't ignore the /veryvisible path"
313+
else
314+
failed "LOG_IGNORE_PATH failed, it should not ignore the /veryvisible path"
315+
docker logs http-echo-tests
316+
exit 1
317+
fi
318+
288319

289320
message " Stop containers "
290321
docker stop http-echo-tests
291322
sleep 5
292323

324+
message " Start container with LOG_IGNORE_PATH (ignore all paths) "
325+
docker run -d --rm -e LOG_IGNORE_PATH=".*" --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:testing
326+
sleep 5
327+
curl -s -k -X POST -d "banana" https://localhost:8443/ > /dev/null
328+
329+
if [ $(docker logs http-echo-tests | wc -l) == 2 ] && \
330+
! [ $(docker logs http-echo-tests | grep banana) ]
331+
then
332+
passed "LOG_IGNORE_PATH ignored all paths"
333+
else
334+
failed "LOG_IGNORE_PATH failed"
335+
docker logs http-echo-tests
336+
exit 1
337+
fi
338+
339+
message " Stop containers "
340+
docker stop http-echo-tests
341+
sleep 5
342+
343+
293344
message " Start container with DISABLE_REQUEST_LOGS "
294345
docker run -d --rm -e DISABLE_REQUEST_LOGS=true --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:testing
295346
sleep 5

0 commit comments

Comments
 (0)