Skip to content

Commit 670447e

Browse files
authored
MySQL version compatibility check: move get_check_logger() to except block (DataDog#20833)
1 parent f3c84ac commit 670447e

3 files changed

Lines changed: 5 additions & 3 deletions

File tree

mysql/changelog.d/20833.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Moved logger instantiation in MySQL version compatibility check to the except block to only perform the costly call to `get_check_logger()` when outputting the warning log.

mysql/datadog_checks/mysql/version_utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,12 @@ class MySQLVersion(namedtuple('MySQLVersion', ['version', 'flavor', 'build'])):
5151
def version_compatible(self, compat_version):
5252
# some patch version numbers contain letters (e.g. 5.0.51a)
5353
# so let's be careful when we compute the version number
54-
log = get_check_logger()
5554
try:
5655
mysql_version = self.version.split('.')
5756
except Exception as e:
58-
log.warning("Cannot compute mysql version, assuming it's older.: %s", e)
57+
log = get_check_logger()
58+
log.warning("Cannot compute MySQL version, assuming it's older: %s", e)
5959
return False
60-
log.debug("MySQL version %s", mysql_version)
6160

6261
patchlevel = int(re.match(r"([0-9]+)", mysql_version[2]).group(1))
6362
version = (int(mysql_version[0]), int(mysql_version[1]), patchlevel)

mysql/tests/test_unit.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ def cursor(self):
139139
assert v.version == '5.5.12'
140140
assert v.flavor == 'MySQL'
141141
assert v.build == 'log'
142+
assert v.version_compatible(compat_version=(5, 4, 3))
143+
assert not v.version_compatible(compat_version=(8, 0, 43))
142144

143145

144146
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)