Merge pull request #620 from SN9NV/master

Sanitize setting values because of Aurora irregularity
This commit is contained in:
Joe Adams 2022-03-22 21:19:49 -04:00 committed by GitHub
commit 7e02b9bd9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,6 +23,13 @@ import (
"github.com/prometheus/client_golang/prometheus"
)
var (
settingUnits = []string{
"ms", "s", "min", "h", "d",
"B", "kB", "MB", "GB", "TB",
}
)
// 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)
@ -93,9 +100,24 @@ func (s *pgSetting) metric(labels prometheus.Labels) prometheus.Metric {
return prometheus.MustNewConstMetric(desc, prometheus.GaugeValue, val)
}
// Removes units from any of the setting values.
// This is mostly because of a irregularity regarding AWS RDS Aurora
// https://github.com/prometheus-community/postgres_exporter/issues/619
func (s *pgSetting) sanitizeValue() {
for _, unit := range settingUnits {
if strings.HasSuffix(s.setting, unit) {
endPos := len(s.setting) - len(unit) - 1
s.setting = s.setting[:endPos]
return
}
}
}
// TODO: fix linter override
// nolint: nakedret
func (s *pgSetting) normaliseUnit() (val float64, unit string, err error) {
s.sanitizeValue()
val, err = strconv.ParseFloat(s.setting, 64)
if err != nil {
return val, unit, fmt.Errorf("Error converting setting %q value %q to float: %s", s.name, s.setting, err)