From 4ce8b5c7411c1b80df41f58eca630efa84df2a76 Mon Sep 17 00:00:00 2001 From: Will Rouesnel Date: Wed, 11 Apr 2018 21:10:29 +1000 Subject: [PATCH 1/3] Add test case which reproduces issue #173 --- cmd/postgres_exporter/pg_setting_test.go | 32 ++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/cmd/postgres_exporter/pg_setting_test.go b/cmd/postgres_exporter/pg_setting_test.go index 8b2019edc..309de9f23 100644 --- a/cmd/postgres_exporter/pg_setting_test.go +++ b/cmd/postgres_exporter/pg_setting_test.go @@ -92,6 +92,38 @@ var fixtures = []fixture{ d: "Desc{fqName: \"pg_settings_16_mb_real_fixture_metric_bytes\", help: \"Foo foo foo [Units converted to bytes.]\", constLabels: {}, variableLabels: []}", v: 5.0331648e+07, }, + { + p: pgSetting{ + name: "32_mb_real_fixture_metric", + setting: "3.0", + unit: "32MB", + shortDesc: "Foo foo foo", + vartype: "real", + }, + n: normalised{ + val: 1.00663296e+08, + unit: "bytes", + err: "", + }, + d: "Desc{fqName: \"pg_settings_32_mb_real_fixture_metric_bytes\", help: \"Foo foo foo [Units converted to bytes.]\", constLabels: {}, variableLabels: []}", + v: 1.00663296e+08, + }, + { + p: pgSetting{ + name: "64_mb_real_fixture_metric", + setting: "3.0", + unit: "64MB", + shortDesc: "Foo foo foo", + vartype: "real", + }, + n: normalised{ + val: 2.01326592e+08, + unit: "bytes", + err: "", + }, + d: "Desc{fqName: \"pg_settings_64_mb_real_fixture_metric_bytes\", help: \"Foo foo foo [Units converted to bytes.]\", constLabels: {}, variableLabels: []}", + v: 2.01326592e+08, + }, { p: pgSetting{ name: "bool_on_fixture_metric", From 0fe49913d2b309c88616403625a7a81e6dd69102 Mon Sep 17 00:00:00 2001 From: Will Rouesnel Date: Sat, 14 Apr 2018 23:38:26 +1000 Subject: [PATCH 2/3] Fix issue #174 Postgres can emit 32MB and 64MB units which were previously unhandled. Handle them. --- cmd/postgres_exporter/pg_setting.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/postgres_exporter/pg_setting.go b/cmd/postgres_exporter/pg_setting.go index e3b89b55a..d3deafc52 100644 --- a/cmd/postgres_exporter/pg_setting.go +++ b/cmd/postgres_exporter/pg_setting.go @@ -96,7 +96,7 @@ func (s *pgSetting) normaliseUnit() (val float64, unit string, err error) { return case "ms", "s", "min", "h", "d": unit = "seconds" - case "kB", "MB", "GB", "TB", "8kB", "16kB", "32kB", "16MB": + case "kB", "MB", "GB", "TB", "8kB", "16kB", "32kB", "16MB", "32MB", "64MB": unit = "bytes" default: err = fmt.Errorf("Unknown unit for runtime variable: %q", s.unit) @@ -134,6 +134,12 @@ func (s *pgSetting) normaliseUnit() (val float64, unit string, err error) { case "16MB": val *= math.Pow(2, 24) } + case "32MB": + val *= math.Pow(2, 25) + } + case "64MB": + val *= math.Pow(2, 26) + } return } From 7ed87356200e808fead1aa0e119adf39a448a4f5 Mon Sep 17 00:00:00 2001 From: Will Rouesnel Date: Sun, 15 Apr 2018 22:54:13 +1000 Subject: [PATCH 3/3] Fix lint and fmt errors. --- cmd/postgres_exporter/pg_setting.go | 2 -- cmd/postgres_exporter/pg_setting_test.go | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/cmd/postgres_exporter/pg_setting.go b/cmd/postgres_exporter/pg_setting.go index d3deafc52..efb60b1dd 100644 --- a/cmd/postgres_exporter/pg_setting.go +++ b/cmd/postgres_exporter/pg_setting.go @@ -133,10 +133,8 @@ func (s *pgSetting) normaliseUnit() (val float64, unit string, err error) { val *= math.Pow(2, 15) case "16MB": val *= math.Pow(2, 24) - } case "32MB": val *= math.Pow(2, 25) - } case "64MB": val *= math.Pow(2, 26) } diff --git a/cmd/postgres_exporter/pg_setting_test.go b/cmd/postgres_exporter/pg_setting_test.go index 309de9f23..0602da8fc 100644 --- a/cmd/postgres_exporter/pg_setting_test.go +++ b/cmd/postgres_exporter/pg_setting_test.go @@ -92,7 +92,7 @@ var fixtures = []fixture{ d: "Desc{fqName: \"pg_settings_16_mb_real_fixture_metric_bytes\", help: \"Foo foo foo [Units converted to bytes.]\", constLabels: {}, variableLabels: []}", v: 5.0331648e+07, }, - { + { p: pgSetting{ name: "32_mb_real_fixture_metric", setting: "3.0", @@ -108,7 +108,7 @@ var fixtures = []fixture{ d: "Desc{fqName: \"pg_settings_32_mb_real_fixture_metric_bytes\", help: \"Foo foo foo [Units converted to bytes.]\", constLabels: {}, variableLabels: []}", v: 1.00663296e+08, }, - { + { p: pgSetting{ name: "64_mb_real_fixture_metric", setting: "3.0",