1
0
mirror of https://github.com/prometheus-community/postgres_exporter.git synced 2025-06-05 22:37:07 +03:00

Feat: Improve Error Handling for Server.Scrape (#1158)

* Update querySettings Error Return in Scrape

If there are errors querying namespace mappings, the potential error from querySettings is obscured. Adding an immediate return if there are errors retreiving settings.

Signed-off-by: Jonathan Bowe <jonathan@bowedev.com>

* Improve Verbosity of queryNamespaceMappings Errors

Previously if any errors were encountered by queryNamespaceMappings, only a count of those errors was returned - making debugging those errors harder than it needs to be.

I'm changing this to immediately return nil if no errors are encountered, and otherwise an error will be formatted with each of the namespaces and what the error was for that namespace.

Signed-off-by: Jonathan Bowe <jonathan@bowedev.com>

* Simplify Error Message

Co-authored-by: Ben Kochie <superq@gmail.com>
Signed-off-by: Jonathan Bowe <bowejonathan99@gmail.com>

---------

Signed-off-by: Jonathan Bowe <jonathan@bowedev.com>
Signed-off-by: Jonathan Bowe <bowejonathan99@gmail.com>
Co-authored-by: Ben Kochie <superq@gmail.com>
This commit is contained in:
Jonathan Bowe 2025-05-29 07:53:56 -04:00 committed by GitHub
parent d1a957f679
commit 94e8399935
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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, namespace: %s error: %s", err, namespace, errStr)
}
return err