Skip to content

fix issue #358: descriptors reported by collector have inconsistent l… #598

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

Open
wants to merge 1 commit 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
15 changes: 15 additions & 0 deletions cmd/postgres_exporter/pg_setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ import (
"math"
"strconv"
"strings"
"sync"

"github.com/go-kit/kit/log/level"
"github.com/prometheus/client_golang/prometheus"
)

var (
// cache the first server setting when there are multiple servers
shortDescCache sync.Map
)

// Query the pg_settings view containing runtime variables
func querySettings(ch chan<- prometheus.Metric, server *Server) error {
level.Debug(logger).Log("msg", "Querying pg_setting view", "server", server)
Expand All @@ -46,6 +52,15 @@ func querySettings(ch chan<- prometheus.Metric, server *Server) error {
return fmt.Errorf("Error retrieving rows on %q: %s %v", server, namespace, err)
}

// once the first server setting shortDesc cached, the other server re-use the first cache
if v, ok := shortDescCache.Load(s.name); !ok {
shortDescCache.Store(s.name, s.shortDesc)
} else {
if shortDesc, ok := v.(string); ok {
s.shortDesc = shortDesc
}
}

ch <- s.metric(server.labels)
}

Expand Down