percona / mongodb_exporter

A Prometheus exporter for MongoDB including sharding, replication and storage engines
Apache License 2.0
1.16k stars 425 forks source link

mongodb exporter 0.40 not supported mongodb 7.0 authorization set enabled ? #754

Closed ericinfra closed 9 months ago

ericinfra commented 9 months ago

Environment

mongodb 7.0.3 After authorization is enabled, mongodb exporter 0.40 cannot be linked to mongodb

/opt/mongodb_exporter/mongodb_exporter  --mongodb.uri=mongodb://mongodb_exporter:123456@10.248.10.13:27017/admin?ssl=false --collect-all --compatible-mode

[root@ip-10-248-10-13 mongodb]#  curl http://127.0.0.1:9216/metrics 
curl: (52) Empty reply from server
[root@ip-10-248-10-13 mongodb]# netstat -tnlp | grep 9216
tcp6       0      0 :::9216                 :::*                    LISTEN      174913/mongodb_expo 

# cat /opt/mongodb/etc/mongod.conf
security:
  authorization: enabled
net:
  port: 27017
  bindIp: 0.0.0.0
storage:
  dbPath: /opt/mongodb/data
systemLog:
   path: /log/mongodb/mongod.log
   destination: file

mongodb exporter 0.40 Logs are as follows:

[root@ip-10-248-10-13 ~]# /opt/mongodb_exporter/mongodb_exporter  --mongodb.uri=mongodb://mongodb_exporter:123456@10.248.10.13:27017/admin?ssl=false --collect-all --compatible-mode

level=info ts=2023-12-08T11:16:28.282Z caller=tls_config.go:274 msg="Listening on" address=[::]:9216
level=info ts=2023-12-08T11:16:28.282Z caller=tls_config.go:277 msg="TLS is disabled." http2=false address=[::]:9216
ERRO[0017] cannot run getDiagnosticData: (Unauthorized) not authorized on admin to execute command { getDiagnosticData: "1", lsid: { id: UUID("c3cf656b-a7f4-4f49-85d5-35ab8fe9cedf") }, $db: "admin" } 
ERRO[0017] cannot run getDiagnosticData: response is empty 
ERRO[0017] cannot decode getDiagnosticData: <nil> for data field: unexpected data type 
ERRO[0017] cannot decode getCmdLineOtpions: cannot execute getCmdLineOpts command: (Unauthorized) not authorized on admin to execute command { getCmdLineOpts: "1", lsid: { id: UUID("c3cf656b-a7f4-4f49-85d5-35ab8fe9cedf") }, $db: "admin" } 
ERRO[0017] cannot retrieve engine type: Engine is unavailable 
2023/12/08 11:16:45 http: panic serving 10.248.10.4:34296: descriptor Desc{fqName: "", help: "", constLabels: {}, variableLabels: []} is invalid: (Unauthorized) not authorized on admin to execute command { currentOp: true, active: true, microsecs_running: { $exists: true }, op: { $ne: "" }, ns: { $ne: "", $not: { $regex: "^admin.*|^local.*" } }, lsid: { id: UUID("c3cf656b-a7f4-4f49-85d5-35ab8fe9cedf") }, $db: "admin" }
goroutine 16 [running]:
net/http.(*conn).serve.func1()
    /opt/hostedtoolcache/go/1.21.3/x64/src/net/http/server.go:1868 +0xb9
panic({0xb3dfe0?, 0xc0002fe520?})
    /opt/hostedtoolcache/go/1.21.3/x64/src/runtime/panic.go:920 +0x270
github.com/prometheus/client_golang/prometheus.(*Registry).MustRegister(...)
    /home/runner/go/pkg/mod/github.com/prometheus/client_golang@v1.14.0/prometheus/registry.go:406
github.com/percona/mongodb_exporter/exporter.(*Exporter).makeRegistry(0xc00028bb90, {0xd731c8?, 0xc000390150}, 0xc00038e1c0, {0xd70678?, 0xc000388e40}, {{0xc000283170, 0x1, 0x1}, 0x0, ...})
    /home/runner/work/mongodb_exporter/mongodb_exporter/exporter/exporter.go:211 +0x1250
