Update multi-target handler to use new DSN type
- Moves new dsn type to config.DSN. This will prevent circular dependencies. - Change DSN.query to be url.Values. This allows the multi-target functionality to merge values without re-parsing the query string - Change NewProbeCollector to use the new config.DSN type - Add DSN.GetConnectionString to return a string formatted for the sql driver to use during connection Signed-off-by: Joe Adams <github@joeadams.io>
This commit is contained in:
@@ -16,11 +16,10 @@ package collector
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus-community/postgres_exporter/config"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@@ -31,7 +30,7 @@ type ProbeCollector struct {
|
||||
db *sql.DB
|
||||
}
|
||||
|
||||
func NewProbeCollector(logger log.Logger, registry *prometheus.Registry, dsn string) (*ProbeCollector, error) {
|
||||
func NewProbeCollector(logger log.Logger, registry *prometheus.Registry, dsn config.DSN) (*ProbeCollector, error) {
|
||||
collectors := make(map[string]Collector)
|
||||
initiatedCollectorsMtx.Lock()
|
||||
defer initiatedCollectorsMtx.Unlock()
|
||||
@@ -55,11 +54,7 @@ func NewProbeCollector(logger log.Logger, registry *prometheus.Registry, dsn str
|
||||
}
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(dsn, "postgres://") {
|
||||
dsn = fmt.Sprintf("postgres://%s", dsn)
|
||||
}
|
||||
|
||||
db, err := sql.Open("postgres", dsn)
|
||||
db, err := sql.Open("postgres", dsn.GetConnectionString())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user