From bc3afb285b7f8522c2f0b43793ec853484d87723 Mon Sep 17 00:00:00 2001 From: mendhak Date: Sat, 10 May 2025 22:24:16 +0100 Subject: [PATCH 1/7] log_ignore_path env var now takes a regex --- index.js | 2 +- tests.sh | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index a380bea..5bb7894 100644 --- a/index.js +++ b/index.js @@ -175,7 +175,7 @@ app.all('*', (req, res) => { } //Certain paths can be ignored in the container logs, useful to reduce noise from healthchecks - if (process.env.LOG_IGNORE_PATH != req.path) { + if (!process.env.LOG_IGNORE_PATH || !new RegExp(process.env.LOG_IGNORE_PATH).test(req.path)) { let spacer = 4; if(process.env.LOG_WITHOUT_NEWLINE){ diff --git a/tests.sh b/tests.sh index d56f4e5..d26886d 100755 --- a/tests.sh +++ b/tests.sh @@ -270,7 +270,7 @@ docker stop http-echo-tests sleep 5 -message " Start container with LOG_IGNORE_PATH " +message " Start container with LOG_IGNORE_PATH (normal path)" 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 sleep 5 curl -s -k -X POST -d "banana" https://localhost:8443/ping > /dev/null @@ -285,6 +285,38 @@ else exit 1 fi +message " Stop containers " +docker stop http-echo-tests +sleep 5 + +message " Start container with LOG_IGNORE_PATH (regex path)" +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 +sleep 5 +curl -s -k -X POST -d "banana" https://localhost:8443/metrics > /dev/null + +if [ $(docker logs http-echo-tests | wc -l) == 2 ] && \ + ! [ $(docker logs http-echo-tests | grep banana) ] +then + passed "LOG_IGNORE_PATH ignored the /metrics path" +else + failed "LOG_IGNORE_PATH failed" + docker logs http-echo-tests + exit 1 +fi + +# Test a positive case where the path is not ignored +curl -s -k -X POST -d "strawberry" https://localhost:8443/veryvisible > /dev/null + +if [[ $(docker logs http-echo-tests | grep strawberry) ]] +then + passed "LOG_IGNORE_PATH didn't ignore the /veryvisible path" +else + failed "LOG_IGNORE_PATH failed, it should not ignore the /veryvisible path" + docker logs http-echo-tests + exit 1 +fi + + message " Stop containers " docker stop http-echo-tests From a1d80f77235dc5781a570c65ff01d23194b78287 Mon Sep 17 00:00:00 2001 From: mendhak Date: Sat, 10 May 2025 22:26:04 +0100 Subject: [PATCH 2/7] Update README with regex example for log ignore path --- README.md | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 879b4c2..ab2a7c5 100644 --- a/README.md +++ b/README.md @@ -116,22 +116,13 @@ In the log output set the environment variable `DISABLE_REQUEST_LOGS` to true, t ## Do not log specific path -Set the environment variable `LOG_IGNORE_PATH` to a path you would like to exclude from verbose logging to stdout. +Set the environment variable `LOG_IGNORE_PATH` to a path or a regex you would like to exclude from verbose logging to stdout. This can help reduce noise from healthchecks in orchestration/infrastructure like Swarm, Kubernetes, ALBs, etc. docker run -e LOG_IGNORE_PATH=/ping -p 8080:8080 -p 8443:8443 --rm -t mendhak/http-https-echo:36 + docker run -e LOG_IGNORE_PATH="^\/ping|^\/health|^\/metrics" -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:36 -With docker compose, this would be: - - my-http-listener: - image: mendhak/http-https-echo:36 - environment: - - LOG_IGNORE_PATH=/ping - ports: - - "8080:8080" - - "8443:8443" - ## JSON payloads and JSON output From fad4c1187385ca682b68d6dad8d415dd67ae0f7b Mon Sep 17 00:00:00 2001 From: mendhak Date: Sat, 10 May 2025 22:26:51 +0100 Subject: [PATCH 3/7] Changelog for 37 --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac11269..2cf5398 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## Version `37` - 2025-05-10 +* The `LOG_IGNORE_PATH` environment variable now takes a regex, so you can ignore multiple paths. + ## Version `36` - 2025-03-22 * Basic handling of gzip content-encoding on requests by [matt-mercer](https://github.com/mendhak/docker-http-https-echo/pull/79) From 1b948fda56d54a3e5e24fecb3a2e38ce2941f84c Mon Sep 17 00:00:00 2001 From: mendhak Date: Sat, 10 May 2025 22:39:51 +0100 Subject: [PATCH 4/7] Test to ignore all paths --- tests.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests.sh b/tests.sh index d26886d..ce94ef0 100755 --- a/tests.sh +++ b/tests.sh @@ -317,11 +317,30 @@ else fi +message " Stop containers " +docker stop http-echo-tests +sleep 5 + +message " Start container with LOG_IGNORE_PATH (ignore all paths) " +docker run -d --rm -e LOG_IGNORE_PATH=".*" --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:testing +sleep 5 +curl -s -k -X POST -d "banana" https://localhost:8443/ > /dev/null + +if [ $(docker logs http-echo-tests | wc -l) == 2 ] && \ + ! [ $(docker logs http-echo-tests | grep banana) ] +then + passed "LOG_IGNORE_PATH ignored all paths" +else + failed "LOG_IGNORE_PATH failed" + docker logs http-echo-tests + exit 1 +fi message " Stop containers " docker stop http-echo-tests sleep 5 + message " Start container with DISABLE_REQUEST_LOGS " 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 sleep 5 From fa983b906ec7ea953af70702d56b9b1081357141 Mon Sep 17 00:00:00 2001 From: mendhak Date: Sat, 10 May 2025 22:40:11 +0100 Subject: [PATCH 5/7] README example for ignoring all paths --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ab2a7c5..5a921bb 100644 --- a/README.md +++ b/README.md @@ -119,8 +119,12 @@ In the log output set the environment variable `DISABLE_REQUEST_LOGS` to true, t Set the environment variable `LOG_IGNORE_PATH` to a path or a regex you would like to exclude from verbose logging to stdout. This can help reduce noise from healthchecks in orchestration/infrastructure like Swarm, Kubernetes, ALBs, etc. - docker run -e LOG_IGNORE_PATH=/ping -p 8080:8080 -p 8443:8443 --rm -t mendhak/http-https-echo:36 - docker run -e LOG_IGNORE_PATH="^\/ping|^\/health|^\/metrics" -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:36 + # Ignore a single path + docker run -e LOG_IGNORE_PATH=/ping -p 8080:8080 -p 8443:8443 --rm -t mendhak/http-https-echo:36 + # Ignore multiple paths + docker run -e LOG_IGNORE_PATH="^\/ping|^\/health|^\/metrics" -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:36 + # Ignore all paths + docker run -e LOG_IGNORE_PATH=".*" -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:36 From 7bd456a55209adfb060a9a02cfa0a1c60714ce5f Mon Sep 17 00:00:00 2001 From: mendhak Date: Sat, 10 May 2025 22:58:27 +0100 Subject: [PATCH 6/7] Updating references to tag 37 in preparation for release later --- README.md | 32 ++++++++++++++++---------------- docker-compose.yml | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 5a921bb..a55102a 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ It comes with various options that can manipulate the response output, see the t ![browser](./screenshots/screenshot.png) -The image is available on [Docker Hub](https://hub.docker.com/r/mendhak/http-https-echo): `mendhak/http-https-echo:36` -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` +The image is available on [Docker Hub](https://hub.docker.com/r/mendhak/http-https-echo): `mendhak/http-https-echo:37` +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` Please do not use the `:latest` tag as it will break without warning, use a specific version instead. @@ -44,7 +44,7 @@ This image is executed as non root by default and is fully compliant with Kubern Run with Docker - docker run -p 8080:8080 -p 8443:8443 --rm -t mendhak/http-https-echo:36 + docker run -p 8080:8080 -p 8443:8443 --rm -t mendhak/http-https-echo:37 Or run with Docker Compose @@ -61,13 +61,13 @@ You can choose a different internal port instead of 8080 and 8443 with the `HTTP In this example I'm setting http to listen on 8888, and https to listen on 9999. - docker run -e HTTP_PORT=8888 -e HTTPS_PORT=9999 -p 8080:8888 -p 8443:9999 --rm -t mendhak/http-https-echo:36 + docker run -e HTTP_PORT=8888 -e HTTPS_PORT=9999 -p 8080:8888 -p 8443:9999 --rm -t mendhak/http-https-echo:37 With docker compose, this would be: my-http-listener: - image: mendhak/http-https-echo:36 + image: mendhak/http-https-echo:37 environment: - HTTP_PORT=8888 - HTTPS_PORT=9999 @@ -83,7 +83,7 @@ The certificates are at `/app/fullchain.pem` and `/app/privkey.pem`. You can use volume mounting to substitute the certificate and private key with your own. my-http-listener: - image: mendhak/http-https-echo:36 + image: mendhak/http-https-echo:37 ports: - "8080:8080" - "8443:8443" @@ -98,7 +98,7 @@ You can use the environment variables `HTTPS_CERT_FILE` and `HTTPS_KEY_FILE` to 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. - docker run -e JWT_HEADER=Authentication -p 8080:8080 -p 8443:8443 --rm -it mendhak/http-https-echo:36 + docker run -e JWT_HEADER=Authentication -p 8080:8080 -p 8443:8443 --rm -it mendhak/http-https-echo:37 Now make your request with `Authentication: eyJ...` header (it should also work with the `Authentication: Bearer eyJ...` schema too): @@ -111,7 +111,7 @@ And in the output you should see a `jwt` section. 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. - docker run --rm -e DISABLE_REQUEST_LOGS=true --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:36 + docker run --rm -e DISABLE_REQUEST_LOGS=true --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:37 ## Do not log specific path @@ -120,11 +120,11 @@ Set the environment variable `LOG_IGNORE_PATH` to a path or a regex you would li This can help reduce noise from healthchecks in orchestration/infrastructure like Swarm, Kubernetes, ALBs, etc. # Ignore a single path - docker run -e LOG_IGNORE_PATH=/ping -p 8080:8080 -p 8443:8443 --rm -t mendhak/http-https-echo:36 + docker run -e LOG_IGNORE_PATH=/ping -p 8080:8080 -p 8443:8443 --rm -t mendhak/http-https-echo:37 # Ignore multiple paths - docker run -e LOG_IGNORE_PATH="^\/ping|^\/health|^\/metrics" -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:36 + docker run -e LOG_IGNORE_PATH="^\/ping|^\/health|^\/metrics" -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:37 # Ignore all paths - docker run -e LOG_IGNORE_PATH=".*" -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:36 + docker run -e LOG_IGNORE_PATH=".*" -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:37 @@ -151,7 +151,7 @@ Will contain a `json` property in the response/output. You can disable new lines in the log output by setting the environment variable `LOG_WITHOUT_NEWLINE`. For example, ```bash -docker run -e LOG_WITHOUT_NEWLINE=true -p 8080:8080 -p 8443:8443 --rm -t mendhak/http-https-echo:36 +docker run -e LOG_WITHOUT_NEWLINE=true -p 8080:8080 -p 8443:8443 --rm -t mendhak/http-https-echo:37 ``` ## Send an empty response @@ -159,7 +159,7 @@ docker run -e LOG_WITHOUT_NEWLINE=true -p 8080:8080 -p 8443:8443 --rm -t mendhak You can disable the JSON output in the response by setting the environment variable `ECHO_BACK_TO_CLIENT`. For example, ```bash -docker run -e ECHO_BACK_TO_CLIENT=false -p 8080:8080 -p 8443:8443 --rm -t mendhak/http-https-echo:36 +docker run -e ECHO_BACK_TO_CLIENT=false -p 8080:8080 -p 8443:8443 --rm -t mendhak/http-https-echo:37 ``` ## Custom status code @@ -240,7 +240,7 @@ You can have environment variables (that are visible to the echo server's proces Pass the `ECHO_INCLUDE_ENV_VARS=1` environment variable in. ```bash -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 +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 ``` Then do a normal request via curl or browser, and you will see the `env` property in the response body. @@ -280,7 +280,7 @@ openssl pkcs12 -export -in cert.pem -inkey privkey.pem -out certpkcs12.pfx 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. ```bash -docker run -e PRESERVE_HEADER_CASE=true -p 8080:8080 -p 8443:8443 --rm -t mendhak/http-https-echo:36 +docker run -e PRESERVE_HEADER_CASE=true -p 8080:8080 -p 8443:8443 --rm -t mendhak/http-https-echo:37 ``` ## Override the response body with a file @@ -289,7 +289,7 @@ To override the response body with a file, set the environment variable `OVERRID The file path needs to be in the `/app` directory. ```bash -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 +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 ``` diff --git a/docker-compose.yml b/docker-compose.yml index c0728a5..9504585 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '3' services: my-http-listener: - image: mendhak/http-https-echo:36 + image: mendhak/http-https-echo:37 environment: - HTTP_PORT=8888 - HTTPS_PORT=9999 From 99fcbce68fd51d234386bfde1504cb3542dd935e Mon Sep 17 00:00:00 2001 From: mendhak Date: Thu, 22 May 2025 21:13:40 +0100 Subject: [PATCH 7/7] another way to ignore all paths --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a55102a..65ba6b2 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,7 @@ This can help reduce noise from healthchecks in orchestration/infrastructure lik docker run -e LOG_IGNORE_PATH="^\/ping|^\/health|^\/metrics" -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:37 # Ignore all paths docker run -e LOG_IGNORE_PATH=".*" -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:37 + docker run -e LOG_IGNORE_PATH="^" -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:37