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

[*] change ConnConfigCallback type to func(*pgxpool.Config) error #325

Merged
merged 2 commits into from
Dec 6, 2023
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
6 changes: 5 additions & 1 deletion src/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/cybertec-postgresql/pgwatch3/metrics"
"github.com/cybertec-postgresql/pgwatch3/psutil"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgxpool"
)

var configDb db.PgxPoolIface
Expand All @@ -38,7 +39,10 @@ func InitSQLConnPoolForMonitoredDBIfNil(md MonitoredDatabase) error {
return nil
}

conn, err := db.GetPostgresDBConnection(mainContext, md.ConnStr)
conn, err := db.GetPostgresDBConnection(mainContext, md.ConnStr, func(conf *pgxpool.Config) error {
conf.MaxConns = int32(opts.MaxParallelConnectionsPerDb)
return nil
})
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions src/db/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ func TryDatabaseConnection(ctx context.Context, connStr string) error {
return err
}

type ConnConfigCallback = func(*pgx.ConnConfig) error
type ConnConfigCallback = func(*pgxpool.Config) error

func GetPostgresDBConnection(ctx context.Context, connStr string, callbacks ...ConnConfigCallback) (PgxPoolIface, error) {
connConfig, err := pgxpool.ParseConfig(connStr)
if err != nil {
return nil, err
}
for _, f := range callbacks {
if err = f(connConfig.ConnConfig); err != nil {
if err = f(connConfig); err != nil {
return nil, err
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/patroni.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/cybertec-postgresql/pgwatch3/config"
"github.com/cybertec-postgresql/pgwatch3/db"
consul_api "github.com/hashicorp/consul/api"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/samuel/go-zookeeper/zk"
client "go.etcd.io/etcd/client/v3"
)
Expand Down Expand Up @@ -321,11 +321,11 @@ func ResolveDatabasesFromPatroni(ce MonitoredDatabase) ([]MonitoredDatabase, err
continue
}
c, err := db.GetPostgresDBConnection(mainContext, ce.ConnStr,
func(c *pgx.ConnConfig) error {
c.Host = host
c.Database = "template1"
i, err := strconv.Atoi(port)
c.Port = uint16(i)
func(c *pgxpool.Config) error {
c.ConnConfig.Host = host
c.ConnConfig.Database = "template1"
i, err := strconv.ParseUint(port, 10, 16)
c.ConnConfig.Port = uint16(i)
Fixed Show fixed Hide fixed
md[len(md)].ConnStr = c.ConnString()
return err
})
Expand Down
Loading