Skip to content
This repository was archived by the owner on Apr 17, 2019. It is now read-only.

Commit cef3374

Browse files
authored
Use pgx instead of lib/pq
1 parent fdad4bb commit cef3374

File tree

193 files changed

+26682
-6587
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

193 files changed

+26682
-6587
lines changed

Gopkg.lock

Lines changed: 18 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626

2727

2828
[[constraint]]
29+
name = "github.com/jackc/pgx"
2930
branch = "master"
30-
name = "github.com/lib/pq"
3131

3232
[[constraint]]
3333
name = "github.com/prometheus/client_golang"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ Run:
3535
sslmode: {ssl mode}
3636
workers: {number of parallel connections to use}
3737
statementTimeout: {pg statement_timeout value for each connection}
38-
skipVersionDetection: {whether perform "show server_version_num" on connect or not; useful while gathering stats of connection poolers}
39-
labels:
38+
isNotPg: {true if the destination side is not postgresql}
39+
labels:
4040
{labels added to each metric in the "queryFiles"}
4141
queryFiles:
4242
{use metric queries from files}

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ loop:
9393
case syscall.SIGTERM:
9494
break loop
9595
case syscall.SIGHUP:
96-
log.Printf("reloading config. to be implemented")
96+
//TODO: reload config
9797
default:
9898
log.Printf("received signal: %v", sig)
9999
}

pkg/config/config.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ func (v VerSQLs) Query(version PgVersion) string {
181181
return ""
182182
}
183183

184-
func parseVersion(str string) PgVersion {
185-
var res int
184+
func ParseVersion(str string) PgVersion {
185+
var res = int(NoVersion)
186186
matches := pgVerRegex.FindStringSubmatch(str)
187187
if matches == nil {
188188
return PgVersion(res)
@@ -214,14 +214,14 @@ func parseVersionRange(str string) (PgVersion, PgVersion) {
214214

215215
parts := strings.Split(str, "-")
216216
if len(parts) == 1 {
217-
min = parseVersion(parts[0])
217+
min = ParseVersion(parts[0])
218218
max = min
219219
} else {
220220
if parts[0] != "" {
221-
min = parseVersion(parts[0])
221+
min = ParseVersion(parts[0])
222222
}
223223
if parts[1] != "" {
224-
max = parseVersion(parts[1])
224+
max = ParseVersion(parts[1])
225225
}
226226
}
227227

@@ -267,8 +267,8 @@ func (c *Config) Load() error {
267267
if err := d.LoadQueries(); err != nil {
268268
return fmt.Errorf("could not load db queries: %v", err)
269269
}
270-
if d.Workers <= 0 {
271-
d.Workers = 1
270+
if d.WorkersNumber <= 0 {
271+
d.WorkersNumber = 1
272272
}
273273

274274
dbs[dbName] = d

pkg/config/db.go

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,26 @@ const applicationName = "pg_prometheus_exporter"
1313

1414
// DbConfigInterface describes DbConfig methods
1515
type DbConfigInterface interface {
16-
GetWorkers() int
17-
GetQueries() []Query
18-
ConnectionString() string
16+
Workers() int
17+
Queries() []Query
1918
InstanceName() string
20-
GetLabels() map[string]string
19+
Labels() map[string]string
20+
ApplicationName() string
2121
}
2222

2323
// DbConfig describes database to get metrics from
2424
type DbConfig struct {
25-
Host string `yaml:"host"`
26-
Port int `yaml:"port"`
27-
User string `yaml:"user"`
28-
Password string `yaml:"password"`
29-
Dbname string `yaml:"dbname"`
30-
Sslmode string `yaml:"sslmode"`
31-
QueryFiles []string `yaml:"queryFiles"`
32-
Labels map[string]string `yaml:"labels"`
33-
Workers int `yaml:"workers"`
34-
SkipVersionDetection bool `yaml:"skipVersionDetection"`
35-
StatementTimeout time.Duration `yaml:"statementTimeout"`
25+
Host string `yaml:"host"`
26+
Port uint16 `yaml:"port"`
27+
User string `yaml:"user"`
28+
Password string `yaml:"password"`
29+
Dbname string `yaml:"dbname"`
30+
Sslmode string `yaml:"sslmode"`
31+
QueryFiles []string `yaml:"queryFiles"`
32+
LabelsMap map[string]string `yaml:"labels"`
33+
WorkersNumber int `yaml:"workers"`
34+
StatementTimeout time.Duration `yaml:"statementTimeout"`
35+
IsNotPg bool `yaml:"isNotPg"`
3636

3737
queries []Query
3838
}
@@ -65,28 +65,26 @@ func (d *DbConfig) LoadQueries() error {
6565
return nil
6666
}
6767

68-
// ConnectionString returns connection string
69-
func (d *DbConfig) ConnectionString() string {
70-
return fmt.Sprintf("postgres://%s:%s@%s:%d/%s?sslmode=%s&fallback_application_name=%s",
71-
d.User, d.Password, d.Host, d.Port, d.Dbname, d.Sslmode, applicationName)
72-
}
73-
7468
// InstanceName returns instance name
7569
func (d *DbConfig) InstanceName() string {
7670
return fmt.Sprintf("%s:%d", d.Host, d.Port)
7771
}
7872

79-
// GetWorkers returns number of workers for the db
80-
func (d *DbConfig) GetWorkers() int {
81-
return d.Workers
73+
// Workers returns number of workers for the db
74+
func (d *DbConfig) Workers() int {
75+
return d.WorkersNumber
8276
}
8377

84-
// GetQueries returns db queries
85-
func (d *DbConfig) GetQueries() []Query {
78+
// Queries returns db queries
79+
func (d *DbConfig) Queries() []Query {
8680
return d.queries
8781
}
8882

89-
// GetLabels returns db labels
90-
func (d *DbConfig) GetLabels() map[string]string {
91-
return d.Labels
83+
// Labels returns db labels
84+
func (d *DbConfig) Labels() map[string]string {
85+
return d.LabelsMap
86+
}
87+
88+
func (d *DbConfig) ApplicationName() string {
89+
return applicationName
9290
}

0 commit comments

Comments
 (0)