Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(#8179) Add json error messages to haproxy #8481

Merged
merged 6 commits into from
Aug 24, 2023

Conversation

nydr
Copy link
Contributor

@nydr nydr commented Aug 22, 2023

Description

For the HAProxy part of #8179 - nginx and haproxy should respect Accept headers when responding with error templates

Code review checklist

  • 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.

@nydr
Copy link
Contributor Author

nydr commented Aug 22, 2023

Targeting branch in PR #8446 as it builds on changes from there. Will update target if that PR gets merged first. Please let me know if you have another preferred workflow for PRs that builds on other PRs

CC @dianabarsan @jonathanvq @mrjones-plip

@garethbowen
Copy link
Member

Targeting branch in PR #8446 as it builds on changes from there. Will update target if that PR gets merged first.

That process is fine. I did get a bit confused for a second but worked it out.

Copy link
Member

@garethbowen garethbowen left a comment

Choose a reason for hiding this comment

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

Great work, thanks! Some thoughts inline.

# nginx_error_messages

This directory contains error pages for haproxy. Do not update the error pages
manually, instead look in `generate.sh` and the `template.json` file
Copy link
Member

Choose a reason for hiding this comment

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

In general I prefer generated code to not be checked in to the repo, and instead generated in CI and published. This means someone doesn't accidentally manually update the output and saves on duplication. What do you think? Is there an advantage to checking in the build output?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can see arguments on both sides. The main reason I went with the more explicit pre-generated files is that I expect these will change at most 1-2 times per year and I didn't want to add complexity to the general build process. I imagine debugging an issue with the generated files without having been involved in this PR be more difficult if they're generated on build/start.

What if I add a test to ensure the current files are equal to how they will look when running generate.sh? I prefer that over build step as it doesn't complicate the build process and can be run independently from the build. I added a suggestion to what that could look like in this PR in the file haproxy/tests/errors_generate.bats feel free to review that one.

haproxy/compose.yml Outdated Show resolved Hide resolved
@@ -19,6 +40,9 @@ defaults
timeout server 360000000
timeout connect 1500000
timeout http-keep-alive 5m

errorfiles json

Copy link
Member

Choose a reason for hiding this comment

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

If I understand this correctly, this will always respond with JSON regardless of the Accepts header?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct, since HAProxy is not being called directly by browsers or mobile apps adding a conditional can be considered unnecessary logic (feel free to discuss further in #8179)


echo " errorfile $status_code /usr/local/etc/haproxy/errors/${status_code}-json.http"

done
Copy link
Member

Choose a reason for hiding this comment

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

Nice script! Thanks.

haproxy/tests/with_mock.bats Show resolved Hide resolved
@nydr nydr requested a review from garethbowen August 23, 2023 16:03
Copy link
Member

@garethbowen garethbowen left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks.

@nydr nydr merged commit 6c1b854 into dn/8179-nginx-json Aug 24, 2023
29 checks passed
@nydr nydr deleted the dn/8179-haproxy-json branch August 24, 2023 13:18
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.

2 participants