Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ COPY . .

RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/event_handler ./cmd/event_handler
RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/failover_validation ./cmd/failover_validation

RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/standby_cleaner ./cmd/standby_cleaner
RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/pg_unregister ./.flyctl/cmd/pg_unregister

RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/pg_unregister ./cmd/pg_unregister
RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/start ./cmd/start

COPY ./bin/* /fly/bin/

FROM wrouesnel/postgres_exporter:latest AS postgres_exporter
Expand Down
Binary file removed cmd/connection_test/connection_test
Binary file not shown.
84 changes: 0 additions & 84 deletions cmd/connection_test/main.go

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/event_handler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strconv"
"time"

"github.com/fly-apps/postgres-flex/pkg/flypg"
"github.com/fly-apps/postgres-flex/internal/flypg"
)

const eventLogFile = "/data/event.log"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"fmt"
"os"

"github.com/fly-apps/postgres-flex/pkg/flypg"
"github.com/fly-apps/postgres-flex/pkg/utils"
"github.com/fly-apps/postgres-flex/internal/flypg"
"github.com/fly-apps/postgres-flex/internal/utils"
)

func main() {
Expand Down
4 changes: 2 additions & 2 deletions cmd/standby_cleaner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"os"
"time"

"github.com/fly-apps/postgres-flex/pkg/flypg"
"github.com/fly-apps/postgres-flex/pkg/flypg/admin"
"github.com/fly-apps/postgres-flex/internal/flypg"
"github.com/fly-apps/postgres-flex/internal/flypg/admin"
"github.com/jackc/pgx/v4"

"golang.org/x/exp/maps"
Expand Down
4 changes: 2 additions & 2 deletions cmd/start/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"syscall"
"time"

"github.com/fly-apps/postgres-flex/pkg/flypg"
"github.com/fly-apps/postgres-flex/pkg/supervisor"
"github.com/fly-apps/postgres-flex/internal/flypg"
"github.com/fly-apps/postgres-flex/internal/supervisor"
)

func main() {
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/handle_admin.go → internal/api/handle_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"net/http"
"strings"

"github.com/fly-apps/postgres-flex/pkg/flypg"
"github.com/fly-apps/postgres-flex/pkg/flypg/admin"
"github.com/fly-apps/postgres-flex/pkg/flypg/state"
"github.com/fly-apps/postgres-flex/internal/flypg"
"github.com/fly-apps/postgres-flex/internal/flypg/admin"
"github.com/fly-apps/postgres-flex/internal/flypg/state"
"golang.org/x/exp/slices"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"net/http"

"github.com/fly-apps/postgres-flex/pkg/flypg/admin"
"github.com/fly-apps/postgres-flex/internal/flypg/admin"
"github.com/go-chi/chi/v5"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/api/handle_users.go → internal/api/handle_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"net/http"

"github.com/fly-apps/postgres-flex/pkg/flypg/admin"
"github.com/fly-apps/postgres-flex/internal/flypg/admin"
"github.com/go-chi/chi/v5"
)

Expand Down
4 changes: 2 additions & 2 deletions pkg/api/handler.go → internal/api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"net/http"

"github.com/fly-apps/postgres-flex/pkg/flycheck"
"github.com/fly-apps/postgres-flex/pkg/flypg"
"github.com/fly-apps/postgres-flex/internal/flycheck"
"github.com/fly-apps/postgres-flex/internal/flypg"
"github.com/go-chi/chi/v5"
"github.com/jackc/pgx/v4"
)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion pkg/flycheck/pg.go → internal/flycheck/pg.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

"github.com/fly-apps/postgres-flex/pkg/flypg"
"github.com/fly-apps/postgres-flex/internal/flypg"
"github.com/jackc/pgx/v4"
"github.com/pkg/errors"
"github.com/superfly/fly-checks/check"
Expand Down
2 changes: 1 addition & 1 deletion pkg/flycheck/role.go → internal/flycheck/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

"github.com/fly-apps/postgres-flex/pkg/flypg"
"github.com/fly-apps/postgres-flex/internal/flypg"
"github.com/pkg/errors"
"github.com/superfly/fly-checks/check"
)
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion pkg/flypg/config.go → internal/flypg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"os"
"strings"

"github.com/fly-apps/postgres-flex/pkg/flypg/state"
"github.com/fly-apps/postgres-flex/internal/flypg/state"
)

type ConfigMap map[string]interface{}
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions pkg/flypg/node.go → internal/flypg/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (
"strconv"
"time"

"github.com/fly-apps/postgres-flex/pkg/flypg/admin"
"github.com/fly-apps/postgres-flex/pkg/flypg/state"
"github.com/fly-apps/postgres-flex/pkg/privnet"
"github.com/fly-apps/postgres-flex/pkg/utils"
"github.com/fly-apps/postgres-flex/internal/flypg/admin"
"github.com/fly-apps/postgres-flex/internal/flypg/state"
"github.com/fly-apps/postgres-flex/internal/privnet"
"github.com/fly-apps/postgres-flex/internal/utils"
"github.com/jackc/pgx/v4"
)

Expand Down
4 changes: 2 additions & 2 deletions pkg/flypg/pg.go → internal/flypg/pg.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"strings"
"syscall"

"github.com/fly-apps/postgres-flex/pkg/flypg/admin"
"github.com/fly-apps/postgres-flex/pkg/utils"
"github.com/fly-apps/postgres-flex/internal/flypg/admin"
"github.com/fly-apps/postgres-flex/internal/utils"
"github.com/jackc/pgx/v4"
"github.com/pkg/errors"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/flypg/pgbouncer.go → internal/flypg/pgbouncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"os"
"strconv"

"github.com/fly-apps/postgres-flex/pkg/utils"
"github.com/fly-apps/postgres-flex/internal/utils"

"github.com/jackc/pgx/v4"
)
Expand Down
6 changes: 3 additions & 3 deletions pkg/flypg/repmgr.go → internal/flypg/repmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"os"
"strconv"

"github.com/fly-apps/postgres-flex/pkg/privnet"
"github.com/fly-apps/postgres-flex/pkg/utils"
"github.com/fly-apps/postgres-flex/internal/privnet"
"github.com/fly-apps/postgres-flex/internal/utils"

"github.com/fly-apps/postgres-flex/pkg/flypg/admin"
"github.com/fly-apps/postgres-flex/internal/flypg/admin"
"github.com/jackc/pgx/v4"
)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package supervisor
import (
"context"
"fmt"
"github.com/fly-apps/postgres-flex/pkg/flypg"
"os"
"os/exec"
"os/signal"
"syscall"
"time"

"github.com/fly-apps/postgres-flex/pkg/api"
"github.com/fly-apps/postgres-flex/internal/flypg"

"github.com/fly-apps/postgres-flex/internal/api"
"github.com/google/shlex"
"golang.org/x/sync/errgroup"
)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
70 changes: 70 additions & 0 deletions scripts/test_scripts/config_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash

APP_NAME=$1

echo "App: $APP_NAME"

# Resolve the machine ID associated with the primary
MACHINE_ID=$(fly status --app $APP_NAME | grep primary | awk '{print $1}')
if (( ${#MACHINE_ID} != 14 ));
then
echo "Error: unable to resolve primary machine"
exit 1
fi
echo "Primary Machine ID: $MACHINE_ID"

# Resolve IP associated with the primary
PRIMARY_IP=$(fly machines list --app $APP_NAME | grep $MACHINE_ID | awk '{print $7}')
echo "Primary IP: $PRIMARY_IP"

# Pull operator password from environment.
OPERATOR_PASSWORD=$(fly ssh console -A $PRIMARY_IP --app $APP_NAME -q -C "printenv OPERATOR_PASSWORD" | tr -d "\r\n")
echo ""

echo "**Verifying connection target**"
result=$(psql "postgres://postgres:$OPERATOR_PASSWORD@$APP_NAME.internal:5432" -c "SELECT inet_server_addr();" | sed -n "3 p" 2>&1)
if [ $PRIMARY_IP = $result ];
then
echo "Connected to:$result (correct)"
else
echo "Connected to:$result (incorrect)"
fi


echo ""
echo "**Verifying PGBouncer configuration**"
for ip in $(dig $APP_NAME.internal aaaa +short)
do
result=$(fly ssh console -A $ip --app $APP_NAME -q -C "cat data/pgbouncer/pgbouncer.database.ini" | grep "host=")
pgbouncer=$(echo $result | cut -d= -f3 | awk '{print $1}')
if [ $pgbouncer != $PRIMARY_IP ];
then
echo "$ip -> $pgbouncer (incorrect)"
else
echo "$ip -> $pgbouncer (correct)"
fi
done


echo ""
echo "**Verifying Readonly configuration**"
for ip in $(dig $APP_NAME.internal aaaa +short)
do
result=$(psql postgres://postgres:$OPERATOR_PASSWORD@[$ip]:5433 -c 'SELECT 'CREATE DATABASE configcheck WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'configcheck')' 2>&1)
if [ "$ip" = "$PRIMARY_IP" ];
then
if [[ $result =~ "read-only" ]];
then
echo "Role: Primary - $ip -> $result (incorrect)"
else
echo "Role: Primary - $ip -> $result (correct)"
fi
else
if [[ $result =~ "read-only" ]];
then
echo "Role: Standby - $ip -> $result (correct)"
else
echo "Role: Standby - $ip -> $result (incorrect)"
fi
fi
done
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.