From c673d48bdffe4796b4da69ec321622c98a1baf98 Mon Sep 17 00:00:00 2001 From: rolatsch Date: Fri, 27 Sep 2024 07:34:49 +0200 Subject: [PATCH] Remove system colections from collstats (#917) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Remove system colections from collstats See https://github.com/percona/mongodb_exporter/pull/893 When the database profiler is enabled a `system.profile` collection is created for which the collection of collstats is not possible. This results in `Unauthorized` errors. For example: ```Sep 23 11:39:03 db-01 mongodb_exporter[53912]: time="2024-09-23T11:39:03Z" level=error msg="cannot get $collstats cursor for collection .system.profile: (Unauthorized) not authorized on to execute command { aggregate: \"system.profile\", pipeline: [ { $collStats: { latencyStats: { histograms: false }, storageStats: { scale: 1 } } }, { $project: { storageStats.wiredTiger: 0, storageStats.indexDetails: 0 } } ], cursor: {}, lsid: { id: UUID("" }, $clusterTime: { clusterTime: Timestamp(, 1099), signature: { hash: BinData(0, ), keyId: } }, $db: \"\" }" collector=collstats``` Should be safe to filter out system collection when gathering collstats as it was already done for the indexstats collector. * Remove whitespaces --------- Co-authored-by: Jiří Čtvrtka <62988319+JiriCtvrtka@users.noreply.github.com> --- exporter/collstats_collector.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/exporter/collstats_collector.go b/exporter/collstats_collector.go index aff206a5..ae2d7c4d 100644 --- a/exporter/collstats_collector.go +++ b/exporter/collstats_collector.go @@ -92,6 +92,11 @@ func (d *collstatsCollector) collect(ch chan<- prometheus.Metric) { database := parts[0] collection := strings.Join(parts[1:], ".") // support collections having a . + // exclude system collections + if strings.HasPrefix(collection, "system.") { + continue + } + aggregation := bson.D{ { Key: "$collStats", Value: bson.M{