From f2d9ba8c94432a82dea0060ecba7b9513fa25e6c Mon Sep 17 00:00:00 2001 From: Mahadevan Date: Wed, 24 Jul 2024 15:26:45 +0530 Subject: [PATCH] Set application name in all cases. --- collector/collect.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/collector/collect.go b/collector/collect.go index e8f1f80..6ec4034 100644 --- a/collector/collect.go +++ b/collector/collect.go @@ -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" } @@ -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") @@ -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