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

Lower authorization errors to debug level in mongodb input #4869

Merged
merged 1 commit into from
Oct 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions plugins/inputs/mongodb/mongodb_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mongodb
import (
"log"
"net/url"
"strings"
"time"

"github.com/influxdata/telegraf"
Expand All @@ -26,6 +27,10 @@ type oplogEntry struct {
Timestamp bson.MongoTimestamp `bson:"ts"`
}

func IsAuthorization(err error) bool {
return strings.Contains(err.Error(), "not authorized")
}

func (s *Server) gatherOplogStats() *OplogStats {
stats := &OplogStats{}
localdb := s.Session.DB("local")
Expand All @@ -39,14 +44,22 @@ func (s *Server) gatherOplogStats() *OplogStats {
if err == mgo.ErrNotFound {
continue
}
log.Println("E! Error getting first oplog entry (" + err.Error() + ")")
if IsAuthorization(err) {
log.Println("D! Error getting first oplog entry (" + err.Error() + ")")
} else {
log.Println("E! Error getting first oplog entry (" + err.Error() + ")")
}
return stats
}
if err := localdb.C(collection_name).Find(query).Sort("-$natural").Limit(1).One(&op_last); err != nil {
if err == mgo.ErrNotFound {
if err == mgo.ErrNotFound || IsAuthorization(err) {
continue
}
log.Println("E! Error getting last oplog entry (" + err.Error() + ")")
if IsAuthorization(err) {
log.Println("D! Error getting first oplog entry (" + err.Error() + ")")
} else {
log.Println("E! Error getting first oplog entry (" + err.Error() + ")")
}
return stats
}
}
Expand Down Expand Up @@ -98,7 +111,11 @@ func (s *Server) gatherData(acc telegraf.Accumulator, gatherDbStats bool) error
},
}, &resultShards)
if err != nil {
log.Println("E! Error getting database shard stats (" + err.Error() + ")")
if IsAuthorization(err) {
log.Println("D! Error getting database shard stats (" + err.Error() + ")")
} else {
log.Println("E! Error getting database shard stats (" + err.Error() + ")")
}
}

oplogStats := s.gatherOplogStats()
Expand Down