Skip to content

Commit

Permalink
Set application name in all cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
mdevan committed Jul 24, 2024
1 parent 69a0634 commit f2d9ba8
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions collector/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ func Collect(o CollectConfig, dbnames []string) *pgmetrics.Model {
if os.Getenv("PGSSLMODE") == "" {
connstr += makeKV("sslmode", "disable")
}
connstr += makeKV("application_name", "pgmetrics")
if len(dbnames) == 1 && dbnames[0] == "pgbouncer" {
mode = "pgbouncer"
}
Expand All @@ -228,6 +227,9 @@ func Collect(o CollectConfig, dbnames []string) *pgmetrics.Model {
connstr += makeKV("statement_timeout", strconv.Itoa(int(o.TimeoutSec)*1000))
}

// set application name
connstr += makeKV("application_name", "pgmetrics")

// use simple protocol for maximum compatibility (pgx-specific keyword)
connstr += makeKV("default_query_exec_mode", "simple_protocol")

Expand Down Expand Up @@ -299,7 +301,7 @@ func collectFromDB(connstr string, c *collector, o CollectConfig) {
}

func getDBNames(connstr string, o CollectConfig) (dbnames []string) {
db := getConn(connstr + makeKV("dbname", "postgres"), o)
db := getConn(connstr+makeKV("dbname", "postgres"), o)
defer db.Close()

timeout := time.Duration(o.TimeoutSec) * time.Second
Expand Down

0 comments on commit f2d9ba8

Please sign in to comment.