Skip to content

Commit

Permalink
Fix version detection for new development releases (#2401)
Browse files Browse the repository at this point in the history
  • Loading branch information
ofek committed Oct 14, 2018
1 parent 7794bf3 commit b4a2fd9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 4 additions & 4 deletions postgres/datadog_checks/postgres/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,14 +402,14 @@ def _get_version(self, key, db):
version_parts = version.split(' ')[0].split('.')
version = [int(part) for part in version_parts]
except Exception:
# Postgres might be in beta, with format \d+beta\d+
match = re.match('(\d+)(beta)(\d+)', version)
# Postgres might be in development, with format \d+[beta|rc]\d+
match = re.match('(\d+)([a-zA-Z]+)(\d+)', version)
if match:
version_parts = list(match.groups())

# We found a valid beta version
# We found a valid development version
if len(version_parts) == 3:
# Replace `beta` with a negative number to properly compare versions
# Replace development tag with a negative number to properly compare versions
version_parts[1] = -1
version = [int(part) for part in version_parts]

Expand Down
6 changes: 5 additions & 1 deletion postgres/tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,13 @@ def test_get_version(check):
db.cursor().fetchone.return_value = ['11beta3']
assert check._get_version('beta_version', db) == [11, -1, 3]

# Test #rc# style versions
db.cursor().fetchone.return_value = ['11rc1']
assert check._get_version('rc_version', db) == [11, -1, 1]

# Test #unknown# style versions
db.cursor().fetchone.return_value = ['11nightly3']
assert check._get_version('unknown_version', db) == '11nightly3'
assert check._get_version('unknown_version', db) == [11, -1, 3]


def test_is_above(check):
Expand Down

0 comments on commit b4a2fd9

Please sign in to comment.