fix(inputs.mongodb): Improve error logging (#12599)

This commit is contained in:
Tom Pillot 2023-02-03 09:44:50 +01:00 committed by GitHub
parent dfc5cdf924
commit cde651b7ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 5 deletions

View File

@ -68,7 +68,7 @@ func (m *MongoDB) Init() error {
InsecureSkipVerify: m.ClientConfig.InsecureSkipVerify, InsecureSkipVerify: m.ClientConfig.InsecureSkipVerify,
} }
if len(m.Ssl.CaCerts) == 0 { if len(m.Ssl.CaCerts) == 0 {
return fmt.Errorf("you must explicitly set insecure_skip_verify to skip cerificate validation") return fmt.Errorf("you must explicitly set insecure_skip_verify to skip certificate validation")
} }
roots := x509.NewCertPool() roots := x509.NewCertPool()
@ -139,7 +139,7 @@ func (m *MongoDB) setupConnection(connURL string) error {
return fmt.Errorf("unable to ping MongoDB: %w", err) return fmt.Errorf("unable to ping MongoDB: %w", err)
} }
m.Log.Errorf("unable to ping MongoDB: %w", err) m.Log.Errorf("unable to ping MongoDB: %s", err)
} }
server := &Server{ server := &Server{
@ -156,7 +156,7 @@ func (m *MongoDB) Stop() {
for _, server := range m.clients { for _, server := range m.clients {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
if err := server.client.Disconnect(ctx); err != nil { if err := server.client.Disconnect(ctx); err != nil {
m.Log.Errorf("disconnecting from %q failed: %w", server, err) m.Log.Errorf("disconnecting from %q failed: %s", server, err)
} }
cancel() cancel()
} }
@ -172,14 +172,14 @@ func (m *MongoDB) Gather(acc telegraf.Accumulator) error {
defer wg.Done() defer wg.Done()
if m.DisconnectedServersBehavior == "skip" { if m.DisconnectedServersBehavior == "skip" {
if err := srv.ping(); err != nil { if err := srv.ping(); err != nil {
m.Log.Debugf("failed to ping server: %w", err) m.Log.Debugf("failed to ping server: %s", err)
return return
} }
} }
err := srv.gatherData(acc, m.GatherClusterStatus, m.GatherPerdbStats, m.GatherColStats, m.GatherTopStat, m.ColStatsDbs) err := srv.gatherData(acc, m.GatherClusterStatus, m.GatherPerdbStats, m.GatherColStats, m.GatherTopStat, m.ColStatsDbs)
if err != nil { if err != nil {
m.Log.Errorf("failed to gather data: %w", err) m.Log.Errorf("failed to gather data: %s", err)
} }
}(client) }(client)
} }