influxdata / telegraf

Agent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data.
https://influxdata.com/telegraf
MIT License
14.6k stars 5.57k forks source link

[inputs.mongodb] Error in plugin: BSON field 'saslContinue.mechanism' is an unknown field. #12752

Closed feiniao0308 closed 1 year ago

feiniao0308 commented 1 year ago

Relevant telegraf.conf

[[inputs.mongodb]]
  gather_col_stats = false
  gather_perdb_stats = true
  insecure_skip_verify = false
  servers = [
    "mongodb://username:password$host1:27017?connect=direct&authMechanism=SCRAM-SHA-1",
    "mongodb://username:password$host2:27017?connect=direct&authMechanism=SCRAM-SHA-1",
    "mongodb://username:password$host3:27017?connect=direct&authMechanism=SCRAM-SHA-1"
  ]
  tls_ca = "/etc/mongo/mongo.crt"

Logs from Telegraf

2023-02-27T20:40:01Z E! [inputs.mongodb] Error in plugin: unable to connect to MongoDB: server returned error on SASL authentication step: BSON field 'saslContinue.mechanism' is an unknown field.
2023-02-27T20:40:01Z E! [inputs.mongodb] Error in plugin: unable to connect to MongoDB: server returned error on SASL authentication step: BSON field 'saslContinue.mechanism' is an unknown field.
2023-02-27T20:40:01Z E! [inputs.mongodb] Error in plugin: unable to connect to MongoDB: server returned error on SASL authentication step: BSON field 'saslContinue.mechanism' is an unknown field.

System info

telegraf v1.25.2

Docker

No response

Steps to reproduce

  1. Upgrade mongo from 4.4.10 to 5.0.14
  2. Restart telegraf

Expected behavior

telegraf should connect to the mongodb and collect metrics

Actual behavior

Error in plugin: unable to connect to MongoDB: server returned error on SASL authentication step: BSON field 'saslContinue.mechanism' is an unknown field.

Additional info

Also tried with authMechanism=SCRAM-SHA-256, but it throw different error:

2023-02-27T20:09:05Z E! [inputs.mongodb] Error in plugin: unable to connect to MongoDB: SASL support not enabled during build (-tags sasl)

powersj commented 1 year ago

mongodb://username:password$host3:27017?connect=direct&authMechanism=SCRAM-SHA-1

Aren't you missing an @ in that URL?

Also can you verify this works via the mongo command:

mongo "mongodb://username:password$host1:27017?connect=direct&authMechanism=SCRAM-SHA-1"
feiniao0308 commented 1 year ago

Yes, no problem when connection with mongo . I started seeing this issue after upgrading mongodb from 4.4.10 to 5.0.14.

❯ mongo "mongodb://username:password@host1:27017/?connect=direct&authMechanism=SCRAM-SHA-1" --tls --tlsCAFile /etc/mongo/mongo.crt
MongoDB shell version v5.0.14
connecting to: mongodb://host1:27017/?authMechanism=SCRAM-SHA-1&compressors=disabled&connect=direct&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("4077dcca-63e6-434b-99f7-3136344d1b75") }
MongoDB server version: 5.0.14
================
Warning: the "mongo" shell has been superseded by "mongosh",
which delivers improved usability and compatibility.The "mongo" shell has been deprecated and will be removed in
an upcoming release.
For installation instructions, see
https://docs.mongodb.com/mongodb-shell/install/
================
... ...
powersj commented 1 year ago

@

I assume you used the @ in your telegraf config as well? Are there are any special characters in your password that need to be escaped?

After searching the web, it seems that this is a common problem when the client used is not new enough to take advantage of new version's features. See:

Telegraf users go.mongodb.org/mongo-driver version 1.11.1 and the latest is 1.11.2, so I do not think that is the issue either.

I am at a bit of a loss. Do you get any other info when running in debug mode?

feiniao0308 commented 1 year ago

yes, @ is part of the mongo uri . I already run in debug mode, only see 2023-02-28T17:59:02Z E! [inputs.mongodb] Error in plugin: unable to connect to MongoDB: server returned error on SASL authentication step: BSON field 'saslContinue.mechanism' is an unknown field. ERROR. I've tried to add some other options in the uri, but looks like most of them are unsupported. No idea what I can do now. I have to disable this plugin for now.

[[inputs.mongodb]]
  gather_col_stats = false
  gather_perdb_stats = true
  insecure_skip_verify = false
  servers = [
    "mongodb://username:password@host:27017/?connect=direct&authMechanism=SCRAM-SHA-1"
  ]
  tls_ca = "/etc/mongo/mongo.crt"
powersj commented 1 year ago

To continue looking at this I am going to need a way to reproduce it or need you to try to connect outside of telegraf, with just the mongo-go-driver. Effectively something like the following, but you would also need to possibly include your TLS config:

import (
    "context"
    "fmt"
    "time"

    "go.mongodb.org/mongo-driver/mongo"
    "go.mongodb.org/mongo-driver/mongo/options"
    "go.mongodb.org/mongo-driver/mongo/readpref"
)

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
_, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://username:password@host:27017/?connect=direct&authMechanism=SCRAM-SHA-1"))
fmt.Println(err)
telegraf-tiger[bot] commented 1 year ago

Hello! I am closing this issue due to inactivity. I hope you were able to resolve your problem, if not please try posting this question in our Community Slack or Community Page. Thank you!