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

Fix/index stats exclude system collections #891

Closed ramunas-omnisend closed 4 weeks ago

ramunas-omnisend commented 4 weeks ago

Details: When a view is created inside a MongoDB database, a special collection named system.views is also created. Attempting to call IndexStats on system.views results in an Unauthorized error, even when executed with root privileges.

For example:

ERRO[0011] cannot get $indexStats cursor for collection <database>.system.views: 
(Unauthorized) not authorized on <database> to execute command { 
aggregate: "system.views", pipeline: [ { $indexStats: {} } ], cursor: {}, 
lsid: { id: UUID("<lsid>") }, $clusterTime: { clusterTime: Timestamp(<timestamp>, 1), 
signature: { hash: BinData(0, <signature>), keyId: <key-id> } }, $db: "<database>", 
$readPreference: { mode: "primaryPreferred" } }

This fix filters out system collections like system.views when gathering IndexStats, preventing these unnecessary errors from appearing in the logs.

it-percona-cla commented 4 weeks ago

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 3 committers have signed the CLA.

:white_check_mark: ramunas-omnisend
:x: zygis
:x: ritmas
You have signed the CLA already but the status is still pending? Let us recheck it.

ramunas-omnisend commented 4 weeks ago

Will open another PR