Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PMM-10072 Filter out profiler collection #589

Closed
15 changes: 13 additions & 2 deletions exporter/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ import (
"go.mongodb.org/mongo-driver/mongo/options"
)

var systemDBs = []string{"admin", "config", "local"} //nolint:gochecknoglobals
var (
systemDBs = []string{"admin", "config", "local"} //nolint:gochecknoglobals
systemCollections = []string{"system.profile"}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
systemCollections is a global variable (gochecknoglobals)

)

func listCollections(ctx context.Context, client *mongo.Client, database string, filterInNamespaces []string) ([]string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to add tests for the new behavior of filtering collections?

filter := bson.D{} // Default=empty -> list all collections
Expand Down Expand Up @@ -63,7 +66,15 @@ func listCollections(ctx context.Context, client *mongo.Client, database string,
return nil, errors.Wrap(err, "cannot get the list of collections for discovery")
}

return collections, nil
filteredCollections := []string{}
for _, collection := range collections {
if collection == systemCollections[0] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there is only one element in the systemCollections slice, could we use it as a constant variable?

Or if you plan to add more elements to systemCollections slice later could you please write this code which will work if the slice has two or more elements, but not only one?

continue
}
filteredCollections = append(filteredCollections, collection)
}

return filteredCollections, nil
ShashankSinha252 marked this conversation as resolved.
Show resolved Hide resolved
}

// databases returns the list of databases matching the filters.
Expand Down