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

Add a configurable default backend. #426

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft

Conversation

sengi
Copy link
Contributor

@sengi sengi commented Jan 22, 2024

For all requests that don't match any path or path prefix in the database, forward the request to ROUTER_DEFAULT_BACKEND_URL. This defaults to government-frontend, which is where 93% of routes go.

This should allow shrinking the route database by an order of magnitude as well as making it a little easier to eliminate Router in the long run.

We no longer respond 503 to all requests when the route database is empty. That feature was presumably conceived as a kind of lameduck mode (albeit somewhat buggy). We're almost certainly better off without it now that an empty database doesn't mean we're completely broken.

@sengi sengi force-pushed the sengi/default-route branch from 1442a30 to 7b67e02 Compare January 22, 2024 10:47
@sengi sengi marked this pull request as ready for review January 22, 2024 10:50
sengi added 6 commits January 22, 2024 16:00
For all requests that don't match any path or path prefix in the
database, forward the request to ROUTER_DEFAULT_BACKEND_URL. This
defaults to `government-frontend`, which is where 93% of routes go.

This should allow shrinking the route database by an order of magnitude
as well as making it a little easier to eliminate Router in the long
run.

We no longer respond 503 to all requests when the route database is
empty. This feature was presumably conceived as a kind of lameduck
mode (albeit somewhat buggy). We're almost certainly better off without
it now that an empty database doesn't mean we're completely broken.
- Use common terminology e.g. "HTTP method".
- Make the `Describe` / `It` test names fit together better.
- Trivial style cleanup to reduce boilerplate somewhat.
- Remove unnecessary conditionals around time.Sleep().
- Use const.
This also gets rid of change-detectors on error response bodies (which
we don't care about, because the edge caches replace them with prettier
ones anyway).

https://onsi.github.io/gomega/#working-with-http-responses

Generated with:

```sh
g grep -l resp.StatusCode integration_tests | xargs gsed -i \
  's/Expect(resp.StatusCode)\.To(Equal(\([0-9]\{3\}\)))/Expect(resp).To(HaveHTTPStatus(\1))/'
```
@sengi sengi force-pushed the sengi/default-route branch from 7b67e02 to f06f154 Compare January 22, 2024 16:52
Copy link
Contributor

@theseanything theseanything left a comment

Choose a reason for hiding this comment

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

Thanks Chris! Agree, this seems like a sensible change. I'm pretty sure that Rails will return 404 for a route it doesn't have - but I think government-frontend has wildcard route that catches everything and then gets handled by the content-item controller. I think there is assumption that there must be a content item in the Content Store if request is routed from router - so unsure what happens it raise an exception. However, it might be safe due to the rescue clauses.

Worth testing to see how government frontend behaves.

@sengi
Copy link
Contributor Author

sengi commented Jan 26, 2024

Ohh good shout, thanks! I'll go explore that before I think about rolling this out 🙇

@sengi sengi marked this pull request as draft February 22, 2024 16:13
@sengi
Copy link
Contributor Author

sengi commented Feb 22, 2024

Did some exploratory testing in the staging environment and all seems happy apart from organisations pages like these: (links unfortunately need VPN or they'll error)

All the other gov-frontend document types seem ok though 🧐

I'll set this back to draft while I figure out what's going on there.

@sengi
Copy link
Contributor Author

sengi commented Feb 22, 2024

Ughhh it's because those pages have paths that shadow shorter path prefixes that go elsewhere 😫 (why, GOV.UK, whyyyyy)

production:PRIMARY> db.routes.find({
  incoming_path: '/government/organisations/hm-revenue-customs'
})
{
  "_id" : ObjectId("5ae1e0b545a5a01908a01215"),
  "backend_id" : "collections",
  "disabled" : false,
  "handler" : "backend",
  "incoming_path" : "/government/organisations/hm-revenue-customs",
  "route_type" : "prefix",
  "updated_at" : ISODate("2023-05-15T16:08:31.165Z")
}
production:PRIMARY> db.routes.find({
  incoming_path: '/government/organisations/hm-revenue-customs/contact/excise-enquiries'
})
{
  "_id" : ObjectId("546dcf7e45a5a0a5a2000121"),
  "backend_id" : "government-frontend",
  "disabled" : false,
  "handler" : "backend",
  "incoming_path" : "/government/organisations/hm-revenue-customs/contact/excise-enquiries",
  "route_type" : "exact"
}

@sengi
Copy link
Contributor Author

sengi commented Feb 22, 2024

Easy enough to just put a fancier filter on the deleteMany() one-off cleanup ofc, but it's disappointing if we're gonna be stuck with some annoying corner cases in government-frontend where it still has to poke at router-api 🫤

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