Skip to content
Draft
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.13.0

* Drop lib/pq and switch to jackc/pgx.

## 0.12.0

* Build with Go 1.17.
Expand Down
16 changes: 11 additions & 5 deletions cmd/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package cmd

import (
"context"
"database/sql"
"fmt"

"github.com/jbub/pgbouncer_exporter/internal/config"
"github.com/jbub/pgbouncer_exporter/internal/sqlstore"

"github.com/jackc/pgx/v4"
"github.com/urfave/cli/v2"
)

Expand All @@ -21,13 +21,19 @@ var Health = &cli.Command{
func checkHealth(ctx *cli.Context) error {
cfg := config.LoadFromCLI(ctx)

db, err := sql.Open("postgres", cfg.DatabaseURL)
connCfg, err := pgx.ParseConfig(cfg.DatabaseURL)
if err != nil {
return fmt.Errorf("could not open db: %v", err)
return fmt.Errorf("could not parse connection config: %v", err)
}
defer db.Close()
connCfg.PreferSimpleProtocol = true

store := sqlstore.New(db)
conn, err := pgx.ConnectConfig(context.Background(), connCfg)
if err != nil {
return fmt.Errorf("could not connect: %v", err)
}
defer conn.Close(context.Background())

store := sqlstore.New(conn)

checkCtx, cancel := context.WithTimeout(context.Background(), cfg.StoreTimeout)
defer cancel()
Expand Down
16 changes: 11 additions & 5 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"context"
"database/sql"
"fmt"
"log"

Expand All @@ -11,6 +10,7 @@ import (
"github.com/jbub/pgbouncer_exporter/internal/server"
"github.com/jbub/pgbouncer_exporter/internal/sqlstore"

"github.com/jackc/pgx/v4"
"github.com/prometheus/common/version"
"github.com/urfave/cli/v2"
)
Expand All @@ -25,13 +25,19 @@ var Server = &cli.Command{
func runServer(ctx *cli.Context) error {
cfg := config.LoadFromCLI(ctx)

db, err := sql.Open("postgres", cfg.DatabaseURL)
connCfg, err := pgx.ParseConfig(cfg.DatabaseURL)
if err != nil {
return fmt.Errorf("could not open db: %v", err)
return fmt.Errorf("could not parse connection config: %v", err)
}
defer db.Close()
connCfg.PreferSimpleProtocol = true

store := sqlstore.New(db)
conn, err := pgx.ConnectConfig(context.Background(), connCfg)
if err != nil {
return fmt.Errorf("could not connect: %v", err)
}
defer conn.Close(context.Background())

store := sqlstore.New(conn)

checkCtx, cancel := context.WithTimeout(context.Background(), cfg.StoreTimeout)
defer cancel()
Expand Down
5 changes: 2 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.7"

services:
postgres:
image: "postgres:12.4-alpine"
image: "postgres:14-alpine"
restart: always
ports:
- "5432:5432"
Expand All @@ -18,7 +18,6 @@ services:
POSTGRESQL_USERNAME: "postgres"
POSTGRESQL_PASSWORD: "postgres"
PGBOUNCER_AUTH_TYPE: "trust"
PGBOUNCER_IGNORE_STARTUP_PARAMETERS: "extra_float_digits"
depends_on:
- postgres

Expand All @@ -29,7 +28,7 @@ services:
ports:
- "9127:9127"
environment:
DATABASE_URL: "postgres://postgres:postgres@pgbouncer:6432/pgbouncer?sslmode=disable&binary_parameters=yes"
DATABASE_URL: "postgres://postgres:postgres@pgbouncer:6432/pgbouncer?sslmode=disable&statement_cache_mode=describe"
DEFAULT_LABELS: "instance=pg1 env=dev"
depends_on:
- pgbouncer
18 changes: 14 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module github.com/jbub/pgbouncer_exporter
go 1.17

require (
github.com/DATA-DOG/go-sqlmock v1.5.0
github.com/lib/pq v1.10.2
github.com/jackc/pgx/v4 v4.13.0
github.com/pashagolub/pgxmock v1.4.0
github.com/prometheus/client_golang v1.11.0
github.com/prometheus/common v0.30.0
github.com/prometheus/common v0.31.1
github.com/stretchr/testify v1.7.0
github.com/urfave/cli/v2 v2.3.0
)
Expand All @@ -17,13 +17,23 @@ require (
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/protobuf v1.4.3 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.10.0 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.1.1 // indirect
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
github.com/jackc/pgtype v1.8.1 // indirect
github.com/jackc/puddle v1.1.3 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/russross/blackfriday/v2 v2.0.1 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40 // indirect
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 // indirect
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
golang.org/x/text v0.3.6 // indirect
google.golang.org/protobuf v1.26.0-rc.1 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
Loading