Skip to content

[inputs.mongodb] Telegraf crash on init if conn to MongoDB fails #10078

@papey

Description

@papey

Relevent telegraf.conf

/etc/telegraf/telegraf.d/mongo.conf

[[inputs.mongodb]]
  servers = ["mongodb://127.0.0.1:27017/?connect=direct"]
  gather_perdb_stats = false

  fieldpass = ["deletes_per_sec", "flushes_per_sec", "getmores_per_sec", "inserts_per_sec", "updates_per_sec", "queries_per_sec", "open_connections", "net_in_bytes", "net_out_bytes", "repl_lag", "state"]

System info

Telegraf 1.20.2 (git: HEAD f721f53), Debian 10.11

Docker

No response

Steps to reproduce

  1. Add a dedicated conf for MongoDB like the one above (to simulate a failed conn, just change the port number, for example)
  2. Restart Telegraf

Expected behavior

At least a log message to STDERR, on init, about a failing conn to a MongoDB server (with no retry mechanism)

Actual behavior

Telegraf crashes :

Nov 08 17:32:09 test-mongo-telegraf telegraf[3423]: 2021-11-08T16:32:09Z E! [telegraf] Error running agent: could not initialize input inputs.mongodb: unable to connect to MongoDB: server selection error: context deadline exceeded, current topology: { Type: Single,
Nov 08 17:32:09 test-mongo-telegraf systemd[1]: telegraf.service: Main process exited, code=exited, status=1/FAILURE

Additional info

My hypothesis is that we need to rethink some logic in the Init function in the mongodb input code

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/mongodbbugunexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions