-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extract version utils and use semver for version comparison #4844
Changes from all commits
42ccb88
ffe81db
294602f
4e3c315
755c960
dd10d0e
c600eb6
9c7ce54
fb9784a
962a8fa
ab8d4ea
5928819
f4022d3
7b0a249
81f9d5f
b7c9f74
0fe217d
5398b24
768a356
d12d774
a0401c6
6b3af0d
1cb0e14
c35f28a
0ddbb8a
e472798
6ab4df9
fb0cba8
4240dc5
19f0d99
bcc3d40
9e3b95a
faf3b65
0960c7a
689f485
6c53573
1ddb84f
d2efb46
7735c41
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# (C) Datadog, Inc. 2019 | ||
# All rights reserved | ||
# Licensed under Simplified BSD License (see LICENSE) | ||
import re | ||
|
||
import semver | ||
|
||
V8_3 = semver.parse("8.3.0") | ||
V9 = semver.parse("9.0.0") | ||
V9_1 = semver.parse("9.1.0") | ||
V9_2 = semver.parse("9.2.0") | ||
V9_4 = semver.parse("9.4.0") | ||
V9_6 = semver.parse("9.6.0") | ||
V10 = semver.parse("10.0.0") | ||
|
||
|
||
def get_version(db): | ||
cursor = db.cursor() | ||
cursor.execute('SHOW SERVER_VERSION;') | ||
raw_version = cursor.fetchone()[0] | ||
try: | ||
version_parts = raw_version.split(' ')[0].split('.') | ||
version = [int(part) for part in version_parts] | ||
while len(version) < 3: | ||
version.append(0) | ||
return semver.VersionInfo(*version) | ||
except Exception: | ||
# Postgres might be in development, with format \d+[beta|rc]\d+ | ||
match = re.match(r'(\d+)([a-zA-Z]+)(\d+)', raw_version) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know. PG documentation only refers to actual releases, which are on X.Y.Z format https://www.postgresql.org/support/versioning/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to https://github.com/postgres/postgres/releases/, postgres seems to follow semver, only betas differ from semver and they seem to only apply to major versions: |
||
if match: | ||
FlorianVeaux marked this conversation as resolved.
Show resolved
Hide resolved
|
||
version = list(match.groups()) | ||
# We found a valid development version | ||
if len(version) == 3: | ||
# Replace development tag with a negative number to properly compare versions | ||
version[1] = -1 | ||
version = [int(part) for part in version] | ||
return semver.VersionInfo(*version) | ||
raise Exception("Cannot determine which version is {}".format(raw_version)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
psycopg2-binary==2.8.4 | ||
semver==2.9.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't cache version information as it may change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cache is cleared when wrong version is detected (see
_clean_state
). Take into account we are already caching version specific information such as which queries to runThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's only cleared when an error occurs and the difference between minor releases is unlikely to cause one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, that is right and that would affect inventories project only. So I'll remove the caching as part of the PR that adds inventories. This PR is not intending to change behaviour and version was already cached (#4874 (comment))