Skip to content

Commit b09ef6f

Browse files
Bump github.com/lib/pq from 1.10.9 to 1.12.3 (#1349)
lib/pq was pinned at v1.10.9, which was 3 years and 6 releases behind the latest tag (v1.11.0, v1.11.1, v1.11.2, v1.12.0, v1.12.1, v1.12.3). Notably, v1.11.0 added support for the target_session_attrs DSN parameter, which is needed to route connections to a primary/standby correctly and was the specific ask in #1344. The only usages of lib/pq in this repo were pq.ParseURL (exporter/util.go, in parseFingerprint) and pq.Array (collector/pg_process_idle.go, exporter/namespace.go). pq.ParseURL was marked deprecated in this range (SA1019), which is the exact breakage reported in #1284 ("Fix fingerprint generator for new lib/pq"). Rather than suppressing the lint warning, parseFingerprint was reworked to stop depending on pq.ParseURL: it now uses net/url directly to pull host/port out of postgres:// and postgresql:// DSNs, falling back to the existing key=value parser for non-URL DSNs. This removes the dependency on pq.ParseURL entirely and drops the lib/pq import from util.go. Behavior is unchanged, verified against the existing parseFingerprint test cases (URL DSNs, percent-encoded passwords, key=value DSNs, and the malformed-DSN error path). pq.Array is unaffected by the bump. Go version and PostgreSQL version requirements introduced by v1.11.0 (Go 1.21+, PostgreSQL 14+ "supported") are already satisfied by this module (go 1.25) and CI's oldest tested version (13.22), respectively, though PG13 is technically past lib/pq's new support window. Verified with `go build ./...`, `go vet ./...`, `go test ./...`, golangci-lint (0 issues), govulncheck (0 vulnerabilities), and the full integration suite (`-tags integration`) against live postgres:13 and postgres:16 Docker containers. Fixes #1344. Fixes #1284. Signed-off-by: Raj <rajeshrajendirandev@gmail.com>
1 parent cf8ccc6 commit b09ef6f

3 files changed

Lines changed: 24 additions & 10 deletions

File tree

exporter/util.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import (
2121
"strconv"
2222
"strings"
2323
"time"
24-
25-
"github.com/lib/pq"
2624
)
2725

2826
// convert a string to the corresponding ColumnUsage
@@ -162,10 +160,27 @@ func dbToString(t interface{}) (string, bool) {
162160
}
163161
}
164162

165-
func parseFingerprint(url string) (string, error) {
166-
dsn, err := pq.ParseURL(url)
167-
if err != nil {
168-
dsn = url
163+
func parseFingerprint(dsn string) (string, error) {
164+
// Only postgres:// and postgresql:// are valid DSN URL schemes; anything
165+
// else (e.g. a key=value DSN like "host=example port=1234") falls through
166+
// to the key=value parser below.
167+
if strings.HasPrefix(dsn, "postgres://") || strings.HasPrefix(dsn, "postgresql://") {
168+
u, err := url.Parse(dsn)
169+
if err != nil {
170+
return "", fmt.Errorf("malformed dsn %q", dsn)
171+
}
172+
173+
host := u.Hostname()
174+
if host == "" {
175+
host = "localhost"
176+
}
177+
178+
port := u.Port()
179+
if port == "" {
180+
port = "5432"
181+
}
182+
183+
return host + ":" + port, nil
169184
}
170185

171186
pairs := strings.Split(dsn, " ")
@@ -175,7 +190,6 @@ func parseFingerprint(url string) (string, error) {
175190
if len(splitted) != 2 {
176191
return "", fmt.Errorf("malformed dsn %q", dsn)
177192
}
178-
// Newer versions of pq.ParseURL quote values so trim them off if they exist
179193
key := strings.Trim(splitted[0], "'\"")
180194
value := strings.Trim(splitted[1], "'\"")
181195
kv[key] = value

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/DATA-DOG/go-sqlmock v1.5.2
77
github.com/alecthomas/kingpin/v2 v2.4.0
88
github.com/blang/semver/v4 v4.0.0
9-
github.com/lib/pq v1.10.9
9+
github.com/lib/pq v1.12.3
1010
github.com/prometheus/client_golang v1.23.2
1111
github.com/prometheus/client_model v0.6.2
1212
github.com/prometheus/common v0.69.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
4040
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
4141
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
4242
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
43-
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
44-
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
43+
github.com/lib/pq v1.12.3 h1:tTWxr2YLKwIvK90ZXEw8GP7UFHtcbTtty8zsI+YjrfQ=
44+
github.com/lib/pq v1.12.3/go.mod h1:/p+8NSbOcwzAEI7wiMXFlgydTwcgTr3OSKMsD2BitpA=
4545
github.com/mdlayher/socket v0.6.0 h1:ScZPaAGyO1icQnbFrhPM8mnXyMu9qukC1K4ZoM2IQKU=
4646
github.com/mdlayher/socket v0.6.0/go.mod h1:q7vozUAnxSqnjHc12Fik5yUKIzfZ8ITCfMkhOtE9z18=
4747
github.com/mdlayher/vsock v1.3.0 h1:bqQfZ1OznI03y6YiXp2sze05RVdzLn/zsfjnjd4+ivI=

0 commit comments

Comments
 (0)