github.com/percona/mongodb_exporter/exporter.RunWebServer.(*Exporter).Handler.func2({0xd72578, 0xc00038e000}, 0xc000392200)
    /home/runner/work/mongodb_exporter/mongodb_exporter/exporter/exporter.go:348 +0x648
net/http.HandlerFunc.ServeHTTP(0x4465a0?, {0xd72578?, 0xc00038e000?}, 0x7ddc1a?)
    /opt/hostedtoolcache/go/1.21.3/x64/src/net/http/server.go:2136 +0x29
net/http.(*ServeMux).ServeHTTP(0x1269a80?, {0xd72578, 0xc00038e000}, 0xc000392200)
    /opt/hostedtoolcache/go/1.21.3/x64/src/net/http/server.go:2514 +0x142
net/http.serverHandler.ServeHTTP({0xc000388780?}, {0xd72578?, 0xc00038e000?}, 0x6?)
    /opt/hostedtoolcache/go/1.21.3/x64/src/net/http/server.go:2938 +0x8e
net/http.(*conn).serve(0xc00038c360, {0xd73120, 0xc00028be90})
    /opt/hostedtoolcache/go/1.21.3/x64/src/net/http/server.go:2009 +0x5f4
created by net/http.(*Server).Serve in goroutine 35
    /opt/hostedtoolcache/go/1.21.3/x64/src/net/http/server.go:3086 +0x5cb
ERRO[0017] cannot run getDiagnosticData: (Unauthorized) not authorized on admin to execute command { getDiagnosticData: "1", lsid: { id: UUID("d4bc8727-4191-4dd3-937e-79699d1a69e5") }, $db: "admin" } 
ERRO[0017] cannot run getDiagnosticData: response is empty 
ERRO[0017] cannot decode getDiagnosticData: <nil> for data field: unexpected data type 
ERRO[0017] cannot decode getCmdLineOtpions: cannot execute getCmdLineOpts command: (Unauthorized) not authorized on admin to execute command { getCmdLineOpts: "1", lsid: { id: UUID("d4bc8727-4191-4dd3-937e-79699d1a69e5") }, $db: "admin" } 
ERRO[0017] cannot retrieve engine type: Engine is unavailable 
2023/12/08 11:16:45 http: panic serving 10.248.10.4:51384: descriptor Desc{fqName: "", help: "", constLabels: {}, variableLabels: []} is invalid: (Unauthorized) not authorized on admin to execute command { currentOp: true, active: true, microsecs_running: { $exists: true }, op: { $ne: "" }, ns: { $ne: "", $not: { $regex: "^admin.*|^local.*" } }, lsid: { id: UUID("d4bc8727-4191-4dd3-937e-79699d1a69e5") }, $db: "admin" }
goroutine 209 [running]:
net/http.(*conn).serve.func1()
    /opt/hostedtoolcache/go/1.21.3/x64/src/net/http/server.go:1868 +0xb9
panic({0xb3dfe0?, 0xc000047e00?})
    /opt/hostedtoolcache/go/1.21.3/x64/src/runtime/panic.go:920 +0x270
github.com/prometheus/client_golang/prometheus.(*Registry).MustRegister(...)
    /home/runner/go/pkg/mod/github.com/prometheus/client_golang@v1.14.0/prometheus/registry.go:406
github.com/percona/mongodb_exporter/exporter.(*Exporter).makeRegistry(0xc00028bb90, {0xd731c8?, 0xc0000b6b60}, 0xc000308380, {0xd70678?, 0xc0000a2540}, {{0xc000283170, 0x1, 0x1}, 0x0, ...})
    /home/runner/work/mongodb_exporter/mongodb_exporter/exporter/exporter.go:211 +0x1250
github.com/percona/mongodb_exporter/exporter.RunWebServer.(*Exporter).Handler.func2({0xd72578, 0xc0003082a0}, 0xc0001f0000)
    /home/runner/work/mongodb_exporter/mongodb_exporter/exporter/exporter.go:348 +0x648
net/http.HandlerFunc.ServeHTTP(0x4465a0?, {0xd72578?, 0xc0003082a0?}, 0x7ddc1a?)
    /opt/hostedtoolcache/go/1.21.3/x64/src/net/http/server.go:2136 +0x29
