Skip to content

Commit c045481

Browse files
committed
PMM-14431 Skip non primary.
1 parent ca6312f commit c045481

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

exporter/metrics.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"sync"
2525
"time"
2626

27+
"github.com/percona/mongodb_exporter/internal/util"
2728
"github.com/pkg/errors"
2829
"github.com/prometheus/client_golang/prometheus"
2930
"go.mongodb.org/mongo-driver/bson"
@@ -213,6 +214,9 @@ func allReservedNames(client *mongo.Client) ([]string, error) {
213214
reservedNames := []string{}
214215
dbs, err := client.ListDatabaseNames(ctx, struct{}{})
215216
if err != nil {
217+
if cmdErr, ok := err.(mongo.CommandError); ok && cmdErr.Code == util.ErrNotPrimaryOrSecondary {
218+
return []string{}, nil
219+
}
216220
return reservedNames, errors.Wrap(err, "ListDatabaseNames failed")
217221
}
218222

0 commit comments

Comments
 (0)