Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEriks Sneiders <eriks.sneiders@zabbix.com>2022-04-07 09:37:56 +0300
committerEriks Sneiders <eriks.sneiders@zabbix.com>2022-04-07 09:58:20 +0300
commit139fbddc248667301dd85122d7d7dafdc3f8f58d (patch)
treecfb61c1bb240caeef4114e1e8a6bc76384a296a9 /src/go/plugins
parent13d2f9bcd2aaee7c47e7c5f9067459d60c01cf10 (diff)
...G...... [ZBX-20538] changed postgres plugin to handle connection per user and not per database for Zabbix agent 2
* commit '709cd2a4421cd93041ad36413d0c240efdd8fea9': ...G...... [ZBX-20538] code clean up .......... [ZBX-20538] added change log ...G...... [ZBX-20538] code clean up ...G...... [ZBX-20538] changed postgres plugin to handle connection per user and not per database for Zabbix agent 2 (cherry picked from commit db088f820e140e1c8a4c3f1338ec5b4a3117f15e)
Diffstat (limited to 'src/go/plugins')
-rwxr-xr-xsrc/go/plugins/postgres/conn.go16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/go/plugins/postgres/conn.go b/src/go/plugins/postgres/conn.go
index 79ad07a1847..9303393b997 100755
--- a/src/go/plugins/postgres/conn.go
+++ b/src/go/plugins/postgres/conn.go
@@ -58,6 +58,7 @@ type PGConn struct {
lastTimeAccess time.Time
version int
queryStorage *yarn.Yarn
+ address string
}
var errorQueryNotFound = "query %q not found"
@@ -127,7 +128,7 @@ func (conn *PGConn) updateAccessTime() {
type ConnManager struct {
sync.Mutex
connMutex sync.Mutex
- connections map[uri.URI]*PGConn
+ connections map[string]*PGConn
keepAlive time.Duration
connectTimeout time.Duration
callTimeout time.Duration
@@ -141,7 +142,7 @@ func NewConnManager(keepAlive, connectTimeout, callTimeout,
ctx, cancel := context.WithCancel(context.Background())
connMgr := &ConnManager{
- connections: make(map[uri.URI]*PGConn),
+ connections: make(map[string]*PGConn),
keepAlive: keepAlive,
connectTimeout: connectTimeout,
callTimeout: callTimeout,
@@ -163,7 +164,7 @@ func (c *ConnManager) closeUnused() {
if time.Since(conn.lastTimeAccess) > c.keepAlive {
conn.client.Close()
delete(c.connections, uri)
- log.Debugf("[%s] Closed unused connection: %s", pluginName, uri.Addr())
+ log.Debugf("[%s] Closed unused connection: %s", pluginName, conn.address)
}
}
}
@@ -200,7 +201,7 @@ func (c *ConnManager) create(uri uri.URI, details tlsconfig.Details) (*PGConn, e
c.connMutex.Lock()
defer c.connMutex.Unlock()
- if _, ok := c.connections[uri]; ok {
+ if _, ok := c.connections[uri.NoQueryString()]; ok {
// Should never happen.
panic("connection already exists")
}
@@ -248,18 +249,19 @@ func (c *ConnManager) create(uri uri.URI, details tlsconfig.Details) (*PGConn, e
return nil, fmt.Errorf("postgres version %d is not supported", serverVersion)
}
- c.connections[uri] = &PGConn{
+ c.connections[uri.NoQueryString()] = &PGConn{
client: client,
callTimeout: c.callTimeout,
version: serverVersion,
lastTimeAccess: time.Now(),
ctx: ctx,
queryStorage: &c.queryStorage,
+ address: uri.Addr(),
}
log.Debugf("[%s] Created new connection: %s", pluginName, uri.Addr())
- return c.connections[uri], nil
+ return c.connections[uri.NoQueryString()], nil
}
func createTLSClient(dsn string, timeout time.Duration, details tlsconfig.Details) (*sql.DB, error) {
@@ -304,7 +306,7 @@ func (c *ConnManager) get(uri uri.URI) *PGConn {
c.connMutex.Lock()
defer c.connMutex.Unlock()
- if conn, ok := c.connections[uri]; ok {
+ if conn, ok := c.connections[uri.NoQueryString()]; ok {
conn.updateAccessTime()
return conn
}