Skip to content

Feat: Improve Error Handling for Server.Scrape #1158

New issue

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

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

Already on GitHub? # to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions cmd/postgres_exporter/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,17 @@ func (s *Server) Scrape(ch chan<- prometheus.Metric, disableSettingsMetrics bool
if !disableSettingsMetrics && s.master {
if err = querySettings(ch, s); err != nil {
err = fmt.Errorf("error retrieving settings: %s", err)
return err
}
}

errMap := queryNamespaceMappings(ch, s)
if len(errMap) > 0 {
err = fmt.Errorf("queryNamespaceMappings returned %d errors", len(errMap))
if len(errMap) == 0 {
return nil
}
err = fmt.Errorf("queryNamespaceMappings errors encountered")
for namespace, errStr := range errMap {
err = fmt.Errorf("%s, %s namespace had the following error: %s", err, namespace, errStr)
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor nit to make it a little simpler to read (and shorter).

Suggested change
err = fmt.Errorf("%s, %s namespace had the following error: %s", err, namespace, errStr)
err = fmt.Errorf("%s, namespace: %s error: %s", err, namespace, errStr)

}

return err
Expand Down