Skip to content

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

Merged
nydr merged 6 commits into
dn/8179-nginx-jsonfrom
dn/8179-haproxy-json
Aug 24, 2023
Merged

chore(#8179) Add json error messages to haproxy#8481
nydr merged 6 commits into
dn/8179-nginx-jsonfrom
dn/8179-haproxy-json

Conversation

@nydr

@nydr nydr commented Aug 22, 2023

Copy link
Copy Markdown
Contributor

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

nydr commented Aug 22, 2023

Copy link
Copy Markdown
Contributor Author

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

@nydr
nydr requested review from Hareet and garethbowen August 22, 2023 20:50
@garethbowen

Copy link
Copy Markdown
Contributor

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.

@garethbowen garethbowen 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.

Great work, thanks! Some thoughts inline.

Comment thread haproxy/errors/README.md
# 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
Copy Markdown
Contributor

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
Copy Markdown
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.

Comment thread haproxy/compose.yml
timeout http-keep-alive 5m

errorfiles json

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.

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

Copy link
Copy Markdown
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice script! Thanks.

Comment thread haproxy/tests/with_mock.bats
@nydr
nydr requested a review from garethbowen August 23, 2023 16:03

@garethbowen garethbowen 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.

Looks great! Thanks.

@nydr
nydr merged commit 6c1b854 into dn/8179-nginx-json Aug 24, 2023
@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