[ZBX-22689] mongodb.ping is using default client timeout Created: 2023 Apr 17  Updated: 2024 Apr 10  Resolved: 2023 May 16

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Agent2 plugin (G)
Affects Version/s: 6.4.1
Fix Version/s: 6.0.18rc1, 6.4.3rc1, 7.0.0alpha1, 7.0 (plan)

Type: Problem report Priority: Minor
Reporter: Aigars Kadikis Assignee: Eriks Sneiders
Resolution: Fixed Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Sub-task
Team: Team INT
Sprint: Sprint 99 (Apr 2023), Sprint 100 (May 2023)
Story Points: 1

 Description   

Mongo driver is having multiple timeouts and one of them is
https://www.mongodb.com/docs/drivers/go/current/fundamentals/connection/

serverSelectionTimeoutMS
integer
30000
Specifies the number of milliseconds to wait to find an available, suitable server to execute an operation.

It has a default value of 30 seconds, so it will always try maximum time allowed by Zabbix agent.

The MongoDB timeout for agent 2 plugin should be configurable or at least smaller than default timeout.

In the source, part where it is creating connection options
https://git.zabbix.com/projects/AP/repos/mongodb/browse/plugin/conn.go#300

We can modify the code to allow the user to manually configure timeout.

Here is diff of MongoDB plugin which allows to lower down timeout:

diff --git a/plugin/conn.go b/plugin/conn.go
index e872a78..7cf65bb 100644
--- a/plugin/conn.go
+++ b/plugin/conn.go
@@ -298,6 +298,7 @@ func (c *ConnManager) createOptions(uri uri.URI, details tlsconfig.Details) (*op
        opt.SetHosts([]string{uri.Addr()})
        opt.SetDirect(true)
        opt.SetConnectTimeout(c.timeout)
+       opt.SetServerSelectionTimeout(c.timeout)
        opt.SetMaxPoolSize(1)

        return opt, nil

Now we can use:

Plugins.MongoDB.Timeout=1

Registering this as a bug report because with existing agent configuration, it's not possible to workaround the issue. The poller which is fetching "mongodb.ping" metric will get stuck.



 Comments   
Comment by Eriks Sneiders [ 2023 May 10 ]

FIXED in 

Generated at Fri Jun 27 06:56:23 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.