Postgres: Switch the datasource plugin from lib/pq to pgx (#81353)

* postgres: switch from lib/pq to pgx

* postgres: improved tls handling
This commit is contained in:
Gábor Farkas
2024-02-28 07:52:45 +01:00
committed by GitHub
parent e8df62941b
commit 8c18d06386
17 changed files with 967 additions and 908 deletions

View File

@ -14,6 +14,7 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/backend/log"
"github.com/grafana/grafana-plugin-sdk-go/experimental"
"github.com/jackc/pgx/v5"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/tsdb/sqleng"
@ -51,7 +52,7 @@ func TestIntegrationPostgresSnapshots(t *testing.T) {
t.Skip()
}
getCnnStr := func() string {
getCnn := func() (*pgx.ConnConfig, error) {
host := os.Getenv("POSTGRES_HOST")
if host == "" {
host = "localhost"
@ -61,8 +62,10 @@ func TestIntegrationPostgresSnapshots(t *testing.T) {
port = "5432"
}
return fmt.Sprintf("user=grafanatest password=grafanatest host=%s port=%s dbname=grafanadstest sslmode=disable",
cnnString := fmt.Sprintf("user=grafanatest password=grafanatest host=%s port=%s dbname=grafanadstest sslmode=disable",
host, port)
return pgx.ParseConfig(cnnString)
}
sqlQueryCommentRe := regexp.MustCompile(`^-- (.+)\n`)
@ -157,9 +160,10 @@ func TestIntegrationPostgresSnapshots(t *testing.T) {
logger := log.New()
cnnstr := getCnnStr()
cnn, err := getCnn()
require.NoError(t, err)
db, handler, err := newPostgres(context.Background(), "error", 10000, dsInfo, cnnstr, logger, backend.DataSourceInstanceSettings{})
db, handler, err := newPostgres(context.Background(), "error", 10000, dsInfo, cnn, logger, backend.DataSourceInstanceSettings{})
t.Cleanup((func() {
_, err := db.Exec("DROP TABLE tbl")