Skip to content

Commit

Permalink
use pgbouncer connection for running healthchecks
Browse files Browse the repository at this point in the history
  • Loading branch information
var77 committed Sep 3, 2024
1 parent 0d53342 commit 6e389b3
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ def self.e2e_test?
# Lantern
override :lantern_top_domain, "db.lantern.dev", string
override :lantern_dns_email, "varik@lantern.dev", string
override :lantern_default_version, "0.3.1", string
override :lantern_default_version, "0.3.3", string
override :lantern_extras_default_version, "0.2.3", string
override :lantern_minor_default_version, "2", string
override :lantern_minor_default_version, "1", string
override :lantern_backup_bucket, "walg-dev-backups"
override :e2e_test, "0"
override :backup_retention_days, 7, int
Expand Down
4 changes: 2 additions & 2 deletions model/lantern/lantern_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def connection_string(port: 6432)
end

def run_query(query, db: "postgres", user: "postgres")
vm.sshable.cmd("sudo docker compose -f #{Config.compose_file} exec -T postgresql psql -q -U #{user} -t --csv #{db}", stdin: query).chomp
vm.sshable.cmd("sudo docker compose -f #{Config.compose_file} exec -T postgresql psql -q -U #{user} -p6432 -t --csv #{db}", stdin: query).chomp
end

def run_query_all(query)
Expand Down Expand Up @@ -242,7 +242,7 @@ def prewarm_indexes_query
end

def list_all_databases
vm.sshable.cmd("sudo docker compose -f #{Config.compose_file} exec postgresql psql -U postgres -P \"footer=off\" -c 'SELECT datname from pg_database' | tail -n +3 | grep -v 'template0' | grep -v 'template1'")
vm.sshable.cmd("sudo docker compose -f #{Config.compose_file} exec postgresql psql -p6432 -U postgres -P \"footer=off\" -c 'SELECT datname from pg_database' | tail -n +3 | grep -v 'template0' | grep -v 'template1'")
.chomp
.strip
.split("\n")
Expand Down
2 changes: 1 addition & 1 deletion rhizome/lantern/bin/doctor/run_query
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ $configure_hash = JSON.parse($stdin.read)
dbs = $configure_hash["dbs"]

def exec_sql(sql, user: "postgres", db: "postgres")
r("docker compose -f #{$compose_file} exec -T postgresql psql -q -U #{user} -t --csv #{db}", stdin: sql).chomp.strip
r("docker compose -f #{$compose_file} exec -T postgresql psql -q -U #{user} -p6432 -t --csv #{db}", stdin: sql).chomp.strip
end

def run_for_db(db)
Expand Down
2 changes: 1 addition & 1 deletion rhizome/lantern/bin/exec
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ require "yaml"
require_relative "../../common/lib/util"
require_relative "../lib/common"

$stdout.puts r "docker compose -f #{$compose_file} exec -T postgresql psql -U postgres -t --csv", stdin: $stdin
$stdout.puts r "docker compose -f #{$compose_file} exec -T postgresql psql -p6432 -U postgres -t --csv", stdin: $stdin
4 changes: 2 additions & 2 deletions rhizome/lantern/bin/exec_all
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require "yaml"
require_relative "../../common/lib/util"
require_relative "../lib/common"

all_dbs = (r "docker compose -f #{$compose_file} exec postgresql psql -U postgres -P \"footer=off\" -c 'SELECT datname from pg_database' | tail -n +3 | grep -v 'template0' | grep -v 'template1'").strip!.split("\n")
all_dbs = (r "docker compose -f #{$compose_file} exec postgresql psql -U postgres -p6432 -P \"footer=off\" -c 'SELECT datname from pg_database' | tail -n +3 | grep -v 'template0' | grep -v 'template1'").strip!.split("\n")
all_dbs.each do |db|
$stdout.puts r "docker compose -f #{$compose_file} exec -T postgresql psql -U postgres -t --csv #{db}", stdin: $stdin
$stdout.puts r "docker compose -f #{$compose_file} exec -T postgresql psql -p6432 -U postgres -t --csv #{db}", stdin: $stdin
end
10 changes: 5 additions & 5 deletions spec/model/lantern/lantern_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,19 @@
end

