-
Notifications
You must be signed in to change notification settings - Fork 23
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
Router on postgres #389
base: main
Are you sure you want to change the base?
Router on postgres #389
Conversation
4596254
to
268d251
Compare
2b73fb8
to
cff0771
Compare
e2a0e19
to
266ed28
Compare
pq is a standard library for interacting with postgresql databases in golang. It is currently in maintenance mode so is as stable as it can be for the foreseeable future.
The underlying functionality is the same, but we are moving away from mongo to postgres to ensure we can continue to maintain the app. We no longer keep soft copies of the data read from the database, instead reading each row from memory. We no longer rely on comparing OpTime from Mongo changes, instead relying on PSQL's LISTEN/NOTIFY process to notify us of changes. However, in order to avoid overloading with constant update requests, we still poll the update every two seconds.
266ed28
to
16aeef6
Compare
Makefile
Outdated
--health-start-period 5s \ | ||
postgres:14; \ | ||
echo Waiting for postgres to be up; \ | ||
until [ "`docker inspect -f '{{.State.Health.Status}}' router-postgres-test-db`" = "healthy" ]; do \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optional: if Docker or the container fails then this could get stuck for a long time (6h on GitHub Actions), so could so with for _ in $(seq 30)
so we fail faster
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry that was meant to be sent along with the review rather than as a one-off (I hit the wrong button)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool — I like the minimal approach.
Makefile
Outdated
--health-start-period 5s \ | ||
postgres:14; \ | ||
echo Waiting for postgres to be up; \ | ||
until [ "`docker inspect -f '{{.State.Health.Status}}' router-postgres-test-db`" = "healthy" ]; do \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry that was meant to be sent along with the review rather than as a one-off (I hit the wrong button)
RedirectType string `bson:"redirect_type"` | ||
SegmentsMode string `bson:"segments_mode"` | ||
Disabled bool `bson:"disabled"` | ||
IncomingPath sql.NullString |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optional: it'd be neat if we could use plain old strings here and deal with the nullability in loadRoutes
or wherever, then we could delete this struct's evil twin in integration_tests/route_helpers.go
. (Would also mean you wouldn't need to deal with nulls in all the places that use struct Route.)
for _, instance := range replicaSet.Members { | ||
if instance.Current { | ||
currentInstance = append(currentInstance, instance) | ||
func (rt *Router) shouldReload(listener *pq.Listener) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is so much neater — I love it
localdb_init.sql
Outdated
FOR EACH ROW | ||
EXECUTE PROCEDURE notify_listeners(); | ||
|
||
CREATE TRIGGER rotues_notify_trigger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
harmless typo
CREATE TRIGGER rotues_notify_trigger | |
CREATE TRIGGER routes_notify_trigger |
@@ -0,0 +1,67 @@ | |||
DROP DATABASE IF EXISTS router_test; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(no action needed) It's kind of a shame we need this almost-but-not-quite-identical copy of the schema here, but I agree it's probably the right call in the interests of time rather than revamping the way the tests work to pull in the real schema from router-api 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with @sengi
The very slight downside of having router-api being the source of the database is that it makes everything in govuk-docker that depends on router now also dependent on router-api. But the advantages of having it as an ordinary rails migration outweighs that (plus the fact that router/router-api doesn't really work on govuk-docker at the moment anyway, and converting to PG might unblock that problem).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That just sounds like a govuk-docker bug/flaw tbh :) I hope next quarter we'll be able to make govuk-helm-charts portable enough to replace at least some govuk-docker use cases in local development / testing.
my optionals are genuinely optional btw — totally fine if you prefer not to do them (and no need to justify!) |
Very little of the tests themselves had to be rewritten to reflect the system being postgres, however a number of tests that relied on mocking Mongo are no longer valid in the Postgres implementation and have been removed. We now spin up a test PSQL database container using an initialiser sql file to test against.
16aeef6
to
6e91739
Compare
The underlying functionality is the same, but we are moving away from
mongo to postgres to ensure we can continue to maintain the app.
We no longer keep soft copies of the data read from the database,
instead reading each row from memory.
We no longer rely on comparing OpTime from Mongo changes, instead relying
on PSQL's LISTEN/NOTIFY process to notify us of changes. However, in order
to avoid overloading with constant update requests, we still poll
the update every two seconds.
https://trello.com/c/YJro3BGj