From cb4b628ca1cfd0497aa8a7cdcb06a5a514a5707d Mon Sep 17 00:00:00 2001 From: Will Rouesnel Date: Mon, 9 Oct 2017 11:07:50 +1100 Subject: [PATCH] Add tolerant version regex parsing to handle PostgreSQL 10. Closes #112. --- postgres_exporter.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/postgres_exporter.go b/postgres_exporter.go index b24a964a..52204794 100644 --- a/postgres_exporter.go +++ b/postgres_exporter.go @@ -102,7 +102,7 @@ func (cu *ColumnUsage) UnmarshalYAML(unmarshal func(interface{}) error) error { } // Regex used to get the "short-version" from the postgres version field. -var versionRegex = regexp.MustCompile(`^\w+ (\d+\.\d+\.\d+)`) +var versionRegex = regexp.MustCompile(`^\w+ ((\d+)(\.\d+)?(\.\d+)?)\s`) var lowestSupportedVersion = semver.MustParse("9.1.0") // Parses the version of postgres into the short version string we can use to @@ -110,7 +110,7 @@ var lowestSupportedVersion = semver.MustParse("9.1.0") func parseVersion(versionString string) (semver.Version, error) { submatches := versionRegex.FindStringSubmatch(versionString) if len(submatches) > 1 { - return semver.Make(submatches[1]) + return semver.ParseTolerant(submatches[1]) } return semver.Version{}, errors.New(fmt.Sprintln("Could not find a postgres version in string:", versionString))