net/http.(*ServeMux).ServeHTTP(0x1269a80?, {0xd72578, 0xc0003082a0}, 0xc0001f0000)
    /opt/hostedtoolcache/go/1.21.3/x64/src/net/http/server.go:2514 +0x142
net/http.serverHandler.ServeHTTP({0xc000333110?}, {0xd72578?, 0xc0003082a0?}, 0x6?)
    /opt/hostedtoolcache/go/1.21.3/x64/src/net/http/server.go:2938 +0x8e
net/http.(*conn).serve(0xc0002c2000, {0xd73120, 0xc00028be90})
    /opt/hostedtoolcache/go/1.21.3/x64/src/net/http/server.go:2009 +0x5f4
created by net/http.(*Server).Serve in goroutine 35
    /opt/hostedtoolcache/go/1.21.3/x64/src/net/http/server.go:3086 +0x5cb

mongodb 7.0.3 Logs are as follows:

{"t":{"$date":"2023-12-08T11:16:30.679+00:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"10.248.10.13:36024","uuid":{"uuid":{"$uuid":"761c5567-cd89-4de6-9c9e-139ccc28482a"}},"connectionId":216,"connectionCount":11}}
{"t":{"$date":"2023-12-08T11:16:30.679+00:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"10.248.10.13:36018","uuid":{"uuid":{"$uuid":"c5d191cc-825b-4770-8c6f-cd37f055cbdf"}},"connectionId":217,"connectionCount":12}}
{"t":{"$date":"2023-12-08T11:16:30.680+00:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn216","msg":"client metadata","attr":{"remote":"10.248.10.13:36024","client":"conn216","doc":{"application":{"name":"mongodb_exporter"},"driver":{"name":"mongo-go-driver","version":"v1.12.1"},"os":{"type":"linux","architecture":"amd64"},"platform":"go1.21.3"}}}
{"t":{"$date":"2023-12-08T11:16:30.680+00:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn217","msg":"client metadata","attr":{"remote":"10.248.10.13:36018","client":"conn217","doc":{"application":{"name":"mongodb_exporter"},"driver":{"name":"mongo-go-driver","version":"v1.12.1"},"os":{"type":"linux","architecture":"amd64"},"platform":"go1.21.3"}}}
{"t":{"$date":"2023-12-08T11:16:30.680+00:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"10.248.10.13:36036","uuid":{"uuid":{"$uuid":"88876202-23b6-4af8-ae1a-573fdb61dabd"}},"connectionId":218,"connectionCount":13}}
{"t":{"$date":"2023-12-08T11:16:30.680+00:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn218","msg":"client metadata","attr":{"remote":"10.248.10.13:36036","client":"conn218","doc":{"application":{"name":"mongodb_exporter"},"driver":{"name":"mongo-go-driver","version":"v1.12.1"},"os":{"type":"linux","architecture":"amd64"},"platform":"go1.21.3"}}}
{"t":{"$date":"2023-12-08T11:16:30.680+00:00"},"s":"I",  "c":"ACCESS",   "id":6788604, "ctx":"conn218","msg":"Auth metrics report","attr":{"metric":"acquireUser","micros":0}}
{"t":{"$date":"2023-12-08T11:16:30.683+00:00"},"s":"I",  "c":"ACCESS",   "id":5286306, "ctx":"conn218","msg":"Successfully authenticated","attr":{"client":"10.248.10.13:36036","isSpeculative":true,"isClusterMember":false,"mechanism":"SCRAM-SHA-256","user":"mongodb_exporter","db":"admin","result":0,"metrics":{"conversation_duration":{"micros":2628,"summary":{"0":{"step":1,"step_total":2,"duration_micros":43},"1":{"step":2,"step_total":2,"duration_micros":35}}}},"extraInfo":{}}}
{"t":{"$date":"2023-12-08T11:16:30.683+00:00"},"s":"I",  "c":"NETWORK",  "id":6788700, "ctx":"conn218","msg":"Received first command on ingress connection since session start or auth handshake","attr":{"elapsedMillis":0}}
{"t":{"$date":"2023-12-08T11:16:30.683+00:00"},"s":"I",  "c":"ACCESS",   "id":20436,   "ctx":"conn218","msg":"Checking authorization failed","attr":{"error":{"code":13,"codeName":"Unauthorized","errmsg":"not authorized on admin to execute command { replSetGetConfig: 1, lsid: { id: UUID(\"04922ff3-6583-44aa-bbf8-9cb40ce84196\") }, $db: \"admin\" }"}}}
{"t":{"$date":"2023-12-08T11:16:30.684+00:00"},"s":"I",  "c":"ACCESS",   "id":20436,   "ctx":"conn218","msg":"Checking authorization failed","attr":{"error":{"code":13,"codeName":"Unauthorized","errmsg":"not authorized on config to execute command { find: \"version\", filter: {}, limit: 1, singleBatch: true, lsid: { id: UUID(\"04922ff3-6583-44aa-bbf8-9cb40ce84196\") }, $db: \"config\" }"}}}
{"t":{"$date":"2023-12-08T11:16:30.684+00:00"},"s":"I",  "c":"ACCESS",   "id":20436,   "ctx":"conn218","msg":"Checking authorization failed","attr":{"error":{"code":13,"codeName":"Unauthorized","errmsg":"not authorized on admin to execute command { find: \"system.version\", filter: { _id: \"shardIdentity\" }, limit: 1, singleBatch: true, lsid: { id: UUID(\"04922ff3-6583-44aa-bbf8-9cb40ce84196\") }, $db: \"admin\" }"}}}
{"t":{"$date":"2023-12-08T11:16:30.684+00:00"},"s":"I",  "c":"ACCESS",   "id":20436,   "ctx":"conn218","msg":"Checking authorization failed","attr":{"error":{"code":13,"codeName":"Unauthorized","errmsg":"not authorized on admin to execute command { replSetGetConfig: 1, lsid: { id: UUID(\"04922ff3-6583-44aa-bbf8-9cb40ce84196\") }, $db: \"admin\" }"}}}
{"t":{"$date":"2023-12-08T11:16:30.686+00:00"},"s":"I",  "c":"-",        "id":20883,   "ctx":"conn216","msg":"Interrupted operation as its client disconnected","attr":{"opId":40454}}
{"t":{"$date":"2023-12-08T11:16:30.686+00:00"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn217","msg":"Connection ended","attr":{"remote":"10.248.10.13:36018","uuid":{"uuid":{"$uuid":"c5d191cc-825b-4770-8c6f-cd37f055cbdf"}},"connectionId":217,"connectionCount":12}}
{"t":{"$date":"2023-12-08T11:16:30.686+00:00"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn218","msg":"Connection ended","attr":{"remote":"10.248.10.13:36036","uuid":{"uuid":{"$uuid":"88876202-23b6-4af8-ae1a-573fdb61dabd"}},"connectionId":218,"connectionCount":11}}
{"t":{"$date":"2023-12-08T11:16:30.686+00:00"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn216","msg":"Connection ended","attr":{"remote":"10.248.10.13:36024","uuid":{"uuid":{"$uuid":"761c5567-cd89-4de6-9c9e-139ccc28482a"}},"connectionId":216,"connectionCount":10}}
{"t":{"$date":"2023-12-08T11:16:45.679+00:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"10.248.10.13:57048","uuid":{"uuid":{"$uuid":"337a1ada-3952-4477-a88a-2c1a42b8fc11"}},"connectionId":219,"connectionCount":11}}
{"t":{"$date":"2023-12-08T11:16:45.679+00:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"10.248.10.13:57050","uuid":{"uuid":{"$uuid":"ce4d3b7e-2340-4e62-bb11-28b901106e3b"}},"connectionId":220,"connectionCount":12}}
{"t":{"$date":"2023-12-08T11:16:45.679+00:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn219","msg":"client metadata","attr":{"remote":"10.248.10.13:57048","client":"conn219","doc":{"application":{"name":"mongodb_exporter"},"driver":{"name":"mongo-go-driver","version":"v1.12.1"},"os":{"type":"linux","architecture":"amd64"},"platform":"go1.21.3"}}}
BupycHuk commented 9 months ago

Hi @ericinfra , I see that you closed this issue. Does that mean that issue was resolved? If it is, what was the problem?

ericinfra commented 9 months ago

The reason is that in mongodb7.0, the mongodb_exporter user must be given the clusterMonitor role.

The command is as follows:

use admin
db.grantRolesToUser(
   "mongodb_exporter",
   [ "clusterMonitor" ]
)