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

Remove system colections from index stats #893

Closed ramunas-omnisend closed 3 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.