it "runs query on vm" do
expect(lantern_server.vm.sshable).to receive(:cmd).with("sudo docker compose -f /var/lib/lantern/docker-compose.yaml exec -T postgresql psql -q -U postgres -t --csv postgres", stdin: "SELECT 1").and_return("1\n")
expect(lantern_server.vm.sshable).to receive(:cmd).with("sudo docker compose -f /var/lib/lantern/docker-compose.yaml exec -T postgresql psql -q -U postgres -p6432 -t --csv postgres", stdin: "SELECT 1").and_return("1\n")
expect(lantern_server.run_query("SELECT 1")).to eq("1")
end

it "runs query on vm with different user and db" do
expect(lantern_server.vm.sshable).to receive(:cmd).with("sudo docker compose -f /var/lib/lantern/docker-compose.yaml exec -T postgresql psql -q -U lantern -t --csv db2", stdin: "SELECT 1").and_return("1\n")
expect(lantern_server.vm.sshable).to receive(:cmd).with("sudo docker compose -f /var/lib/lantern/docker-compose.yaml exec -T postgresql psql -q -U lantern -p6432 -t --csv db2", stdin: "SELECT 1").and_return("1\n")
expect(lantern_server.run_query("SELECT 1", db: "db2", user: "lantern")).to eq("1")
end

it "runs query on vm for all databases" do
expect(lantern_server).to receive(:list_all_databases).and_return(["postgres", "db2"])
expect(lantern_server.vm.sshable).to receive(:cmd).with("sudo docker compose -f /var/lib/lantern/docker-compose.yaml exec -T postgresql psql -q -U postgres -t --csv postgres", stdin: "SELECT 1").and_return("1\n")
expect(lantern_server.vm.sshable).to receive(:cmd).with("sudo docker compose -f /var/lib/lantern/docker-compose.yaml exec -T postgresql psql -q -U postgres -t --csv db2", stdin: "SELECT 1").and_return("2\n")
expect(lantern_server.vm.sshable).to receive(:cmd).with("sudo docker compose -f /var/lib/lantern/docker-compose.yaml exec -T postgresql psql -q -U postgres -p6432 -t --csv postgres", stdin: "SELECT 1").and_return("1\n")
expect(lantern_server.vm.sshable).to receive(:cmd).with("sudo docker compose -f /var/lib/lantern/docker-compose.yaml exec -T postgresql psql -q -U postgres -p6432 -t --csv db2", stdin: "SELECT 1").and_return("2\n")
expect(lantern_server.run_query_all("SELECT 1")).to eq(
[
["postgres", "1"],
Expand Down Expand Up @@ -691,7 +691,7 @@

describe "#list_all_databases" do
it "returns list of all databases" do
expect(lantern_server.vm.sshable).to receive(:cmd).with("sudo docker compose -f /var/lib/lantern/docker-compose.yaml exec postgresql psql -U postgres -P \"footer=off\" -c 'SELECT datname from pg_database' | tail -n +3 | grep -v 'template0' | grep -v 'template1'").and_return("postgres\ndb2\n")
expect(lantern_server.vm.sshable).to receive(:cmd).with("sudo docker compose -f /var/lib/lantern/docker-compose.yaml exec postgresql psql -p6432 -U postgres -P \"footer=off\" -c 'SELECT datname from pg_database' | tail -n +3 | grep -v 'template0' | grep -v 'template1'").and_return("postgres\ndb2\n")
expect(lantern_server.list_all_databases).to eq(["postgres", "db2"])
end
end
Expand Down

0 comments on commit 6e389b3

Please sign in to comment.