Skip to content

Commit ad6bbc3

Browse files
committed
fix issue prometheus-community#358: descriptors reported by collector have inconsistent label names
Signed-off-by: zhoujk <[email protected]>
1 parent 0977e96 commit ad6bbc3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

cmd/postgres_exporter/pg_setting.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@ import (
1818
"math"
1919
"strconv"
2020
"strings"
21+
"sync"
2122

2223
"github.com/go-kit/kit/log/level"
2324
"github.com/prometheus/client_golang/prometheus"
2425
)
2526

27+
var (
28+
// cache the first server setting when there are multiple servers
29+
shortDescCache sync.Map
30+
)
31+
2632
// Query the pg_settings view containing runtime variables
2733
func querySettings(ch chan<- prometheus.Metric, server *Server) error {
2834
level.Debug(logger).Log("msg", "Querying pg_setting view", "server", server)
@@ -46,6 +52,15 @@ func querySettings(ch chan<- prometheus.Metric, server *Server) error {
4652
return fmt.Errorf("Error retrieving rows on %q: %s %v", server, namespace, err)
4753
}
4854

55+
// once the first server setting shortDesc cached, the other server re-use the first cache
56+
if v, ok := shortDescCache.Load(s.name); !ok {
57+
shortDescCache.Store(s.name, s.shortDesc)
58+
} else {
59+
if shortDesc, ok := v.(string); ok {
60+
s.shortDesc = shortDesc
61+
}
62+
}
63+
4964
ch <- s.metric(server.labels)
5065
}
5166

0 commit comments

Comments
 (0)