Skip to content

Commit 23c3c41

Browse files
committed
Fix: Skip the non-exist namespaces when there are multiple mongo instance metrics to scrape
Signed-off-by: LinPr <[email protected]>
1 parent ba39863 commit 23c3c41

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

exporter/common.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func unique(slice []string) []string {
164164
}
165165

166166
func checkNamespacesForViews(ctx context.Context, client *mongo.Client, collections []string) ([]string, error) {
167-
onlyCollectionsNamespaces, err := listAllCollections(ctx, client, nil, nil, true)
167+
onlyCollectionsNamespaces, err := listAllCollections(ctx, client, collections, nil, true)
168168
if err != nil {
169169
return nil, err
170170
}
@@ -183,7 +183,7 @@ func checkNamespacesForViews(ctx context.Context, client *mongo.Client, collecti
183183
}
184184

185185
if _, ok := namespaces[collection]; !ok {
186-
return nil, errors.Errorf("namespace %s is a view and cannot be used for collstats/indexstats", collection)
186+
continue
187187
}
188188

189189
filteredCollections = append(filteredCollections, collection)

exporter/common_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,9 @@ func TestCheckNamespacesForViews(t *testing.T) {
199199
defer cleanupDB(ctx, client)
200200

201201
t.Run("Views in provided collection list (should fail)", func(t *testing.T) {
202-
_, err := checkNamespacesForViews(ctx, client, []string{"testdb01.col01", "testdb01.system.views", "testdb01.view01"})
203-
assert.EqualError(t, err, "namespace testdb01.view01 is a view and cannot be used for collstats/indexstats")
202+
filtered, err := checkNamespacesForViews(ctx, client, []string{"testdb01.col01", "testdb01.system.views", "testdb01.view01"})
203+
assert.NoError(t, err)
204+
assert.Equal(t, []string{"testdb01.col01", "testdb01.system.views"}, filtered)
204205
})
205206

206207
t.Run("No Views in provided collection list", func(t *testing.T) {

0 commit comments

Comments
 (0)