From 51bf48f3559429278baa0ec3e218cb7efa58541f Mon Sep 17 00:00:00 2001 From: Joshua Powers Date: Tue, 21 Jun 2022 11:16:12 -0600 Subject: [PATCH] fix: filter out views in mongodb lookup (#11280) --- plugins/inputs/mongodb/mongodb_server.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/inputs/mongodb/mongodb_server.go b/plugins/inputs/mongodb/mongodb_server.go index 79d3d36c6c038..ae0ab31ab37a4 100644 --- a/plugins/inputs/mongodb/mongodb_server.go +++ b/plugins/inputs/mongodb/mongodb_server.go @@ -3,13 +3,13 @@ package mongodb import ( "context" "fmt" - "go.mongodb.org/mongo-driver/bson/primitive" "strconv" "strings" "time" "github.com/influxdata/telegraf" "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" "go.mongodb.org/mongo-driver/x/bsonx" @@ -229,8 +229,11 @@ func (s *Server) gatherCollectionStats(colStatsDbs []string) (*ColStats, error) results := &ColStats{} for _, dbName := range names { if stringInSlice(dbName, colStatsDbs) || len(colStatsDbs) == 0 { + // skip views as they fail on collStats below + filter := bson.M{"type": bson.M{"$in": bson.A{"collection", "timeseries"}}} + var colls []string - colls, err = s.client.Database(dbName).ListCollectionNames(context.Background(), bson.D{}) + colls, err = s.client.Database(dbName).ListCollectionNames(context.Background(), filter) if err != nil { s.Log.Errorf("Error getting collection names: %s", err.Error()) continue