mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-18 15:33:02 +00:00
Only log hub / singleuser version mismatch once
If your jupyterhub and jupyterhub-singleuser instances are running at different minor or greater versions a warning gets logged per active server which can be a lot when you have hundreds of active servers. This adds a flag to that version mismatch logging logic such that the warning is only logged once per restart of the hub server. Closes issue #2970
This commit is contained in:
@@ -18,6 +18,15 @@ version_info = (
|
|||||||
|
|
||||||
__version__ = ".".join(map(str, version_info[:3])) + ".".join(version_info[3:])
|
__version__ = ".".join(map(str, version_info[:3])) + ".".join(version_info[3:])
|
||||||
|
|
||||||
|
# Singleton flag to only log the major/minor mismatch warning once.
|
||||||
|
_version_mismatch_warning_logged = False
|
||||||
|
|
||||||
|
|
||||||
|
def reset_globals():
|
||||||
|
"""Used to reset globals between test cases."""
|
||||||
|
global _version_mismatch_warning_logged
|
||||||
|
_version_mismatch_warning_logged = False
|
||||||
|
|
||||||
|
|
||||||
def _check_version(hub_version, singleuser_version, log):
|
def _check_version(hub_version, singleuser_version, log):
|
||||||
"""Compare Hub and single-user server versions"""
|
"""Compare Hub and single-user server versions"""
|
||||||
@@ -42,19 +51,26 @@ def _check_version(hub_version, singleuser_version, log):
|
|||||||
hub_major_minor = V(hub_version).version[:2]
|
hub_major_minor = V(hub_version).version[:2]
|
||||||
singleuser_major_minor = V(singleuser_version).version[:2]
|
singleuser_major_minor = V(singleuser_version).version[:2]
|
||||||
extra = ""
|
extra = ""
|
||||||
|
do_log = True
|
||||||
if singleuser_major_minor == hub_major_minor:
|
if singleuser_major_minor == hub_major_minor:
|
||||||
# patch-level mismatch or lower, log difference at debug-level
|
# patch-level mismatch or lower, log difference at debug-level
|
||||||
# because this should be fine
|
# because this should be fine
|
||||||
log_method = log.debug
|
log_method = log.debug
|
||||||
else:
|
else:
|
||||||
# log warning-level for more significant mismatch, such as 0.8 vs 0.9, etc.
|
# log warning-level for more significant mismatch, such as 0.8 vs 0.9, etc.
|
||||||
log_method = log.warning
|
global _version_mismatch_warning_logged
|
||||||
extra = " This could cause failure to authenticate and result in redirect loops!"
|
if _version_mismatch_warning_logged:
|
||||||
log_method(
|
do_log = False # We already logged this warning so don't log it again.
|
||||||
"jupyterhub version %s != jupyterhub-singleuser version %s." + extra,
|
else:
|
||||||
hub_version,
|
log_method = log.warning
|
||||||
singleuser_version,
|
extra = " This could cause failure to authenticate and result in redirect loops!"
|
||||||
)
|
_version_mismatch_warning_logged = True
|
||||||
|
if do_log:
|
||||||
|
log_method(
|
||||||
|
"jupyterhub version %s != jupyterhub-singleuser version %s." + extra,
|
||||||
|
hub_version,
|
||||||
|
singleuser_version,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
log.debug(
|
log.debug(
|
||||||
"jupyterhub and jupyterhub-singleuser both on version %s" % hub_version
|
"jupyterhub and jupyterhub-singleuser both on version %s" % hub_version
|
||||||
|
@@ -4,6 +4,11 @@ import logging
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from .._version import _check_version
|
from .._version import _check_version
|
||||||
|
from .._version import reset_globals
|
||||||
|
|
||||||
|
|
||||||
|
def setup_function(function):
|
||||||
|
reset_globals()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
@@ -25,3 +30,17 @@ def test_check_version(hub_version, singleuser_version, log_level, msg, caplog):
|
|||||||
record = caplog.records[0]
|
record = caplog.records[0]
|
||||||
assert record.levelno == log_level
|
assert record.levelno == log_level
|
||||||
assert msg in record.getMessage()
|
assert msg in record.getMessage()
|
||||||
|
|
||||||
|
|
||||||
|
def test_check_version_singleton(caplog):
|
||||||
|
"""Tests that minor version difference logging is only logged once."""
|
||||||
|
# Run test_check_version twice which will assert that the warning is only logged
|
||||||
|
# once.
|
||||||
|
for x in range(2):
|
||||||
|
test_check_version(
|
||||||
|
'1.2.0',
|
||||||
|
'1.1.0',
|
||||||
|
logging.WARNING,
|
||||||
|
'This could cause failure to authenticate',
|
||||||
|
caplog,
|
||||||
|
)
|
||||||
|
Reference in New Issue
Block a user