Skip to content

fix(#8179) Add support for nginx and haproxy returning json error pages - #8446

Merged
nydr merged 11 commits into
masterfrom
dn/8179-nginx-json
Aug 31, 2023
Merged

fix(#8179) Add support for nginx and haproxy returning json error pages#8446
nydr merged 11 commits into
masterfrom
dn/8179-nginx-json

Conversation

@nydr

@nydr nydr commented Aug 10, 2023

Copy link
Copy Markdown
Contributor

Description

Resolves #8179 - nginx and haproxy should respect Accept headers when responding with error templates

Code review checklist

  • Documented: Configuration and user documentation on cht-docs
  • Tested: Unit and/or e2e where appropriate
  • Backwards compatible: Works with existing data and configuration or includes a migration. Any breaking changes documented in the release notes.

Compose URLs

If Build CI hasn't passed, these may 404:

License

The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.

@mrjones-plip mrjones-plip left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work - thanks very much @nydr ! This took a bit longer for me because I don't know some of the techniques you use inside nginx and docker - but they were fun to learn!

For the most part this PR is good to go. I was able to spin up a vanilla 4.2.0 CHT instance and a one with the nginx running the public.ecr.aws/medic/cht-nginx:4.3.0-dn-8179-nginx-json image. Smoke testing the web app worked fine in latest Chrome on Ubuntu 20.

As well, i wrote a little one liner and tried docker kill ... on the same service in each Core deployments. JSON was correctly returned! \o/

➜  nginx git:(dn/8179-nginx-json) ✗ echo "\n------------8179 branch------------";curl  -H "Accept: application/json"   https://192-168-68-26.local-ip.medicmobile.org:10451/api/v2/monitoring ; echo "\n\n-------------4.2.0-----------------" ; curl  -H "Accept: application/json"   https://192-168-68-26.local-ip.medicmobile.org:10450/api/v2/monitoring


------------8179 branch------------
{"version":{"app":"4.2.2.5489334896","node":"v16.20.1","couchdb":"2.3.1"},"couchdb":{"medic":{"name":"medic","update_sequence":117---SNIP-TRUNCATE-JSON--connected_users":{"count":1}}

-------------4.2.0-----------------
{"version":{"app":"4.2.0.5075680573","node":"v16.20.0","couchdb":"2.3.1"},"couchdb":{"medic":{"name":"medic","update_sequence":136---SNIP-TRUNCATE-JSON--connected_users":{"count":1}}                                                                  

➜  nginx git:(dn/8179-nginx-json) ✗ docker kill test_nginx_error_pages_8446_api_1 four_two__yay_api_1 
test_nginx_error_pages_8446_api_1
four_two__yay_api_1

➜  nginx git:(dn/8179-nginx-json) ✗ echo "\n------------8179 branch------------";curl  -H "Accept: application/json"   https://192-168-68-26.local-ip.medicmobile.org:10451/api/v2/monitoring ; echo "\n\n-------------4.2.0-----------------" ; curl  -H "Accept: application/json"   https://192-168-68-26.local-ip.medicmobile.org:10450/api/v2/monitoring


------------8179 branch------------
{
  "type": "ERROR",
  "error": "502 Bad Gateway",
  "server": "nginx"
}

-------------4.2.0-----------------
<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.19.6</center>
</body>
</html>

I suspect this PR would be good as is, but I had one major change request as well as some minor ones and a one nitpick. Oh, and some questions too! If the questions end up blocking too much, feel free to resolve them and we can just chat on slack/ad hoc vid call!

Thanks again!

Comment thread .github/workflows/nginx_test.yml
Comment thread .github/workflows/nginx_test.yml Outdated
Comment thread nginx/Dockerfile Outdated
Comment thread nginx/Makefile Outdated
Comment thread nginx/docker-compose.test.yml
Comment thread nginx/nginx_error_pages/generate.sh
Comment thread nginx/nginx.conf
Comment thread nginx/tests/compose.bats Outdated
Comment thread nginx/Dockerfile
Comment thread nginx/Dockerfile Outdated
@mrjones-plip

Copy link
Copy Markdown
Contributor

Oh yes! I forgot to compliment you on the test coverage here ! Great to see this as a hopefully a new standard of PRs - we really could use it.

@dianabarsan dianabarsan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fantastic work, @nydr . I'm really impressed.

@mrjones-plip has done a great job adding comments, that I don't have anything further to request.

@mrjones-plip

This comment was marked as resolved.

@nydr
nydr requested a review from mrjones-plip August 14, 2023 15:25
mrjones-plip

This comment was marked as resolved.

@nydr

This comment was marked as resolved.

Comment thread nginx/tests/with_mock.bats Outdated
@nydr
nydr requested a review from mrjones-plip August 21, 2023 07:33
@nydr

This comment was marked as resolved.

@nydr nydr changed the title chore(#8179) Add support for nginx returning json error pages chore(#8179) Add support for nginx and haproxy returning json error pages Aug 24, 2023
@nydr

This comment was marked as resolved.

@garethbowen garethbowen changed the title chore(#8179) Add support for nginx and haproxy returning json error pages fix(#8179) Add support for nginx and haproxy returning json error pages Aug 27, 2023
@mrjones-plip

This comment was marked as resolved.

@nydr

nydr commented Aug 30, 2023

Copy link
Copy Markdown
Contributor Author

Thanks for checking @mrjones-plip! I've updated the PR so it should pass now

@mrjones-plip mrjones-plip left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really good work here @nydr ! Thanks very much for working through my feedback.

ship it 🚢

Replace `as` with upper case format `AS`.
@sonarqubecloud

Copy link
Copy Markdown

SonarCloud Quality Gate failed.    Quality Gate failed

Bug C 140 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@nydr

nydr commented Aug 31, 2023

Copy link
Copy Markdown
Contributor Author

SonarCloud Quality Gate failed.    Quality Gate failed

Added minor Code Smell fix. Ignoring the 140 Bugs from SonarCloud as they are all based on modern html convention and the template is following the default nginx format for error pages [ref]. Suggestion for fixing linting Bugs in #8509.

@nydr
nydr merged commit 0086150 into master Aug 31, 2023
@nydr
nydr deleted the dn/8179-nginx-json branch August 31, 2023 10:27
@nydr nydr mentioned this pull request Feb 19, 2024
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nginx and haproxy should respect Accept headers when responding with error templates

3 participants