mongodb.ping is using default client timeout

XMLWordPrintable

    • Sprint 99 (Apr 2023), Sprint 100 (May 2023)
    • 1

      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.

            Assignee:
            Eriks Sneiders
            Reporter:
            Aigars Kadikis
            Team INT
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: